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