this repo has no description
0
fork

Configure Feed

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

Merge pull request #2 from willdot/chore/tests

Add some tests for the handler to stop myself from breaking things again

authored by

Will Andrew and committed by
GitHub
e44c0709 7b896ea9

+16 -6
+4
go.mod
··· 9 9 github.com/bugsnag/bugsnag-go/v2 v2.5.1 10 10 github.com/glebarez/go-sqlite v1.22.0 11 11 github.com/golang-jwt/jwt/v5 v5.2.1 12 + github.com/stretchr/testify v1.9.0 12 13 ) 13 14 14 15 require ( ··· 16 17 github.com/bugsnag/panicwrap v1.3.4 // indirect 17 18 github.com/carlmjohnson/versioninfo v0.22.5 // indirect 18 19 github.com/cespare/xxhash/v2 v2.3.0 // indirect 20 + github.com/davecgh/go-spew v1.1.1 // indirect 19 21 github.com/dustin/go-humanize v1.0.1 // indirect 20 22 github.com/felixge/httpsnoop v1.0.4 // indirect 21 23 github.com/go-logr/logr v1.4.1 // indirect ··· 54 56 github.com/multiformats/go-varint v0.0.7 // indirect 55 57 github.com/opentracing/opentracing-go v1.2.0 // indirect 56 58 github.com/pkg/errors v0.9.1 // indirect 59 + github.com/pmezard/go-difflib v1.0.0 // indirect 57 60 github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f // indirect 58 61 github.com/prometheus/client_golang v1.19.1 // indirect 59 62 github.com/prometheus/client_model v0.6.1 // indirect ··· 77 80 golang.org/x/time v0.5.0 // indirect 78 81 golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect 79 82 google.golang.org/protobuf v1.34.2 // indirect 83 + gopkg.in/yaml.v3 v3.0.1 // indirect 80 84 lukechampine.com/blake3 v1.2.1 // indirect 81 85 modernc.org/libc v1.37.6 // indirect 82 86 modernc.org/mathutil v1.6.0 // indirect
+5 -1
handler.go
··· 13 13 "github.com/willdot/bskyfeedgen/store" 14 14 ) 15 15 16 + const ( 17 + myDid = "did:plc:dadhhalkfcq3gucaq25hjqon" 18 + ) 19 + 16 20 type HandlerStore interface { 17 21 AddFeedPost(feedItem store.FeedPost) error 18 22 GetSubscriptionsForPost(postURI string) ([]string, error) ··· 62 66 // look for posts that are "subscribe" so that we can add the post URI to a list of posts we want to find replies for 63 67 if strings.Contains(post.Text, "/subscribe") { 64 68 // For now just look for me 65 - if event.Did != "did:plc:dadhhalkfcq3gucaq25hjqon" { 69 + if event.Did != myDid { 66 70 return nil 67 71 } 68 72 slog.Info("a post that's subscribing to another post. Adding to posts to look for", "subscribed post URI", subscribedPostURI)
+5 -3
store/database.go
··· 15 15 } 16 16 17 17 func New(dbPath string) (*Store, error) { 18 - err := createDbFile(dbPath) 19 - if err != nil { 20 - return nil, fmt.Errorf("create db file: %w", err) 18 + if dbPath != ":memory:" { 19 + err := createDbFile(dbPath) 20 + if err != nil { 21 + return nil, fmt.Errorf("create db file: %w", err) 22 + } 21 23 } 22 24 23 25 db, err := sql.Open("sqlite", dbPath)
+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)