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/notify: move posthog notifier as subpackage

Also add NewIssueComment to the interface.

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

authored by

Anirudh Oppiliappan and committed by
Tangled
8c2d44b9 57ff984d

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