Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

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

appview: wrap posthog under unified notifier

- Make `db.New*()` methods to accept complete model object instead of
individual fields
- Remove `posthog` field from *most* Service structs. Oauth still has
one as an edge-case
- Add more notifier methods to replace posthog logics

Signed-off-by: Seongmin Lee <boltlessengineer@proton.me>

authored by

Seongmin Lee and committed by
Tangled
8273bd20 8ac30f1a

+273 -140
+2 -2
appview/db/follow.go
··· 12 12 Rkey string 13 13 } 14 14 15 - func AddFollow(e Execer, userDid, subjectDid, rkey string) error { 15 + func AddFollow(e Execer, follow *Follow) error { 16 16 query := `insert or ignore into follows (user_did, subject_did, rkey) values (?, ?, ?)` 17 - _, err := e.Exec(query, userDid, subjectDid, rkey) 17 + _, err := e.Exec(query, follow.UserDid, follow.SubjectDid, follow.Rkey) 18 18 return err 19 19 } 20 20
+7 -2
appview/db/star.go
··· 33 33 return nil 34 34 } 35 35 36 - func AddStar(e Execer, starredByDid string, repoAt syntax.ATURI, rkey string) error { 36 + func AddStar(e Execer, star *Star) error { 37 37 query := `insert or ignore into stars (starred_by_did, repo_at, rkey) values (?, ?, ?)` 38 - _, err := e.Exec(query, starredByDid, repoAt, rkey) 38 + _, err := e.Exec( 39 + query, 40 + star.StarredByDid, 41 + star.RepoAt.String(), 42 + star.Rkey, 43 + ) 39 44 return err 40 45 } 41 46
+10 -3
appview/ingester.go
··· 100 100 l.Error("invalid record", "err", err) 101 101 return err 102 102 } 103 - err = db.AddStar(i.Db, did, subjectUri, e.Commit.RKey) 103 + err = db.AddStar(i.Db, &db.Star{ 104 + StarredByDid: did, 105 + RepoAt: subjectUri, 106 + Rkey: e.Commit.RKey, 107 + }) 104 108 case models.CommitOperationDelete: 105 109 err = db.DeleteStarByRkey(i.Db, did, e.Commit.RKey) 106 110 } ··· 133 129 return err 134 130 } 135 131 136 - subjectDid := record.Subject 137 - err = db.AddFollow(i.Db, did, subjectDid, e.Commit.RKey) 132 + err = db.AddFollow(i.Db, &db.Follow{ 133 + UserDid: did, 134 + SubjectDid: record.Subject, 135 + Rkey: e.Commit.RKey, 136 + }) 138 137 case models.CommitOperationDelete: 139 138 err = db.DeleteFollowByRkey(i.Db, did, e.Commit.RKey) 140 139 }
+5 -14
appview/issues/issues.go
··· 14 14 "github.com/bluesky-social/indigo/atproto/syntax" 15 15 lexutil "github.com/bluesky-social/indigo/lex/util" 16 16 "github.com/go-chi/chi/v5" 17 - "github.com/posthog/posthog-go" 18 17 19 18 "tangled.sh/tangled.sh/core/api/tangled" 20 19 "tangled.sh/tangled.sh/core/appview" 21 20 "tangled.sh/tangled.sh/core/appview/config" 22 21 "tangled.sh/tangled.sh/core/appview/db" 23 22 "tangled.sh/tangled.sh/core/appview/idresolver" 23 + "tangled.sh/tangled.sh/core/appview/notify" 24 24 "tangled.sh/tangled.sh/core/appview/oauth" 25 25 "tangled.sh/tangled.sh/core/appview/pages" 26 26 "tangled.sh/tangled.sh/core/appview/pagination" ··· 34 34 idResolver *idresolver.Resolver 35 35 db *db.DB 36 36 config *config.Config 37 - posthog posthog.Client 37 + notifier notify.Notifier 38 38 } 39 39 40 40 func New( ··· 44 44 idResolver *idresolver.Resolver, 45 45 db *db.DB, 46 46 config *config.Config, 47 - posthog posthog.Client, 47 + notifier notify.Notifier, 48 48 ) *Issues { 49 49 return &Issues{ 50 50 oauth: oauth, ··· 53 53 idResolver: idResolver, 54 54 db: db, 55 55 config: config, 56 - posthog: posthog, 56 + notifier: notifier, 57 57 } 58 58 } 59 59 ··· 750 750 return 751 751 } 752 752 753 - if !rp.config.Core.Dev { 754 - err = rp.posthog.Enqueue(posthog.Capture{ 755 - DistinctId: user.Did, 756 - Event: "new_issue", 757 - Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issue.IssueId}, 758 - }) 759 - if err != nil { 760 - log.Println("failed to enqueue posthog event:", err) 761 - } 762 - } 753 + rp.notifier.NewIssue(r.Context(), issue) 763 754 764 755 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 765 756 return
+37 -6
appview/notify/merged_notifier.go
··· 11 11 } 12 12 13 13 func NewMergedNotifier(notifiers ...Notifier) Notifier { 14 - return &mergedNotifier{ 15 - notifiers, 16 - } 14 + return &mergedNotifier{notifiers} 17 15 } 18 16 19 17 var _ Notifier = &mergedNotifier{} 18 + 19 + func (m *mergedNotifier) NewRepo(ctx context.Context, repo *db.Repo) { 20 + for _, notifier := range m.notifiers { 21 + notifier.NewRepo(ctx, repo) 22 + } 23 + } 24 + 25 + func (m *mergedNotifier) NewStar(ctx context.Context, star *db.Star) { 26 + for _, notifier := range m.notifiers { 27 + notifier.NewStar(ctx, star) 28 + } 29 + } 30 + func (m *mergedNotifier) DeleteStar(ctx context.Context, star *db.Star) { 31 + for _, notifier := range m.notifiers { 32 + notifier.DeleteStar(ctx, star) 33 + } 34 + } 20 35 21 36 func (m *mergedNotifier) NewIssue(ctx context.Context, issue *db.Issue) { 22 37 for _, notifier := range m.notifiers { ··· 39 24 } 40 25 } 41 26 42 - func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment db.Comment) { 27 + func (m *mergedNotifier) NewFollow(ctx context.Context, follow *db.Follow) { 43 28 for _, notifier := range m.notifiers { 44 - notifier.NewIssueComment(ctx, comment) 29 + notifier.NewFollow(ctx, follow) 30 + } 31 + } 32 + func (m *mergedNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) { 33 + for _, notifier := range m.notifiers { 34 + notifier.DeleteFollow(ctx, follow) 45 35 } 46 36 } 47 37 48 - func (m *mergedNotifier) NewPullComment(ctx context.Context, comment db.PullComment) { 38 + func (m *mergedNotifier) NewPull(ctx context.Context, pull *db.Pull) { 39 + for _, notifier := range m.notifiers { 40 + notifier.NewPull(ctx, pull) 41 + } 42 + } 43 + func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) { 49 44 for _, notifier := range m.notifiers { 50 45 notifier.NewPullComment(ctx, comment) 46 + } 47 + } 48 + 49 + func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) { 50 + for _, notifier := range m.notifiers { 51 + notifier.UpdateProfile(ctx, profile) 51 52 } 52 53 }
+33 -3
appview/notify/notifier.go
··· 7 7 ) 8 8 9 9 type Notifier interface { 10 - NewIssue(ctx context.Context, issue *db.Issue) 11 - NewIssueComment(ctx context.Context, comment db.Comment) 10 + NewRepo(ctx context.Context, repo *db.Repo) 12 11 13 - NewPullComment(ctx context.Context, comment db.PullComment) 12 + NewStar(ctx context.Context, star *db.Star) 13 + DeleteStar(ctx context.Context, star *db.Star) 14 + 15 + NewIssue(ctx context.Context, issue *db.Issue) 16 + 17 + NewFollow(ctx context.Context, follow *db.Follow) 18 + DeleteFollow(ctx context.Context, follow *db.Follow) 19 + 20 + NewPull(ctx context.Context, pull *db.Pull) 21 + NewPullComment(ctx context.Context, comment *db.PullComment) 22 + 23 + UpdateProfile(ctx context.Context, profile *db.Profile) 14 24 } 25 + 26 + // BaseNotifier is a listener that does nothing 27 + type BaseNotifier struct{} 28 + 29 + var _ Notifier = &BaseNotifier{} 30 + 31 + func (m *BaseNotifier) NewRepo(ctx context.Context, repo *db.Repo) {} 32 + 33 + func (m *BaseNotifier) NewStar(ctx context.Context, star *db.Star) {} 34 + func (m *BaseNotifier) DeleteStar(ctx context.Context, star *db.Star) {} 35 + 36 + func (m *BaseNotifier) NewIssue(ctx context.Context, issue *db.Issue) {} 37 + 38 + func (m *BaseNotifier) NewFollow(ctx context.Context, follow *db.Follow) {} 39 + func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {} 40 + 41 + func (m *BaseNotifier) NewPull(ctx context.Context, pull *db.Pull) {} 42 + func (m *BaseNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {} 43 + 44 + func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {}
-4
appview/pipelines/pipelines.go
··· 22 22 23 23 "github.com/go-chi/chi/v5" 24 24 "github.com/gorilla/websocket" 25 - "github.com/posthog/posthog-go" 26 25 ) 27 26 28 27 type Pipelines struct { ··· 33 34 spindlestream *eventconsumer.Consumer 34 35 db *db.DB 35 36 enforcer *rbac.Enforcer 36 - posthog posthog.Client 37 37 logger *slog.Logger 38 38 } 39 39 ··· 44 46 idResolver *idresolver.Resolver, 45 47 db *db.DB, 46 48 config *config.Config, 47 - posthog posthog.Client, 48 49 enforcer *rbac.Enforcer, 49 50 ) *Pipelines { 50 51 logger := log.New("pipelines") ··· 55 58 config: config, 56 59 spindlestream: spindlestream, 57 60 db: db, 58 - posthog: posthog, 59 61 enforcer: enforcer, 60 62 logger: logger, 61 63 }
+131
appview/posthog/notifier.go
··· 1 + package posthog_service 2 + 3 + import ( 4 + "context" 5 + "log" 6 + 7 + "github.com/posthog/posthog-go" 8 + "tangled.sh/tangled.sh/core/appview/db" 9 + "tangled.sh/tangled.sh/core/appview/notify" 10 + ) 11 + 12 + type posthogNotifier struct { 13 + client posthog.Client 14 + notify.BaseNotifier 15 + } 16 + 17 + func NewPosthogNotifier(client posthog.Client) notify.Notifier { 18 + return &posthogNotifier{ 19 + client, 20 + notify.BaseNotifier{}, 21 + } 22 + } 23 + 24 + var _ notify.Notifier = &posthogNotifier{} 25 + 26 + func (n *posthogNotifier) NewRepo(ctx context.Context, repo *db.Repo) { 27 + err := n.client.Enqueue(posthog.Capture{ 28 + DistinctId: repo.Did, 29 + Event: "new_repo", 30 + Properties: posthog.Properties{"repo": repo.Name, "repo_at": repo.RepoAt()}, 31 + }) 32 + if err != nil { 33 + log.Println("failed to enqueue posthog event:", err) 34 + } 35 + } 36 + 37 + func (n *posthogNotifier) NewStar(ctx context.Context, star *db.Star) { 38 + err := n.client.Enqueue(posthog.Capture{ 39 + DistinctId: star.StarredByDid, 40 + Event: "star", 41 + Properties: posthog.Properties{"repo_at": star.RepoAt.String()}, 42 + }) 43 + if err != nil { 44 + log.Println("failed to enqueue posthog event:", err) 45 + } 46 + } 47 + 48 + func (n *posthogNotifier) DeleteStar(ctx context.Context, star *db.Star) { 49 + err := n.client.Enqueue(posthog.Capture{ 50 + DistinctId: star.StarredByDid, 51 + Event: "unstar", 52 + Properties: posthog.Properties{"repo_at": star.RepoAt.String()}, 53 + }) 54 + if err != nil { 55 + log.Println("failed to enqueue posthog event:", err) 56 + } 57 + } 58 + 59 + func (n *posthogNotifier) NewIssue(ctx context.Context, issue *db.Issue) { 60 + err := n.client.Enqueue(posthog.Capture{ 61 + DistinctId: issue.OwnerDid, 62 + Event: "new_issue", 63 + Properties: posthog.Properties{ 64 + "repo_at": issue.RepoAt.String(), 65 + "issue_id": issue.IssueId, 66 + }, 67 + }) 68 + if err != nil { 69 + log.Println("failed to enqueue posthog event:", err) 70 + } 71 + } 72 + 73 + func (n *posthogNotifier) NewPull(ctx context.Context, pull *db.Pull) { 74 + err := n.client.Enqueue(posthog.Capture{ 75 + DistinctId: pull.OwnerDid, 76 + Event: "new_pull", 77 + Properties: posthog.Properties{ 78 + "repo_at": pull.RepoAt, 79 + "pull_id": pull.PullId, 80 + }, 81 + }) 82 + if err != nil { 83 + log.Println("failed to enqueue posthog event:", err) 84 + } 85 + } 86 + 87 + func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) { 88 + err := n.client.Enqueue(posthog.Capture{ 89 + DistinctId: comment.OwnerDid, 90 + Event: "new_pull_comment", 91 + Properties: posthog.Properties{ 92 + "repo_at": comment.RepoAt, 93 + "pull_id": comment.PullId, 94 + }, 95 + }) 96 + if err != nil { 97 + log.Println("failed to enqueue posthog event:", err) 98 + } 99 + } 100 + 101 + func (n *posthogNotifier) NewFollow(ctx context.Context, follow *db.Follow) { 102 + err := n.client.Enqueue(posthog.Capture{ 103 + DistinctId: follow.UserDid, 104 + Event: "follow", 105 + Properties: posthog.Properties{"subject": follow.SubjectDid}, 106 + }) 107 + if err != nil { 108 + log.Println("failed to enqueue posthog event:", err) 109 + } 110 + } 111 + 112 + func (n *posthogNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) { 113 + err := n.client.Enqueue(posthog.Capture{ 114 + DistinctId: follow.UserDid, 115 + Event: "unfollow", 116 + Properties: posthog.Properties{"subject": follow.SubjectDid}, 117 + }) 118 + if err != nil { 119 + log.Println("failed to enqueue posthog event:", err) 120 + } 121 + } 122 + 123 + func (n *posthogNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) { 124 + err := n.client.Enqueue(posthog.Capture{ 125 + DistinctId: profile.Did, 126 + Event: "edit_profile", 127 + }) 128 + if err != nil { 129 + log.Println("failed to enqueue posthog event:", err) 130 + } 131 + }
+14 -29
appview/pulls/pulls.go
··· 18 18 "tangled.sh/tangled.sh/core/appview/config" 19 19 "tangled.sh/tangled.sh/core/appview/db" 20 20 "tangled.sh/tangled.sh/core/appview/idresolver" 21 + "tangled.sh/tangled.sh/core/appview/notify" 21 22 "tangled.sh/tangled.sh/core/appview/oauth" 22 23 "tangled.sh/tangled.sh/core/appview/pages" 23 24 "tangled.sh/tangled.sh/core/appview/reporesolver" ··· 32 31 lexutil "github.com/bluesky-social/indigo/lex/util" 33 32 "github.com/go-chi/chi/v5" 34 33 "github.com/google/uuid" 35 - "github.com/posthog/posthog-go" 36 34 ) 37 35 38 36 type Pulls struct { ··· 41 41 idResolver *idresolver.Resolver 42 42 db *db.DB 43 43 config *config.Config 44 - posthog posthog.Client 44 + notifier notify.Notifier 45 45 } 46 46 47 47 func New( ··· 51 51 resolver *idresolver.Resolver, 52 52 db *db.DB, 53 53 config *config.Config, 54 - posthog posthog.Client, 54 + notifier notify.Notifier, 55 55 ) *Pulls { 56 56 return &Pulls{ 57 57 oauth: oauth, ··· 60 60 idResolver: resolver, 61 61 db: db, 62 62 config: config, 63 - posthog: posthog, 63 + notifier: notifier, 64 64 } 65 65 } 66 66 ··· 685 685 return 686 686 } 687 687 688 - // Create the pull comment in the database with the commentAt field 689 - commentId, err := db.NewPullComment(tx, &db.PullComment{ 688 + comment := &db.PullComment{ 690 689 OwnerDid: user.Did, 691 690 RepoAt: f.RepoAt.String(), 692 691 PullId: pull.PullId, 693 692 Body: body, 694 693 CommentAt: atResp.Uri, 695 694 SubmissionId: pull.Submissions[roundNumber].ID, 696 - }) 695 + } 696 + 697 + // Create the pull comment in the database with the commentAt field 698 + commentId, err := db.NewPullComment(tx, comment) 697 699 if err != nil { 698 700 log.Println("failed to create pull comment", err) 699 701 s.pages.Notice(w, "pull-comment", "Failed to create comment.") ··· 709 707 return 710 708 } 711 709 712 - if !s.config.Core.Dev { 713 - err = s.posthog.Enqueue(posthog.Capture{ 714 - DistinctId: user.Did, 715 - Event: "new_pull_comment", 716 - Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "pull_id": pull.PullId}, 717 - }) 718 - if err != nil { 719 - log.Println("failed to enqueue posthog event:", err) 720 - } 721 - } 710 + s.notifier.NewPullComment(r.Context(), comment) 722 711 723 712 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", f.OwnerSlashRepo(), pull.PullId, commentId)) 724 713 return ··· 1043 1050 Patch: patch, 1044 1051 SourceRev: sourceRev, 1045 1052 } 1046 - err = db.NewPull(tx, &db.Pull{ 1053 + pull := &db.Pull{ 1047 1054 Title: title, 1048 1055 Body: body, 1049 1056 TargetBranch: targetBranch, ··· 1054 1061 &initialSubmission, 1055 1062 }, 1056 1063 PullSource: pullSource, 1057 - }) 1064 + } 1065 + err = db.NewPull(tx, pull) 1058 1066 if err != nil { 1059 1067 log.Println("failed to create pull request", err) 1060 1068 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") ··· 1095 1101 return 1096 1102 } 1097 1103 1098 - if !s.config.Core.Dev { 1099 - err = s.posthog.Enqueue(posthog.Capture{ 1100 - DistinctId: user.Did, 1101 - Event: "new_pull", 1102 - Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "pull_id": pullId}, 1103 - }) 1104 - if err != nil { 1105 - log.Println("failed to enqueue posthog event:", err) 1106 - } 1107 - } 1104 + s.notifier.NewPull(r.Context(), pull) 1108 1105 1109 1106 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId)) 1110 1107 }
+4 -4
appview/repo/repo.go
··· 21 21 "tangled.sh/tangled.sh/core/appview/config" 22 22 "tangled.sh/tangled.sh/core/appview/db" 23 23 "tangled.sh/tangled.sh/core/appview/idresolver" 24 + "tangled.sh/tangled.sh/core/appview/notify" 24 25 "tangled.sh/tangled.sh/core/appview/oauth" 25 26 "tangled.sh/tangled.sh/core/appview/pages" 26 27 "tangled.sh/tangled.sh/core/appview/pages/markup" ··· 35 34 securejoin "github.com/cyphar/filepath-securejoin" 36 35 "github.com/go-chi/chi/v5" 37 36 "github.com/go-git/go-git/v5/plumbing" 38 - "github.com/posthog/posthog-go" 39 37 40 38 comatproto "github.com/bluesky-social/indigo/api/atproto" 41 39 lexutil "github.com/bluesky-social/indigo/lex/util" ··· 49 49 spindlestream *eventconsumer.Consumer 50 50 db *db.DB 51 51 enforcer *rbac.Enforcer 52 - posthog posthog.Client 52 + notifier notify.Notifier 53 53 } 54 54 55 55 func New( ··· 60 60 idResolver *idresolver.Resolver, 61 61 db *db.DB, 62 62 config *config.Config, 63 - posthog posthog.Client, 63 + notifier notify.Notifier, 64 64 enforcer *rbac.Enforcer, 65 65 ) *Repo { 66 66 return &Repo{oauth: oauth, ··· 70 70 config: config, 71 71 spindlestream: spindlestream, 72 72 db: db, 73 - posthog: posthog, 73 + notifier: notifier, 74 74 enforcer: enforcer, 75 75 } 76 76 }
+11 -24
appview/state/follow.go
··· 7 7 8 8 comatproto "github.com/bluesky-social/indigo/api/atproto" 9 9 lexutil "github.com/bluesky-social/indigo/lex/util" 10 - "github.com/posthog/posthog-go" 11 10 "tangled.sh/tangled.sh/core/api/tangled" 12 11 "tangled.sh/tangled.sh/core/appview" 13 12 "tangled.sh/tangled.sh/core/appview/db" ··· 57 58 return 58 59 } 59 60 60 - err = db.AddFollow(s.db, currentUser.Did, subjectIdent.DID.String(), rkey) 61 + log.Println("created atproto record: ", resp.Uri) 62 + 63 + follow := &db.Follow{ 64 + UserDid: currentUser.Did, 65 + SubjectDid: subjectIdent.DID.String(), 66 + Rkey: rkey, 67 + } 68 + 69 + err = db.AddFollow(s.db, follow) 61 70 if err != nil { 62 71 log.Println("failed to follow", err) 63 72 return 64 73 } 65 74 66 - log.Println("created atproto record: ", resp.Uri) 75 + s.notifier.NewFollow(r.Context(), follow) 67 76 68 77 s.pages.FollowFragment(w, pages.FollowFragmentParams{ 69 78 UserDid: subjectIdent.DID.String(), 70 79 FollowStatus: db.IsFollowing, 71 80 }) 72 - 73 - if !s.config.Core.Dev { 74 - err = s.posthog.Enqueue(posthog.Capture{ 75 - DistinctId: currentUser.Did, 76 - Event: "follow", 77 - Properties: posthog.Properties{"subject": subjectIdent.DID.String()}, 78 - }) 79 - if err != nil { 80 - log.Println("failed to enqueue posthog event:", err) 81 - } 82 - } 83 81 84 82 return 85 83 case http.MethodDelete: ··· 109 113 FollowStatus: db.IsNotFollowing, 110 114 }) 111 115 112 - if !s.config.Core.Dev { 113 - err = s.posthog.Enqueue(posthog.Capture{ 114 - DistinctId: currentUser.Did, 115 - Event: "unfollow", 116 - Properties: posthog.Properties{"subject": subjectIdent.DID.String()}, 117 - }) 118 - if err != nil { 119 - log.Println("failed to enqueue posthog event:", err) 120 - } 121 - } 116 + s.notifier.DeleteFollow(r.Context(), follow) 122 117 123 118 return 124 119 }
+1 -10
appview/state/profile.go
··· 16 16 "github.com/bluesky-social/indigo/atproto/syntax" 17 17 lexutil "github.com/bluesky-social/indigo/lex/util" 18 18 "github.com/go-chi/chi/v5" 19 - "github.com/posthog/posthog-go" 20 19 "tangled.sh/tangled.sh/core/api/tangled" 21 20 "tangled.sh/tangled.sh/core/appview/db" 22 21 "tangled.sh/tangled.sh/core/appview/pages" ··· 370 371 return 371 372 } 372 373 373 - if !s.config.Core.Dev { 374 - err = s.posthog.Enqueue(posthog.Capture{ 375 - DistinctId: user.Did, 376 - Event: "edit_profile", 377 - }) 378 - if err != nil { 379 - log.Println("failed to enqueue posthog event:", err) 380 - } 381 - } 374 + s.notifier.UpdateProfile(r.Context(), profile) 382 375 383 376 s.pages.HxRedirect(w, "/"+user.Did) 384 377 return
+4 -4
appview/state/router.go
··· 198 198 } 199 199 200 200 func (s *State) IssuesRouter(mw *middleware.Middleware) http.Handler { 201 - issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog) 201 + issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.notifier) 202 202 return issues.Router(mw) 203 203 } 204 204 205 205 func (s *State) PullsRouter(mw *middleware.Middleware) http.Handler { 206 - pulls := pulls.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog) 206 + pulls := pulls.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.notifier) 207 207 return pulls.Router(mw) 208 208 } 209 209 210 210 func (s *State) RepoRouter(mw *middleware.Middleware) http.Handler { 211 - repo := repo.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.posthog, s.enforcer) 211 + repo := repo.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.notifier, s.enforcer) 212 212 return repo.Router(mw) 213 213 } 214 214 215 215 func (s *State) PipelinesRouter(mw *middleware.Middleware) http.Handler { 216 - pipes := pipelines.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.posthog, s.enforcer) 216 + pipes := pipelines.New(s.oauth, s.repoResolver, s.pages, s.spindlestream, s.idResolver, s.db, s.config, s.enforcer) 217 217 return pipes.Router(mw) 218 218 }
+11 -25
appview/state/star.go
··· 8 8 comatproto "github.com/bluesky-social/indigo/api/atproto" 9 9 "github.com/bluesky-social/indigo/atproto/syntax" 10 10 lexutil "github.com/bluesky-social/indigo/lex/util" 11 - "github.com/posthog/posthog-go" 12 11 "tangled.sh/tangled.sh/core/api/tangled" 13 12 "tangled.sh/tangled.sh/core/appview" 14 13 "tangled.sh/tangled.sh/core/appview/db" ··· 53 54 log.Println("failed to create atproto record", err) 54 55 return 55 56 } 57 + log.Println("created atproto record: ", resp.Uri) 56 58 57 - err = db.AddStar(s.db, currentUser.Did, subjectUri, rkey) 59 + star := &db.Star{ 60 + StarredByDid: currentUser.Did, 61 + RepoAt: subjectUri, 62 + Rkey: rkey, 63 + } 64 + 65 + err = db.AddStar(s.db, star) 58 66 if err != nil { 59 67 log.Println("failed to star", err) 60 68 return ··· 72 66 log.Println("failed to get star count for ", subjectUri) 73 67 } 74 68 75 - log.Println("created atproto record: ", resp.Uri) 69 + s.notifier.NewStar(r.Context(), star) 76 70 77 71 s.pages.RepoActionsFragment(w, pages.RepoActionsFragmentParams{ 78 72 IsStarred: true, ··· 81 75 StarCount: starCount, 82 76 }, 83 77 }) 84 - 85 - if !s.config.Core.Dev { 86 - err = s.posthog.Enqueue(posthog.Capture{ 87 - DistinctId: currentUser.Did, 88 - Event: "star", 89 - Properties: posthog.Properties{"repo_at": subjectUri.String()}, 90 - }) 91 - if err != nil { 92 - log.Println("failed to enqueue posthog event:", err) 93 - } 94 - } 95 78 96 79 return 97 80 case http.MethodDelete: ··· 114 119 return 115 120 } 116 121 122 + s.notifier.DeleteStar(r.Context(), star) 123 + 117 124 s.pages.RepoActionsFragment(w, pages.RepoActionsFragmentParams{ 118 125 IsStarred: false, 119 126 RepoAt: subjectUri, ··· 123 126 StarCount: starCount, 124 127 }, 125 128 }) 126 - 127 - if !s.config.Core.Dev { 128 - err = s.posthog.Enqueue(posthog.Capture{ 129 - DistinctId: currentUser.Did, 130 - Event: "unstar", 131 - Properties: posthog.Properties{"repo_at": subjectUri.String()}, 132 - }) 133 - if err != nil { 134 - log.Println("failed to enqueue posthog event:", err) 135 - } 136 - } 137 129 138 130 return 139 131 }
+3 -10
appview/state/state.go
··· 25 25 "tangled.sh/tangled.sh/core/appview/notify" 26 26 "tangled.sh/tangled.sh/core/appview/oauth" 27 27 "tangled.sh/tangled.sh/core/appview/pages" 28 + posthog_service "tangled.sh/tangled.sh/core/appview/posthog" 28 29 "tangled.sh/tangled.sh/core/appview/reporesolver" 29 30 "tangled.sh/tangled.sh/core/eventconsumer" 30 31 "tangled.sh/tangled.sh/core/jetstream" ··· 135 134 spindlestream.Start(ctx) 136 135 137 136 notifier := notify.NewMergedNotifier( 137 + posthog_service.NewPosthogNotifier(posthog), 138 138 ) 139 139 140 140 state := &State{ ··· 768 766 return 769 767 } 770 768 771 - if !s.config.Core.Dev { 772 - err = s.posthog.Enqueue(posthog.Capture{ 773 - DistinctId: user.Did, 774 - Event: "new_repo", 775 - Properties: posthog.Properties{"repo": repoName, "repo_at": repo.AtUri}, 776 - }) 777 - if err != nil { 778 - log.Println("failed to enqueue posthog event:", err) 779 - } 780 - } 769 + s.notifier.NewRepo(r.Context(), repo) 781 770 782 771 s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s", user.Handle, repoName)) 783 772 return