Monorepo for Tangled tangled.org

appview/notify: merge new comment events into one #1275

open opened by boltless.me targeting master from sl/comment
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mimbhgiqgy22
+168 -181
Diff #2
+1 -1
appview/issues/issues.go
··· 537 537 return 538 538 } 539 539 540 - rp.notifier.NewIssueComment(r.Context(), &comment, mentions) 540 + rp.notifier.NewComment(r.Context(), &comment, mentions) 541 541 542 542 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) 543 543 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d#comment-%d", ownerSlashRepo, issue.IssueId, comment.Id))
+137 -136
appview/notify/db/db.go
··· 77 77 // no-op 78 78 } 79 79 80 - func (n *databaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { 80 + func (n *databaseNotifier) NewComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 81 81 l := log.FromContext(ctx) 82 82 83 - collaborators, err := db.GetCollaborators(n.db, orm.FilterEq("repo_at", issue.Repo.RepoAt())) 84 - if err != nil { 85 - l.Error("failed to fetch collaborators", "err", err) 86 - return 87 - } 83 + var ( 84 + // built the recipients list: 85 + // - the owner of the repo 86 + // - | if the comment is a reply -> everybody on that thread 87 + // | if the comment is a top level -> just the issue owner 88 + // - remove mentioned users from the recipients list 89 + recipients = sets.New[syntax.DID]() 90 + entityType string 91 + entityId string 92 + repoId *int64 93 + issueId *int64 94 + pullId *int64 95 + ) 88 96 89 - // build the recipients list 90 - // - owner of the repo 91 - // - collaborators in the repo 92 - // - remove users already mentioned 93 - recipients := sets.Singleton(syntax.DID(issue.Repo.Did)) 94 - for _, c := range collaborators { 95 - recipients.Insert(c.SubjectDid) 96 - } 97 - for _, m := range mentions { 98 - recipients.Remove(m) 99 - } 97 + subjectAt := syntax.ATURI(comment.Subject.Uri) 100 98 101 - actorDid := syntax.DID(issue.Did) 102 - entityType := "issue" 103 - entityId := issue.AtUri().String() 104 - repoId := &issue.Repo.Id 105 - issueId := &issue.Id 106 - var pullId *int64 99 + switch subjectAt.Collection() { 100 + case tangled.RepoIssueNSID: 101 + issues, err := db.GetIssues( 102 + n.db, 103 + orm.FilterEq("at_uri", subjectAt), 104 + ) 105 + if err != nil { 106 + l.Error("failed to get issues", "err", err) 107 + return 108 + } 109 + if len(issues) == 0 { 110 + l.Error("no issue found", "subject", comment.Subject) 111 + return 112 + } 113 + issue := issues[0] 114 + 115 + recipients.Insert(syntax.DID(issue.Repo.Did)) 116 + if comment.IsReply() { 117 + // if this comment is a reply, then notify everybody in that thread 118 + parent := *comment.ReplyTo 119 + 120 + // find the parent thread, and add all DIDs from here to the recipient list 121 + for _, t := range issue.CommentList() { 122 + if t.Self.AtUri() == syntax.ATURI(parent.Uri) { 123 + for _, p := range t.Participants() { 124 + recipients.Insert(p) 125 + } 126 + } 127 + } 128 + } else { 129 + // not a reply, notify just the issue author 130 + recipients.Insert(syntax.DID(issue.Did)) 131 + } 132 + 133 + entityType = "issue" 134 + entityId = issue.AtUri().String() 135 + repoId = &issue.Repo.Id 136 + issueId = &issue.Id 137 + 138 + for _, m := range mentions { 139 + recipients.Remove(m) 140 + } 141 + 142 + n.notifyEvent( 143 + ctx, 144 + comment.Did, 145 + recipients, 146 + models.NotificationTypeIssueCommented, 147 + entityType, 148 + entityId, 149 + repoId, 150 + issueId, 151 + pullId, 152 + ) 153 + 154 + case tangled.RepoPullNSID: 155 + pulls, err := db.GetPulls( 156 + n.db, 157 + orm.FilterEq("owner_did", subjectAt.Authority()), 158 + orm.FilterEq("rkey", subjectAt.RecordKey()), 159 + ) 160 + if err != nil { 161 + l.Error("NewComment: failed to get pulls", "err", err) 162 + return 163 + } 164 + if len(pulls) == 0 { 165 + l.Error("NewComment: no pull found", "aturi", comment.Subject) 166 + return 167 + } 168 + pull := pulls[0] 169 + 170 + pull.Repo, err = db.GetRepo(n.db, orm.FilterEq("at_uri", pull.RepoAt)) 171 + if err != nil { 172 + l.Error("NewComment: failed to get repo", "err", err) 173 + return 174 + } 175 + 176 + recipients.Insert(syntax.DID(pull.Repo.Did)) 177 + for _, p := range pull.Participants() { 178 + recipients.Insert(syntax.DID(p)) 179 + } 180 + 181 + entityType = "pull" 182 + entityId = pull.AtUri().String() 183 + repoId = &pull.Repo.Id 184 + p := int64(pull.ID) 185 + pullId = &p 186 + 187 + for _, m := range mentions { 188 + recipients.Remove(m) 189 + } 190 + 191 + n.notifyEvent( 192 + ctx, 193 + comment.Did, 194 + recipients, 195 + models.NotificationTypePullCommented, 196 + entityType, 197 + entityId, 198 + repoId, 199 + issueId, 200 + pullId, 201 + ) 202 + default: 203 + return // no-op 204 + } 107 205 108 206 n.notifyEvent( 109 207 ctx, 110 - actorDid, 111 - recipients, 112 - models.NotificationTypeIssueCreated, 113 - entityType, 114 - entityId, 115 - repoId, 116 - issueId, 117 - pullId, 118 - ) 119 - n.notifyEvent( 120 - ctx, 121 - actorDid, 208 + comment.Did, 122 209 sets.Collect(slices.Values(mentions)), 123 210 models.NotificationTypeUserMentioned, 124 211 entityType, ··· 129 216 ) 130 217 } 131 218 132 - func (n *databaseNotifier) NewIssueComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 219 + func (n *databaseNotifier) DeleteComment(ctx context.Context, comment *models.Comment) { 220 + // no-op 221 + } 222 + 223 + func (n *databaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { 133 224 l := log.FromContext(ctx) 134 225 135 - issues, err := db.GetIssues(n.db, orm.FilterEq("at_uri", comment.Subject)) 226 + collaborators, err := db.GetCollaborators(n.db, orm.FilterEq("repo_at", issue.Repo.RepoAt())) 136 227 if err != nil { 137 - l.Error("failed to get issues", "err", err) 138 - return 139 - } 140 - if len(issues) == 0 { 141 - l.Error("no issue found for", "err", comment.Subject) 228 + l.Error("failed to fetch collaborators", "err", err) 142 229 return 143 230 } 144 - issue := issues[0] 145 231 146 - // built the recipients list: 147 - // - the owner of the repo 148 - // - | if the comment is a reply -> everybody on that thread 149 - // | if the comment is a top level -> just the issue owner 150 - // - remove mentioned users from the recipients list 232 + // build the recipients list 233 + // - owner of the repo 234 + // - collaborators in the repo 235 + // - remove users already mentioned 151 236 recipients := sets.Singleton(syntax.DID(issue.Repo.Did)) 152 - 153 - if comment.IsReply() { 154 - // if this comment is a reply, then notify everybody in that thread 155 - parent := *comment.ReplyTo 156 - 157 - // find the parent thread, and add all DIDs from here to the recipient list 158 - for _, t := range issue.CommentList() { 159 - if t.Self.AtUri() == syntax.ATURI(parent.Uri) { 160 - for _, p := range t.Participants() { 161 - recipients.Insert(p) 162 - } 163 - } 164 - } 165 - } else { 166 - // not a reply, notify just the issue author 167 - recipients.Insert(syntax.DID(issue.Did)) 237 + for _, c := range collaborators { 238 + recipients.Insert(c.SubjectDid) 168 239 } 169 - 170 240 for _, m := range mentions { 171 241 recipients.Remove(m) 172 242 } 173 243 174 - actorDid := syntax.DID(comment.Did) 244 + actorDid := syntax.DID(issue.Did) 175 245 entityType := "issue" 176 246 entityId := issue.AtUri().String() 177 247 repoId := &issue.Repo.Id ··· 182 252 ctx, 183 253 actorDid, 184 254 recipients, 185 - models.NotificationTypeIssueCommented, 255 + models.NotificationTypeIssueCreated, 186 256 entityType, 187 257 entityId, 188 258 repoId, ··· 278 348 ) 279 349 } 280 350 281 - func (n *databaseNotifier) NewPullComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 282 - l := log.FromContext(ctx) 283 - 284 - subjectAt := syntax.ATURI(comment.Subject.Uri) 285 - pulls, err := db.GetPulls(n.db, 286 - orm.FilterEq("owner_did", subjectAt.Authority()), 287 - orm.FilterEq("rkey", subjectAt.RecordKey()), 288 - ) 289 - if err != nil { 290 - l.Error("failed to get pull", "err", err) 291 - return 292 - } 293 - if len(pulls) == 0 { 294 - l.Error("NewPullComment: no pull found", "aturi", comment.Subject) 295 - return 296 - } 297 - pull := pulls[0] 298 - 299 - repo, err := db.GetRepo(n.db, orm.FilterEq("at_uri", pull.RepoAt)) 300 - if err != nil { 301 - l.Error("failed to get repos", "err", err) 302 - return 303 - } 304 - 305 - // build up the recipients list: 306 - // - repo owner 307 - // - all pull participants 308 - // - remove those already mentioned 309 - recipients := sets.Singleton(syntax.DID(repo.Did)) 310 - for _, p := range pull.Participants() { 311 - recipients.Insert(syntax.DID(p)) 312 - } 313 - for _, m := range mentions { 314 - recipients.Remove(m) 315 - } 316 - 317 - actorDid := comment.Did 318 - eventType := models.NotificationTypePullCommented 319 - entityType := "pull" 320 - entityId := pull.AtUri().String() 321 - repoId := &repo.Id 322 - var issueId *int64 323 - p := int64(pull.ID) 324 - pullId := &p 325 - 326 - n.notifyEvent( 327 - ctx, 328 - actorDid, 329 - recipients, 330 - eventType, 331 - entityType, 332 - entityId, 333 - repoId, 334 - issueId, 335 - pullId, 336 - ) 337 - n.notifyEvent( 338 - ctx, 339 - actorDid, 340 - sets.Collect(slices.Values(mentions)), 341 - models.NotificationTypeUserMentioned, 342 - entityType, 343 - entityId, 344 - repoId, 345 - issueId, 346 - pullId, 347 - ) 348 - } 349 - 350 351 func (n *databaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { 351 352 // no-op 352 353 }
+9 -10
appview/notify/logging/notifier.go
··· 36 36 l.inner.DeleteStar(ctx, star) 37 37 } 38 38 39 + func (l *loggingNotifier) NewComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 40 + ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewComment")) 41 + l.inner.NewComment(ctx, comment, mentions) 42 + } 43 + func (l *loggingNotifier) DeleteComment(ctx context.Context, comment *models.Comment) { 44 + ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "DeleteComment")) 45 + l.inner.DeleteComment(ctx, comment) 46 + } 47 + 39 48 func (l *loggingNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { 40 49 ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewIssue")) 41 50 l.inner.NewIssue(ctx, issue, mentions) 42 51 } 43 52 44 - func (l *loggingNotifier) NewIssueComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 45 - ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewIssueComment")) 46 - l.inner.NewIssueComment(ctx, comment, mentions) 47 - } 48 - 49 53 func (l *loggingNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 50 54 ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewIssueState")) 51 55 l.inner.NewIssueState(ctx, actor, issue) ··· 81 85 l.inner.NewPull(ctx, pull) 82 86 } 83 87 84 - func (l *loggingNotifier) NewPullComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 85 - ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewPullComment")) 86 - l.inner.NewPullComment(ctx, comment, mentions) 87 - } 88 - 89 88 func (l *loggingNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 90 89 ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewPullState")) 91 90 l.inner.NewPullState(ctx, actor, pull)
+8 -8
appview/notify/merged_notifier.go
··· 42 42 m.fanout(func(n Notifier) { n.DeleteStar(ctx, star) }) 43 43 } 44 44 45 - func (m *mergedNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { 46 - m.fanout(func(n Notifier) { n.NewIssue(ctx, issue, mentions) }) 45 + func (m *mergedNotifier) NewComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 46 + m.fanout(func(n Notifier) { n.NewComment(ctx, comment, mentions) }) 47 + } 48 + 49 + func (m *mergedNotifier) DeleteComment(ctx context.Context, comment *models.Comment) { 50 + m.fanout(func(n Notifier) { n.DeleteComment(ctx, comment) }) 47 51 } 48 52 49 - func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 50 - m.fanout(func(n Notifier) { n.NewIssueComment(ctx, comment, mentions) }) 53 + func (m *mergedNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { 54 + m.fanout(func(n Notifier) { n.NewIssue(ctx, issue, mentions) }) 51 55 } 52 56 53 57 func (m *mergedNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { ··· 78 82 m.fanout(func(n Notifier) { n.NewPull(ctx, pull) }) 79 83 } 80 84 81 - func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 82 - m.fanout(func(n Notifier) { n.NewPullComment(ctx, comment, mentions) }) 83 - } 84 - 85 85 func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 86 86 m.fanout(func(n Notifier) { n.NewPullState(ctx, actor, pull) }) 87 87 }
+8 -7
appview/notify/notifier.go
··· 13 13 NewStar(ctx context.Context, star *models.Star) 14 14 DeleteStar(ctx context.Context, star *models.Star) 15 15 16 + NewComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) 17 + DeleteComment(ctx context.Context, comment *models.Comment) 18 + 16 19 NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) 17 - NewIssueComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) 18 20 NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) 19 21 DeleteIssue(ctx context.Context, issue *models.Issue) 20 22 ··· 22 24 DeleteFollow(ctx context.Context, follow *models.Follow) 23 25 24 26 NewPull(ctx context.Context, pull *models.Pull) 25 - NewPullComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) 26 27 NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 28 28 29 NewIssueLabelOp(ctx context.Context, issue *models.Issue) ··· 49 50 func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} 50 51 func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} 51 52 52 - func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) {} 53 - func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 53 + func (m *BaseNotifier) NewComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 54 54 } 55 + func (m *BaseNotifier) DeleteComment(ctx context.Context, comment *models.Comment) {} 56 + 57 + func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) {} 55 58 func (m *BaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {} 56 59 func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 57 60 ··· 61 64 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 62 65 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {} 63 66 64 - func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} 65 - func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.Comment, mentions []syntax.DID) { 66 - } 67 + func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} 67 68 func (m *BaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) {} 68 69 69 70 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {}
+4 -18
appview/notify/posthog/notifier.go
··· 86 86 } 87 87 } 88 88 89 - func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 90 - err := n.client.Enqueue(posthog.Capture{ 91 - DistinctId: comment.Did.String(), 92 - Event: "new_pull_comment", 93 - Properties: posthog.Properties{ 94 - "pull_at": comment.Subject, 95 - "mentions": mentions, 96 - }, 97 - }) 98 - if err != nil { 99 - log.Println("failed to enqueue posthog event:", err) 100 - } 101 - } 102 - 103 89 func (n *posthogNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) { 104 90 err := n.client.Enqueue(posthog.Capture{ 105 91 DistinctId: pull.OwnerDid, ··· 190 176 } 191 177 } 192 178 193 - func (n *posthogNotifier) NewIssueComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 179 + func (n *posthogNotifier) NewComment(ctx context.Context, comment *models.Comment, mentions []syntax.DID) { 194 180 err := n.client.Enqueue(posthog.Capture{ 195 181 DistinctId: comment.Did.String(), 196 - Event: "new_issue_comment", 182 + Event: "new_comment", 197 183 Properties: posthog.Properties{ 198 - "issue_at": comment.Subject.Uri, 199 - "mentions": mentions, 184 + "subject_at": comment.Subject.Uri, 185 + "mentions": mentions, 200 186 }, 201 187 }) 202 188 if err != nil {
+1 -1
appview/pulls/pulls.go
··· 901 901 return 902 902 } 903 903 904 - s.notifier.NewPullComment(r.Context(), &comment, mentions) 904 + s.notifier.NewComment(r.Context(), &comment, mentions) 905 905 906 906 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) 907 907 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", ownerSlashRepo, pull.PullId, comment.Id))

History

10 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
no conflicts, ready to merge
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments
1 commit
expand
appview/notify: merge new comment events into one
3/3 failed
expand
expand 0 comments