Files
multica/server/pkg/db/generated/notification_preferences.sql.go
Jiayuan 45e1dfd325 feat(inbox): add notification preferences settings
Add per-type notification preference controls to the Inbox, allowing
users to toggle which notification types they receive. This addresses
the core pain point of agent-generated status change noise flooding
user inboxes.

Backend:
- New `notification_preference` table (migration 064) with per-user,
  per-workspace, per-type enabled/disabled toggle
- GET/PUT /api/inbox/preferences endpoints for CRUD
- notification_listeners.go checks user preferences before creating
  inbox items, using preloaded per-type batch queries for efficiency
- status_changed notifications default to OFF; all others default ON

Frontend:
- NotificationPreference type and API client methods
- TanStack Query options + optimistic mutation hook
- Settings dialog accessible via gear icon in Inbox header
- Grouped by category: Status, Comments, Assignments, Mentions,
  Priority, Due dates, Reactions, Agent events, Quick create
- Each category shows icon, label, description, and Switch toggle
2026-04-29 21:10:00 +02:00

167 lines
4.8 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: notification_preferences.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const deleteNotificationPreferences = `-- name: DeleteNotificationPreferences :exec
DELETE FROM notification_preference
WHERE workspace_id = $1 AND user_id = $2
`
type DeleteNotificationPreferencesParams struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
UserID pgtype.UUID `json:"user_id"`
}
func (q *Queries) DeleteNotificationPreferences(ctx context.Context, arg DeleteNotificationPreferencesParams) error {
_, err := q.db.Exec(ctx, deleteNotificationPreferences, arg.WorkspaceID, arg.UserID)
return err
}
const getDisabledNotificationTypes = `-- name: GetDisabledNotificationTypes :many
SELECT notification_type FROM notification_preference
WHERE workspace_id = $1 AND user_id = $2 AND enabled = false
`
type GetDisabledNotificationTypesParams struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
UserID pgtype.UUID `json:"user_id"`
}
func (q *Queries) GetDisabledNotificationTypes(ctx context.Context, arg GetDisabledNotificationTypesParams) ([]string, error) {
rows, err := q.db.Query(ctx, getDisabledNotificationTypes, arg.WorkspaceID, arg.UserID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []string{}
for rows.Next() {
var notification_type string
if err := rows.Scan(&notification_type); err != nil {
return nil, err
}
items = append(items, notification_type)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listNotificationPreferences = `-- name: ListNotificationPreferences :many
SELECT id, workspace_id, user_id, notification_type, enabled, created_at, updated_at FROM notification_preference
WHERE workspace_id = $1 AND user_id = $2
ORDER BY notification_type
`
type ListNotificationPreferencesParams struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
UserID pgtype.UUID `json:"user_id"`
}
func (q *Queries) ListNotificationPreferences(ctx context.Context, arg ListNotificationPreferencesParams) ([]NotificationPreference, error) {
rows, err := q.db.Query(ctx, listNotificationPreferences, arg.WorkspaceID, arg.UserID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []NotificationPreference{}
for rows.Next() {
var i NotificationPreference
if err := rows.Scan(
&i.ID,
&i.WorkspaceID,
&i.UserID,
&i.NotificationType,
&i.Enabled,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listNotificationPreferencesByType = `-- name: ListNotificationPreferencesByType :many
SELECT user_id, enabled FROM notification_preference
WHERE workspace_id = $1 AND notification_type = $2
`
type ListNotificationPreferencesByTypeParams struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
NotificationType string `json:"notification_type"`
}
type ListNotificationPreferencesByTypeRow struct {
UserID pgtype.UUID `json:"user_id"`
Enabled bool `json:"enabled"`
}
func (q *Queries) ListNotificationPreferencesByType(ctx context.Context, arg ListNotificationPreferencesByTypeParams) ([]ListNotificationPreferencesByTypeRow, error) {
rows, err := q.db.Query(ctx, listNotificationPreferencesByType, arg.WorkspaceID, arg.NotificationType)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListNotificationPreferencesByTypeRow{}
for rows.Next() {
var i ListNotificationPreferencesByTypeRow
if err := rows.Scan(&i.UserID, &i.Enabled); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const upsertNotificationPreference = `-- name: UpsertNotificationPreference :one
INSERT INTO notification_preference (workspace_id, user_id, notification_type, enabled)
VALUES ($1, $2, $3, $4)
ON CONFLICT (workspace_id, user_id, notification_type)
DO UPDATE SET enabled = $4, updated_at = now()
RETURNING id, workspace_id, user_id, notification_type, enabled, created_at, updated_at
`
type UpsertNotificationPreferenceParams struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
UserID pgtype.UUID `json:"user_id"`
NotificationType string `json:"notification_type"`
Enabled bool `json:"enabled"`
}
func (q *Queries) UpsertNotificationPreference(ctx context.Context, arg UpsertNotificationPreferenceParams) (NotificationPreference, error) {
row := q.db.QueryRow(ctx, upsertNotificationPreference,
arg.WorkspaceID,
arg.UserID,
arg.NotificationType,
arg.Enabled,
)
var i NotificationPreference
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.UserID,
&i.NotificationType,
&i.Enabled,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}