appview: add user_mentioned notification preference option #744

merged
opened by boltless.me targeting master from feat/mentions
Changed files
+31 -3
appview
db
models
pages
templates
user
settings
+7
appview/db/db.go
···
return err
})
return &DB{
db,
logger,
···
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,
+6 -2
appview/db/notifications.go
···
pull_created,
pull_commented,
followed,
pull_merged,
issue_closed,
email_notifications
···
&prefs.PullCreated,
&prefs.PullCommented,
&prefs.Followed,
&prefs.PullMerged,
&prefs.IssueClosed,
&prefs.EmailNotifications,
···
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`
result, err := d.DB.ExecContext(ctx, query,
···
prefs.PullCreated,
prefs.PullCommented,
prefs.Followed,
prefs.PullMerged,
prefs.IssueClosed,
prefs.EmailNotifications,
···
pull_created,
pull_commented,
followed,
+
user_mentioned,
pull_merged,
issue_closed,
email_notifications
···
&prefs.PullCreated,
&prefs.PullCommented,
&prefs.Followed,
+
&prefs.UserMentioned,
&prefs.PullMerged,
&prefs.IssueClosed,
&prefs.EmailNotifications,
···
query := `
INSERT OR REPLACE INTO notification_preferences
(user_did, repo_starred, issue_created, issue_commented, pull_created,
+
pull_commented, followed, user_mentioned, pull_merged, issue_closed,
+
email_notifications)
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`
result, err := d.DB.ExecContext(ctx, query,
···
prefs.PullCreated,
prefs.PullCommented,
prefs.Followed,
+
prefs.UserMentioned,
prefs.PullMerged,
prefs.IssueClosed,
prefs.EmailNotifications,
+3 -1
appview/models/notifications.go
···
PullCreated bool
PullCommented bool
Followed bool
PullMerged bool
IssueClosed bool
EmailNotifications bool
···
case NotificationTypeFollowed:
return prefs.Followed
case NotificationTypeUserMentioned:
-
return true // always notify on mention
default:
return false
}
···
PullCreated: true,
PullCommented: true,
Followed: true,
PullMerged: true,
IssueClosed: true,
EmailNotifications: false,
···
PullCreated bool
PullCommented bool
Followed bool
+
UserMentioned bool
PullMerged bool
IssueClosed bool
EmailNotifications bool
···
case NotificationTypeFollowed:
return prefs.Followed
case NotificationTypeUserMentioned:
+
return prefs.UserMentioned
default:
return false
}
···
PullCreated: true,
PullCommented: true,
Followed: true,
+
UserMentioned: true,
PullMerged: true,
IssueClosed: true,
EmailNotifications: false,
+14
appview/pages/templates/user/settings/notifications.html
···
</label>
</div>
<div class="flex items-center justify-between p-2">
<div class="flex items-center gap-2">
<div class="flex flex-col gap-1">
···
</label>
</div>
+
<div class="flex items-center justify-between p-2">
+
<div class="flex items-center gap-2">
+
<div class="flex flex-col gap-1">
+
<span class="font-bold">Mentions</span>
+
<div class="flex text-sm items-center gap-1 text-gray-500 dark:text-gray-400">
+
<span>When someone mentions you.</span>
+
</div>
+
</div>
+
</div>
+
<label class="flex items-center gap-2">
+
<input type="checkbox" name="mentioned" {{if .Preferences.UserMentioned}}checked{{end}}>
+
</label>
+
</div>
+
<div class="flex items-center justify-between p-2">
<div class="flex items-center gap-2">
<div class="flex flex-col gap-1">
+1
appview/settings/settings.go
···
PullCommented: r.FormValue("pull_commented") == "on",
PullMerged: r.FormValue("pull_merged") == "on",
Followed: r.FormValue("followed") == "on",
EmailNotifications: r.FormValue("email_notifications") == "on",
}
···
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",
}