From ccc00a4329fe70a097597bef2d6ffefcd69e1af1 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Mon, 3 Nov 2025 18:54:57 +0900 Subject: [PATCH] appview: add `user_mentioned` notification preference option Change-Id: ospwplwymstvmtrtvtklqoxtkpowvsyx Signed-off-by: Seongmin Lee --- appview/db/db.go | 7 +++++++ appview/db/notifications.go | 8 ++++++-- appview/models/notifications.go | 4 +++- .../templates/user/settings/notifications.html | 14 ++++++++++++++ appview/settings/settings.go | 1 + 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/appview/db/db.go b/appview/db/db.go index f61490c7..260cb8ec 100644 --- a/appview/db/db.go +++ b/appview/db/db.go @@ -1113,6 +1113,13 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { return err }) + runMigration(conn, logger, "add-usermentioned-preference", func(tx *sql.Tx) error { + _, err := tx.Exec(` + alter table notification_preferences add column user_mentioned integer not null default 1; + `) + return err + }) + return &DB{ db, logger, diff --git a/appview/db/notifications.go b/appview/db/notifications.go index 10f18ce1..8f7c59fb 100644 --- a/appview/db/notifications.go +++ b/appview/db/notifications.go @@ -394,6 +394,7 @@ func GetNotificationPreferences(e Execer, filters ...filter) (map[syntax.DID]*mo pull_created, pull_commented, followed, + user_mentioned, pull_merged, issue_closed, email_notifications @@ -419,6 +420,7 @@ func GetNotificationPreferences(e Execer, filters ...filter) (map[syntax.DID]*mo &prefs.PullCreated, &prefs.PullCommented, &prefs.Followed, + &prefs.UserMentioned, &prefs.PullMerged, &prefs.IssueClosed, &prefs.EmailNotifications, @@ -440,8 +442,9 @@ func (d *DB) UpdateNotificationPreferences(ctx context.Context, prefs *models.No query := ` INSERT OR REPLACE INTO notification_preferences (user_did, repo_starred, issue_created, issue_commented, pull_created, - pull_commented, followed, pull_merged, issue_closed, email_notifications) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + pull_commented, followed, user_mentioned, pull_merged, issue_closed, + email_notifications) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` result, err := d.DB.ExecContext(ctx, query, @@ -452,6 +455,7 @@ func (d *DB) UpdateNotificationPreferences(ctx context.Context, prefs *models.No prefs.PullCreated, prefs.PullCommented, prefs.Followed, + prefs.UserMentioned, prefs.PullMerged, prefs.IssueClosed, prefs.EmailNotifications, diff --git a/appview/models/notifications.go b/appview/models/notifications.go index c1896074..e35281b2 100644 --- a/appview/models/notifications.go +++ b/appview/models/notifications.go @@ -87,6 +87,7 @@ type NotificationPreferences struct { PullCreated bool PullCommented bool Followed bool + UserMentioned bool PullMerged bool IssueClosed bool EmailNotifications bool @@ -117,7 +118,7 @@ func (prefs *NotificationPreferences) ShouldNotify(t NotificationType) bool { case NotificationTypeFollowed: return prefs.Followed case NotificationTypeUserMentioned: - return true // always notify on mention + return prefs.UserMentioned default: return false } @@ -132,6 +133,7 @@ func DefaultNotificationPreferences(user syntax.DID) *NotificationPreferences { PullCreated: true, PullCommented: true, Followed: true, + UserMentioned: true, PullMerged: true, IssueClosed: true, EmailNotifications: false, diff --git a/appview/pages/templates/user/settings/notifications.html b/appview/pages/templates/user/settings/notifications.html index 656ec642..768c402e 100644 --- a/appview/pages/templates/user/settings/notifications.html +++ b/appview/pages/templates/user/settings/notifications.html @@ -141,6 +141,20 @@ +
+
+
+ Mentions +
+ When someone mentions you. +
+
+
+ +
+
diff --git a/appview/settings/settings.go b/appview/settings/settings.go index 1f1d9187..14c700b5 100644 --- a/appview/settings/settings.go +++ b/appview/settings/settings.go @@ -120,6 +120,7 @@ func (s *Settings) updateNotificationPreferences(w http.ResponseWriter, r *http. PullCommented: r.FormValue("pull_commented") == "on", PullMerged: r.FormValue("pull_merged") == "on", Followed: r.FormValue("followed") == "on", + UserMentioned: r.FormValue("user_mentioned") == "on", EmailNotifications: r.FormValue("email_notifications") == "on", } -- 2.43.0