Add server notification settings with app checkboxes
Persist three global ntfy switches in server_settings: run_finished (default on: auto-mode runs notify on success, read inside the transition transaction; on/off modes unchanged), chat_needs_you (default on: gates chat question/approval alerts) and chat_reply_finished (default off: one alert per finished assistant turn). Expose notification_settings / set_notification_settings over the websocket protocol, add a Phone notifications section with Material and Cupertino checkboxes in Settings, document the settings, and keep the cli, tui, stage and pipeline test packages from inheriting a real ntfy configuration.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// notificationSettingsStore persists the operator's global notification
|
||||
// choices. *pipeline.Store implements it.
|
||||
type notificationSettingsStore interface {
|
||||
NotificationSettings(context.Context) (protocol.NotificationSettings, error)
|
||||
UpdateNotificationSettings(context.Context, map[string]any) (protocol.NotificationSettings, error)
|
||||
}
|
||||
|
||||
// handleNotificationSettings answers notification_settings and
|
||||
// set_notification_settings. It reports whether request was one of them.
|
||||
func handleNotificationSettings(ctx context.Context, request protocol.Message, store notificationSettingsStore, write func(protocol.Message) error) bool {
|
||||
if request.Type != protocol.GetNotificationSettings && request.Type != protocol.SetNotificationSettings {
|
||||
return false
|
||||
}
|
||||
response := protocol.Message{Type: protocol.NotificationSettingsReply, ID: request.ID}
|
||||
var settings protocol.NotificationSettings
|
||||
var err error
|
||||
switch {
|
||||
case store == nil:
|
||||
response.Type = protocol.Error
|
||||
response.Error = "notification settings are unavailable: no store"
|
||||
case request.Type == protocol.GetNotificationSettings:
|
||||
settings, err = store.NotificationSettings(ctx)
|
||||
default:
|
||||
settings, err = store.UpdateNotificationSettings(ctx, request.NotificationSettings)
|
||||
}
|
||||
if err != nil {
|
||||
response.Type = protocol.Error
|
||||
response.Error = err.Error()
|
||||
} else if response.Type != protocol.Error {
|
||||
response.NotificationSettings = settings.Map()
|
||||
}
|
||||
_ = write(response)
|
||||
return true
|
||||
}
|
||||
|
||||
// chatNotificationSettings reads the chat-related choices for a pending
|
||||
// publication. Without a store the defaults apply; a read failure is logged and
|
||||
// also falls back to the defaults so a transient database error neither
|
||||
// silences the operator nor fails chat handling.
|
||||
func chatNotificationSettings(ctx context.Context, store notificationSettingsStore) protocol.NotificationSettings {
|
||||
if store == nil {
|
||||
return protocol.DefaultNotificationSettings()
|
||||
}
|
||||
settings, err := store.NotificationSettings(ctx)
|
||||
if err != nil {
|
||||
log.Printf("read notification settings: %v", err)
|
||||
return protocol.DefaultNotificationSettings()
|
||||
}
|
||||
return settings
|
||||
}
|
||||
Reference in New Issue
Block a user