forked from tangled.org/core
Monorepo for Tangled

appview/notify: move posthog notifier as subpackage

Also add NewIssueComment to the interface.

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.sh>

authored by anirudh.fi and committed by anirudh.fi 4a966c03 a0222dde

Changed files
+78 -6
appview
+11
appview/notify/merged_notifier.go
··· 38 notifier.NewIssue(ctx, issue) 39 } 40 } 41 42 func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 43 for _, notifier := range m.notifiers {
··· 38 notifier.NewIssue(ctx, issue) 39 } 40 } 41 + func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) { 42 + for _, notifier := range m.notifiers { 43 + notifier.NewIssueComment(ctx, comment) 44 + } 45 + } 46 + 47 + func (m *mergedNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) { 48 + for _, notifier := range m.notifiers { 49 + notifier.NewIssueClosed(ctx, issue) 50 + } 51 + } 52 53 func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 54 for _, notifier := range m.notifiers {
+5 -1
appview/notify/notifier.go
··· 13 DeleteStar(ctx context.Context, star *models.Star) 14 15 NewIssue(ctx context.Context, issue *models.Issue) 16 17 NewFollow(ctx context.Context, follow *models.Follow) 18 DeleteFollow(ctx context.Context, follow *models.Follow) ··· 37 func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} 38 func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} 39 40 - func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} 41 42 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 43 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {}
··· 13 DeleteStar(ctx context.Context, star *models.Star) 14 15 NewIssue(ctx context.Context, issue *models.Issue) 16 + NewIssueComment(ctx context.Context, comment *models.IssueComment) 17 + NewIssueClosed(ctx context.Context, issue *models.Issue) 18 19 NewFollow(ctx context.Context, follow *models.Follow) 20 DeleteFollow(ctx context.Context, follow *models.Follow) ··· 39 func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} 40 func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} 41 42 + func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} 43 + func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) {} 44 + func (m *BaseNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) {} 45 46 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 47 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {}
+58 -3
appview/posthog/notifier.go appview/notify/posthog/notifier.go
··· 1 - package posthog_service 2 3 import ( 4 "context" ··· 98 } 99 } 100 101 func (n *posthogNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 102 err := n.client.Enqueue(posthog.Capture{ 103 DistinctId: follow.UserDid, ··· 152 } 153 } 154 155 - func (n *posthogNotifier) CreateString(ctx context.Context, string models.String) { 156 err := n.client.Enqueue(posthog.Capture{ 157 DistinctId: string.Did.String(), 158 - Event: "create_string", 159 Properties: posthog.Properties{"rkey": string.Rkey}, 160 }) 161 if err != nil { 162 log.Println("failed to enqueue posthog event:", err) 163 } 164 }
··· 1 + package posthog 2 3 import ( 4 "context" ··· 98 } 99 } 100 101 + func (n *posthogNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) { 102 + err := n.client.Enqueue(posthog.Capture{ 103 + DistinctId: pull.OwnerDid, 104 + Event: "pull_closed", 105 + Properties: posthog.Properties{ 106 + "repo_at": pull.RepoAt, 107 + "pull_id": pull.PullId, 108 + }, 109 + }) 110 + if err != nil { 111 + log.Println("failed to enqueue posthog event:", err) 112 + } 113 + } 114 + 115 func (n *posthogNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 116 err := n.client.Enqueue(posthog.Capture{ 117 DistinctId: follow.UserDid, ··· 166 } 167 } 168 169 + func (n *posthogNotifier) NewString(ctx context.Context, string *models.String) { 170 err := n.client.Enqueue(posthog.Capture{ 171 DistinctId: string.Did.String(), 172 + Event: "new_string", 173 Properties: posthog.Properties{"rkey": string.Rkey}, 174 }) 175 if err != nil { 176 log.Println("failed to enqueue posthog event:", err) 177 } 178 } 179 + 180 + func (n *posthogNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) { 181 + err := n.client.Enqueue(posthog.Capture{ 182 + DistinctId: comment.Did, 183 + Event: "new_issue_comment", 184 + Properties: posthog.Properties{ 185 + "issue_at": comment.IssueAt, 186 + }, 187 + }) 188 + if err != nil { 189 + log.Println("failed to enqueue posthog event:", err) 190 + } 191 + } 192 + 193 + func (n *posthogNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) { 194 + err := n.client.Enqueue(posthog.Capture{ 195 + DistinctId: issue.Did, 196 + Event: "issue_closed", 197 + Properties: posthog.Properties{ 198 + "repo_at": issue.RepoAt.String(), 199 + "issue_id": issue.IssueId, 200 + }, 201 + }) 202 + if err != nil { 203 + log.Println("failed to enqueue posthog event:", err) 204 + } 205 + } 206 + 207 + func (n *posthogNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) { 208 + err := n.client.Enqueue(posthog.Capture{ 209 + DistinctId: pull.OwnerDid, 210 + Event: "pull_merged", 211 + Properties: posthog.Properties{ 212 + "repo_at": pull.RepoAt, 213 + "pull_id": pull.PullId, 214 + }, 215 + }) 216 + if err != nil { 217 + log.Println("failed to enqueue posthog event:", err) 218 + } 219 + }
+2
appview/state/router.go
··· 156 r.Mount("/strings", s.StringsRouter(mw)) 157 r.Mount("/knots", s.KnotsRouter()) 158 r.Mount("/spindles", s.SpindlesRouter()) 159 r.Mount("/signup", s.SignupRouter()) 160 r.Mount("/", s.OAuthRouter()) 161
··· 156 r.Mount("/strings", s.StringsRouter(mw)) 157 r.Mount("/knots", s.KnotsRouter()) 158 r.Mount("/spindles", s.SpindlesRouter()) 159 + r.Mount("/notifications", s.NotificationsRouter(mw)) 160 + 161 r.Mount("/signup", s.SignupRouter()) 162 r.Mount("/", s.OAuthRouter()) 163
+2 -2
appview/state/state.go
··· 25 "tangled.org/core/appview/db" 26 "tangled.org/core/appview/models" 27 "tangled.org/core/appview/notify" 28 "tangled.org/core/appview/oauth" 29 "tangled.org/core/appview/pages" 30 - posthogService "tangled.org/core/appview/posthog" 31 "tangled.org/core/appview/reporesolver" 32 "tangled.org/core/appview/validator" 33 xrpcclient "tangled.org/core/appview/xrpcclient" ··· 149 150 var notifiers []notify.Notifier 151 if !config.Core.Dev { 152 - notifiers = append(notifiers, posthogService.NewPosthogNotifier(posthog)) 153 } 154 notifier := notify.NewMergedNotifier(notifiers...) 155
··· 25 "tangled.org/core/appview/db" 26 "tangled.org/core/appview/models" 27 "tangled.org/core/appview/notify" 28 + phnotify "tangled.org/core/appview/notify/posthog" 29 "tangled.org/core/appview/oauth" 30 "tangled.org/core/appview/pages" 31 "tangled.org/core/appview/reporesolver" 32 "tangled.org/core/appview/validator" 33 xrpcclient "tangled.org/core/appview/xrpcclient" ··· 149 150 var notifiers []notify.Notifier 151 if !config.Core.Dev { 152 + notifiers = append(notifiers, phnotify.NewPosthogNotifier(posthog)) 153 } 154 notifier := notify.NewMergedNotifier(notifiers...) 155