this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

rest of tests done

+3 -109
-106
hander_test.go
··· 1 - package main 2 - 3 - import ( 4 - "context" 5 - "encoding/json" 6 - "testing" 7 - 8 - "github.com/bluesky-social/indigo/api/atproto" 9 - apibsky "github.com/bluesky-social/indigo/api/bsky" 10 - "github.com/bluesky-social/jetstream/pkg/models" 11 - "github.com/stretchr/testify/assert" 12 - "github.com/stretchr/testify/require" 13 - "github.com/willdot/bskyfeedgen/store" 14 - ) 15 - 16 - func TestHandlerReceivesSubscribeMessage(t *testing.T) { 17 - db, err := store.New(":memory:") 18 - require.NoError(t, err) 19 - 20 - handler := handler{ 21 - store: db, 22 - } 23 - 24 - record := apibsky.FeedPost{ 25 - Text: "/subscribe", 26 - Reply: &apibsky.FeedPost_ReplyRef{ 27 - Parent: &atproto.RepoStrongRef{ 28 - Uri: "parent-uri", 29 - }, 30 - }, 31 - } 32 - 33 - recordB, err := json.Marshal(record) 34 - require.NoError(t, err) 35 - 36 - event := &models.Event{ 37 - Did: myDid, 38 - Commit: &models.Commit{ 39 - Operation: models.CommitOperationCreate, 40 - Collection: "app.bsky.feed.post", 41 - RKey: "subscribe-post-rkey", 42 - Record: recordB, 43 - }, 44 - } 45 - 46 - // send the event twice to simulate subscribing to the same post twice, to check only 47 - // 1 subscription is created 48 - err = handler.HandleEvent(context.Background(), event) 49 - require.NoError(t, err) 50 - err = handler.HandleEvent(context.Background(), event) 51 - require.NoError(t, err) 52 - 53 - subs, err := db.GetSubscriptionsForPost("parent-uri") 54 - require.NoError(t, err) 55 - 56 - assert.Len(t, subs, 1) 57 - assert.Equal(t, myDid, subs[0]) 58 - } 59 - 60 - func TestHandlerReceivesReplyToASubscribedPost(t *testing.T) { 61 - db, err := store.New(":memory:") 62 - require.NoError(t, err) 63 - 64 - handler := handler{ 65 - store: db, 66 - } 67 - 68 - // add the subscription 69 - err = db.AddSubscriptionForPost("parent-uri", myDid, "subscribe-post-rkey") 70 - require.NoError(t, err) 71 - 72 - record := apibsky.FeedPost{ 73 - Text: "this is a reply to a post that was subscribed to", 74 - Reply: &apibsky.FeedPost_ReplyRef{ 75 - Parent: &atproto.RepoStrongRef{ 76 - Uri: "parent-uri", 77 - }, 78 - }, 79 - } 80 - 81 - recordB, err := json.Marshal(record) 82 - require.NoError(t, err) 83 - 84 - event := &models.Event{ 85 - Did: myDid, 86 - Commit: &models.Commit{ 87 - Operation: models.CommitOperationCreate, 88 - Collection: "app.bsky.feed.post", 89 - RKey: "reply-post-rkey", 90 - Record: recordB, 91 - }, 92 - } 93 - 94 - // send the event twice to simulate subscribing to the same post twice, to check only 95 - // 1 subscription is created 96 - err = handler.HandleEvent(context.Background(), event) 97 - require.NoError(t, err) 98 - err = handler.HandleEvent(context.Background(), event) 99 - require.NoError(t, err) 100 - 101 - subs, err := db.GetSubscriptionsForPost("some-uri") 102 - require.NoError(t, err) 103 - 104 - assert.Len(t, subs, 1) 105 - assert.Equal(t, myDid, subs[0]) 106 - }
+1 -1
handler.go
··· 82 82 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 83 84 84 replyPostURI := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", event.Did, event.Commit.RKey) 85 - h.createFeedPostForSubscribedUsers(subscribedDids, subscribedPostURI, replyPostURI) 85 + h.createFeedPostForSubscribedUsers(subscribedDids, replyPostURI, subscribedPostURI) 86 86 return nil 87 87 } 88 88
+2 -2
store/feed.go
··· 46 46 } 47 47 48 48 func (s *Store) GetUsersFeed(usersDID string) ([]FeedPost, error) { 49 - sql := "SELECT id, replyURI, userDID FROM feed WHERE userDID = ?;" 49 + sql := "SELECT id, replyURI, userDID, subscribedPostURI FROM feed WHERE userDID = ?;" 50 50 rows, err := s.db.Query(sql, usersDID) 51 51 if err != nil { 52 52 return nil, fmt.Errorf("run query to get users feed posts: %w", err) ··· 56 56 feedPosts := make([]FeedPost, 0) 57 57 for rows.Next() { 58 58 var feedPost FeedPost 59 - if err := rows.Scan(&feedPost.ID, &feedPost.ReplyURI, &feedPost.UserDID); err != nil { 59 + if err := rows.Scan(&feedPost.ID, &feedPost.ReplyURI, &feedPost.UserDID, &feedPost.SubscribedPostURI); err != nil { 60 60 return nil, fmt.Errorf("scan row: %w", err) 61 61 } 62 62 feedPosts = append(feedPosts, feedPost)