appview/notify: notify users mentioned on PR comments #739

merged
opened by boltless.me targeting master from feat/mentions
Changed files
+32 -10
appview
+11 -1
appview/notify/db/db.go
··· 239 ) 240 } 241 242 - func (n *databaseNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) { 243 pull, err := db.GetPull(n.db, 244 syntax.ATURI(comment.RepoAt), 245 comment.PullId, ··· 283 issueId, 284 pullId, 285 ) 286 } 287 288 func (n *databaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
··· 239 ) 240 } 241 242 + func (n *databaseNotifier) NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) { 243 pull, err := db.GetPull(n.db, 244 syntax.ATURI(comment.RepoAt), 245 comment.PullId, ··· 283 issueId, 284 pullId, 285 ) 286 + n.notifyEvent( 287 + actorDid, 288 + mentions, 289 + models.NotificationTypeUserMentioned, 290 + entityType, 291 + entityId, 292 + repoId, 293 + issueId, 294 + pullId, 295 + ) 296 } 297 298 func (n *databaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
+2 -2
appview/notify/merged_notifier.go
··· 82 m.fanout("NewPull", ctx, pull) 83 } 84 85 - func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) { 86 - m.fanout("NewPullComment", ctx, comment) 87 } 88 89 func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) {
··· 82 m.fanout("NewPull", ctx, pull) 83 } 84 85 + func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) { 86 + m.fanout("NewPullComment", ctx, comment, mentions) 87 } 88 89 func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) {
+3 -3
appview/notify/notifier.go
··· 22 DeleteFollow(ctx context.Context, follow *models.Follow) 23 24 NewPull(ctx context.Context, pull *models.Pull) 25 - NewPullComment(ctx context.Context, comment *models.PullComment) 26 NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 28 UpdateProfile(ctx context.Context, profile *models.Profile) ··· 50 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 51 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {} 52 53 - func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} 54 - func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {} 55 func (m *BaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) {} 56 57 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {}
··· 22 DeleteFollow(ctx context.Context, follow *models.Follow) 23 24 NewPull(ctx context.Context, pull *models.Pull) 25 + NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) 26 NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 28 UpdateProfile(ctx context.Context, profile *models.Profile) ··· 50 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 51 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {} 52 53 + func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} 54 + func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment, mentions []syntax.DID) {} 55 func (m *BaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) {} 56 57 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {}
+4 -3
appview/notify/posthog/notifier.go
··· 86 } 87 } 88 89 - func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) { 90 err := n.client.Enqueue(posthog.Capture{ 91 DistinctId: comment.OwnerDid, 92 Event: "new_pull_comment", 93 Properties: posthog.Properties{ 94 - "repo_at": comment.RepoAt, 95 - "pull_id": comment.PullId, 96 }, 97 }) 98 if err != nil {
··· 86 } 87 } 88 89 + func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) { 90 err := n.client.Enqueue(posthog.Capture{ 91 DistinctId: comment.OwnerDid, 92 Event: "new_pull_comment", 93 Properties: posthog.Properties{ 94 + "repo_at": comment.RepoAt, 95 + "pull_id": comment.PullId, 96 + "mentions": mentions, 97 }, 98 }) 99 if err != nil {
+12 -1
appview/pulls/pulls.go
··· 33 "tangled.org/core/types" 34 35 comatproto "github.com/bluesky-social/indigo/api/atproto" 36 lexutil "github.com/bluesky-social/indigo/lex/util" 37 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 38 "github.com/go-chi/chi/v5" ··· 690 } 691 692 func (s *Pulls) PullComment(w http.ResponseWriter, r *http.Request) { 693 user := s.oauth.GetUser(r) 694 f, err := s.repoResolver.Resolve(r) 695 if err != nil { ··· 787 return 788 } 789 790 - s.notifier.NewPullComment(r.Context(), comment) 791 792 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", f.OwnerSlashRepo(), pull.PullId, commentId)) 793 return
··· 33 "tangled.org/core/types" 34 35 comatproto "github.com/bluesky-social/indigo/api/atproto" 36 + "github.com/bluesky-social/indigo/atproto/syntax" 37 lexutil "github.com/bluesky-social/indigo/lex/util" 38 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 39 "github.com/go-chi/chi/v5" ··· 691 } 692 693 func (s *Pulls) PullComment(w http.ResponseWriter, r *http.Request) { 694 + l := s.logger.With("handler", "PullComment") 695 user := s.oauth.GetUser(r) 696 f, err := s.repoResolver.Resolve(r) 697 if err != nil { ··· 789 return 790 } 791 792 + rawMentions := markup.FindUserMentions(comment.Body) 793 + idents := s.idResolver.ResolveIdents(r.Context(), rawMentions) 794 + l.Debug("parsed mentions", "raw", rawMentions, "idents", idents) 795 + var mentions []syntax.DID 796 + for _, ident := range idents { 797 + if ident != nil && !ident.Handle.IsInvalidHandle() { 798 + mentions = append(mentions, ident.DID) 799 + } 800 + } 801 + s.notifier.NewPullComment(r.Context(), comment, mentions) 802 803 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", f.OwnerSlashRepo(), pull.PullId, commentId)) 804 return