This commit is contained in:
ponzischeme89
2026-08-19 06:57:59 +12:00
parent 8c847c59b8
commit 2b43b9ef12
94 changed files with 6359 additions and 778 deletions
+26 -3
View File
@@ -281,16 +281,26 @@ func (s *Store) AllNotificationPreferences(ctx context.Context) (map[string]Noti
return result, rows.Err()
}
// UpsertNotification writes one notification into a viewer's own list.
//
// It reports whether a row was actually inserted, which is what separates the two answers
// the source key produces: a genuine delivery, and a repeat of one already sitting in
// somebody's list. Both are ordinary — the digest job runs hourly and re-sends the same
// weekly key all evening on purpose — but the notification log has to be able to tell them
// apart, or every catch-up run would read as a second summary nobody received.
func (s *Store) UpsertNotification(
ctx context.Context, userID, sourceKey, kind, itemID, title, message string, eventAt *time.Time,
) error {
_, err := s.pool.Exec(ctx, `
) (bool, error) {
tag, err := s.pool.Exec(ctx, `
INSERT INTO user_notifications
(emby_user_id, source_key, kind, item_id, title, message, event_at)
VALUES ($1, $2, $3, $4, $5, $6, $7)
ON CONFLICT (emby_user_id, source_key) DO NOTHING`,
userID, sourceKey, kind, itemID, title, message, eventAt)
return err
if err != nil {
return false, err
}
return tag.RowsAffected() > 0, nil
}
func (s *Store) UserNotifications(ctx context.Context, userID string) ([]UserNotification, error) {
@@ -325,6 +335,19 @@ func (s *Store) MarkNotificationRead(ctx context.Context, userID string, id int6
return err
}
// MarkNotificationUnread puts a notification back to new.
//
// The counterpart to MarkNotificationRead, and deliberately a plain assignment rather than
// that one's COALESCE: read is sticky because it is set by merely looking at a row, so a
// second glance must not move the timestamp, while unread is only ever the viewer saying so
// and means exactly one thing.
func (s *Store) MarkNotificationUnread(ctx context.Context, userID string, id int64) error {
_, err := s.pool.Exec(ctx, `
UPDATE user_notifications SET read_at = NULL
WHERE id = $1 AND emby_user_id = $2`, id, userID)
return err
}
func (s *Store) DismissNotification(ctx context.Context, userID string, id int64) error {
_, err := s.pool.Exec(ctx, `
UPDATE user_notifications SET dismissed_at = now()