A feed generator that allows Bluesky bookmarks via DMs

store the createdAt timestamp for when the feed item was added

+10 -4
+6 -2
handler.go
··· 6 6 "fmt" 7 7 "log/slog" 8 8 "strings" 9 + "time" 9 10 10 11 apibsky "github.com/bluesky-social/indigo/api/bsky" 11 12 "github.com/bluesky-social/jetstream/pkg/models" ··· 81 82 82 83 slog.Info("post is a reply to a post that users are subscribed to", "subscribed post URI", subscribedPostURI, "dids", subscribedDids, "RKey", event.Commit.RKey) 83 84 85 + createdAt := time.Now().UTC().UnixNano() 86 + 84 87 replyPostURI := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", event.Did, event.Commit.RKey) 85 - h.createFeedPostForSubscribedUsers(subscribedDids, replyPostURI, subscribedPostURI) 88 + h.createFeedPostForSubscribedUsers(subscribedDids, replyPostURI, subscribedPostURI, createdAt) 86 89 return nil 87 90 } 88 91 ··· 138 141 return dids 139 142 } 140 143 141 - func (h *handler) createFeedPostForSubscribedUsers(usersDids []string, replyPostURI, subscribedPostURI string) { 144 + func (h *handler) createFeedPostForSubscribedUsers(usersDids []string, replyPostURI, subscribedPostURI string, createdAt int64) { 142 145 for _, did := range usersDids { 143 146 feedItem := store.FeedPost{ 144 147 ReplyURI: replyPostURI, 145 148 UserDID: did, 146 149 SubscribedPostURI: subscribedPostURI, 150 + CreatedAt: createdAt, 147 151 } 148 152 err := h.store.AddFeedPost(feedItem) 149 153 if err != nil {
+4 -2
store/feed.go
··· 12 12 "replyURI" TEXT, 13 13 "userDID" TEXT, 14 14 "subscribedPostURI" TEXT, 15 + "createdAt" integer NOT NULL, 15 16 UNIQUE(replyURI, userDID) 16 17 );` 17 18 ··· 34 35 ReplyURI string 35 36 UserDID string 36 37 SubscribedPostURI string 38 + CreatedAt int64 37 39 } 38 40 39 41 func (s *Store) AddFeedPost(feedPost FeedPost) error { 40 - sql := `INSERT INTO feed (replyURI, userDID, subscribedPostURI) VALUES (?, ?, ?) ON CONFLICT(replyURI, userDID) DO NOTHING;` 41 - _, err := s.db.Exec(sql, feedPost.ReplyURI, feedPost.UserDID, feedPost.SubscribedPostURI) 42 + sql := `INSERT INTO feed (replyURI, userDID, subscribedPostURI, createdAt) VALUES (?, ?, ?, ?) ON CONFLICT(replyURI, userDID) DO NOTHING;` 43 + _, err := s.db.Exec(sql, feedPost.ReplyURI, feedPost.UserDID, feedPost.SubscribedPostURI, feedPost.CreatedAt) 42 44 if err != nil { 43 45 return fmt.Errorf("exec insert feed item: %w", err) 44 46 }