From 45a22725bf9deddd7e466a670c5d5b951e53da8b Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 28 May 2026 12:44:01 +0100 Subject: [PATCH] appview/db: mark notifications as read upon page visit when visiting an issue or a pull, automatically mark any notifications related to that issue/pull as read. Signed-off-by: oppiliappan --- appview/db/notifications.go | 22 ++++++++++++++++++++++ appview/issues/issues.go | 11 +++++++++++ appview/pulls/single.go | 11 +++++++++++ 3 files changed, 44 insertions(+) diff --git a/appview/db/notifications.go b/appview/db/notifications.go index 83059249..b7c4bf2a 100644 --- a/appview/db/notifications.go +++ b/appview/db/notifications.go @@ -331,6 +331,28 @@ func MarkNotificationRead(e Execer, notificationID int64, userDID string) error return nil } +func MarkNotificationsReadForIssue(e Execer, userDID, repoDid string, issueNum int) error { + query := ` + update notifications set read = 1 + where recipient_did = ? + and read = 0 + and issue_id = (select id from issues where repo_did = ? and issue_id = ?) + ` + _, err := e.Exec(query, userDID, repoDid, issueNum) + return err +} + +func MarkNotificationsReadForPull(e Execer, userDID, repoDid string, pullNum int) error { + query := ` + update notifications set read = 1 + where recipient_did = ? + and read = 0 + and pull_id = (select p.id from pulls p where p.pull_id = ? and p.repo_did = ?) + ` + _, err := e.Exec(query, userDID, pullNum, repoDid) + return err +} + func MarkNotificationUnread(e Execer, notificationID int64, userDID string) error { idFilter := orm.FilterEq("id", notificationID) recipientFilter := orm.FilterEq("recipient_did", userDID) diff --git a/appview/issues/issues.go b/appview/issues/issues.go index 2b114f5a..c67e6ba1 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -99,6 +99,17 @@ func (rp *Issues) RepoSingleIssue(w http.ResponseWriter, r *http.Request) { return } + if user != nil { + repoDid := f.RepoDid + userDid := user.Did + issueId := issue.IssueId + go func() { + if err := db.MarkNotificationsReadForIssue(rp.db, userDid, repoDid, issueId); err != nil { + l.Error("failed to mark issue notifications as read", "err", err) + } + }() + } + entities := []syntax.ATURI{issue.AtUri()} for _, c := range issue.Comments { entities = append(entities, c.FeedCommentAtUri()) diff --git a/appview/pulls/single.go b/appview/pulls/single.go index f97eecf9..629a59fc 100644 --- a/appview/pulls/single.go +++ b/appview/pulls/single.go @@ -102,6 +102,17 @@ func (s *Pulls) repoPullHelper(w http.ResponseWriter, r *http.Request, interdiff } l = l.With("pull_id", pull.PullId, "pull_owner", pull.OwnerDid) + if user != nil { + repoDid := f.RepoDid + userDid := user.Did + pullId := pull.PullId + go func() { + if err := db.MarkNotificationsReadForPull(s.db, userDid, repoDid, pullId); err != nil { + l.Error("failed to mark pull notifications as read", "err", err) + } + }() + } + backlinks, err := db.GetBacklinks(s.db, pull.AtUri()) if err != nil { l.Error("failed to get pull backlinks", "err", err) -- 2.51.2