forked from tangled.org/core
this repo has no description

appview: add `NewIssueComment` event

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

boltless.me 171488e2 28409862

verified
Changed files
+40 -28
appview
-12
appview/db/issues.go
··· 94 94 return nil 95 95 } 96 96 97 - func GetIssueAt(e Execer, repoAt syntax.ATURI, issueId int) (string, error) { 98 - var issueAt string 99 - err := e.QueryRow(`select issue_at from issues where repo_at = ? and issue_id = ?`, repoAt, issueId).Scan(&issueAt) 100 - return issueAt, err 101 - } 102 - 103 - func GetIssueOwnerDid(e Execer, repoAt syntax.ATURI, issueId int) (string, error) { 104 - var ownerDid string 105 - err := e.QueryRow(`select owner_did from issues where repo_at = ? and issue_id = ?`, repoAt, issueId).Scan(&ownerDid) 106 - return ownerDid, err 107 - } 108 - 109 97 func GetIssuesPaginated(e Execer, repoAt syntax.ATURI, isOpen bool, page pagination.Page) ([]Issue, error) { 110 98 var issues []Issue 111 99 openValue := 0
+18 -16
appview/issues/issues.go
··· 260 260 return 261 261 } 262 262 263 - commentId := mathrand.IntN(1000000) 264 - rkey := tid.TID() 265 - 266 - err := db.NewIssueComment(rp.db, &db.Comment{ 263 + comment := &db.Comment{ 267 264 OwnerDid: user.Did, 268 265 RepoAt: f.RepoAt(), 269 266 Issue: issueIdInt, 270 - CommentId: commentId, 267 + CommentId: mathrand.IntN(1000000), 271 268 Body: body, 272 - Rkey: rkey, 273 - }) 269 + Rkey: tid.TID(), 270 + } 271 + 272 + err := db.NewIssueComment(rp.db, comment) 274 273 if err != nil { 275 274 log.Println("failed to create comment", err) 276 275 rp.pages.Notice(w, "issue-comment", "Failed to create comment.") ··· 278 277 } 279 278 280 279 createdAt := time.Now().Format(time.RFC3339) 281 - commentIdInt64 := int64(commentId) 282 - ownerDid := user.Did 283 - issueAt, err := db.GetIssueAt(rp.db, f.RepoAt(), issueIdInt) 280 + commentIdInt64 := int64(comment.CommentId) 281 + issue, err := db.GetIssue(rp.db, f.RepoAt(), issueIdInt) 284 282 if err != nil { 285 - log.Println("failed to get issue at", err) 283 + log.Println("failed to get issue", err) 286 284 rp.pages.Notice(w, "issue-comment", "Failed to create comment.") 287 285 return 288 286 } 289 287 290 - atUri := f.RepoAt().String() 288 + atUri := comment.RepoAt.String() 291 289 client, err := rp.oauth.AuthorizedClient(r) 292 290 if err != nil { 293 291 log.Println("failed to get authorized client", err) ··· 297 295 _, err = client.RepoPutRecord(r.Context(), &comatproto.RepoPutRecord_Input{ 298 296 Collection: tangled.RepoIssueCommentNSID, 299 297 Repo: user.Did, 300 - Rkey: rkey, 298 + Rkey: comment.Rkey, 301 299 Record: &lexutil.LexiconTypeDecoder{ 302 300 Val: &tangled.RepoIssueComment{ 303 301 Repo: &atUri, 304 - Issue: issueAt, 302 + Issue: issue.AtUri().String(), 305 303 CommentId: &commentIdInt64, 306 - Owner: &ownerDid, 304 + Owner: &comment.OwnerDid, 307 305 Body: body, 308 306 CreatedAt: createdAt, 309 307 }, ··· 315 313 return 316 314 } 317 315 318 - rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d#comment-%d", f.OwnerSlashRepo(), issueIdInt, commentId)) 316 + mentions := markup.FindUserMentions(comment.Body) 317 + 318 + rp.notifier.NewIssueComment(r.Context(), &f.Repo, issue, comment, mentions) 319 + 320 + rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d#comment-%d", f.OwnerSlashRepo(), comment.Issue, comment.CommentId)) 319 321 return 320 322 } 321 323 }
+6
appview/notify/merged_notifier.go
··· 39 39 } 40 40 } 41 41 42 + func (m *mergedNotifier) NewIssueComment(ctx context.Context, repo *db.Repo, issue *db.Issue, comment *db.Comment, mentions []string) { 43 + for _, notifier := range m.notifiers { 44 + notifier.NewIssueComment(ctx, repo, issue, comment, mentions) 45 + } 46 + } 47 + 42 48 func (m *mergedNotifier) NewFollow(ctx context.Context, follow *db.Follow) { 43 49 for _, notifier := range m.notifiers { 44 50 notifier.NewFollow(ctx, follow)
+2
appview/notify/notifier.go
··· 13 13 DeleteStar(ctx context.Context, star *db.Star) 14 14 15 15 NewIssue(ctx context.Context, issue *db.Issue) 16 + NewIssueComment(ctx context.Context, repo *db.Repo, issue *db.Issue, comment *db.Comment, mentions []string) 16 17 17 18 NewFollow(ctx context.Context, follow *db.Follow) 18 19 DeleteFollow(ctx context.Context, follow *db.Follow) ··· 34 35 func (m *BaseNotifier) DeleteStar(ctx context.Context, star *db.Star) {} 35 36 36 37 func (m *BaseNotifier) NewIssue(ctx context.Context, issue *db.Issue) {} 38 + func (m *BaseNotifier) NewIssueComment(ctx context.Context, repo *db.Repo, issue *db.Issue, comment *db.Comment, mentions []string) {} 37 39 38 40 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *db.Follow) {} 39 41 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {}
+14
appview/posthog/notifier.go
··· 70 70 } 71 71 } 72 72 73 + func (n *posthogNotifier) NewIssueComment(ctx context.Context, repo *db.Repo, issue *db.Issue, comment *db.Comment, mentions []string) { 74 + err := n.client.Enqueue(posthog.Capture{ 75 + DistinctId: comment.OwnerDid, 76 + Event: "new_issue", 77 + Properties: posthog.Properties{ 78 + "repo_at": comment.RepoAt.String(), 79 + "issue_id": comment.Issue, 80 + }, 81 + }) 82 + if err != nil { 83 + log.Println("failed to enqueue posthog event:", err) 84 + } 85 + } 86 + 73 87 func (n *posthogNotifier) NewPull(ctx context.Context, pull *db.Pull) { 74 88 err := n.client.Enqueue(posthog.Capture{ 75 89 DistinctId: pull.OwnerDid,