fc7dbb0ac0
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat tool notify, auto-switch and schedule notices), the chat push outbox (its table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*. The app_notifications stream, subscribe/clear and kinds are unchanged. Notification settings keep run_finished/chat_needs_you/chat_reply_finished; ntfy_enabled is accepted and ignored and its stored row is never read. Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to the Pipelines apps — use the stage notify hook". The notify hook remains. Installer: no ntfy build, accounts, config or supervisor child; manifest gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log, with a note in logs/install.log); uninstall cleans leftovers. App: ntfy settings section replaced by "Notification events"; texts updated. Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli, author skill references updated; security review M1 marked resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
136 lines
4.0 KiB
Dart
136 lines
4.0 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
import '../../core/api_gateway.dart';
|
|
|
|
/// One server-side notification choice, in the server's wire key.
|
|
class NotificationSetting {
|
|
const NotificationSetting(this.key, this.label, {this.subtitle});
|
|
|
|
final String key;
|
|
final String label;
|
|
|
|
/// Optional one-line explanation shown under [label].
|
|
final String? subtitle;
|
|
}
|
|
|
|
/// The server's global notification choices, in display order. They are
|
|
/// stored on the server, so they apply to every signed-in device.
|
|
///
|
|
/// `run_finished` (server default off) makes every run end notify; without it
|
|
/// only runs started with "Notify me" announce their success or failure.
|
|
const notificationSettings = <NotificationSetting>[
|
|
NotificationSetting(
|
|
'run_finished',
|
|
'Notify when any run ends',
|
|
subtitle: 'Otherwise only runs started with Notify me',
|
|
),
|
|
NotificationSetting('chat_needs_you', 'Chat needs your answer or approval'),
|
|
NotificationSetting('chat_reply_finished', 'Chat reply finished'),
|
|
];
|
|
|
|
/// Loads and changes the server's notification settings through the shared
|
|
/// gateway (`notification_settings` / `set_notification_settings`).
|
|
///
|
|
/// A toggle shows the new value at once and is reverted, with the server's
|
|
/// refusal as [error], when the write fails. Every reply carries all keys, so
|
|
/// the stored result always replaces the local copy. Keys the app does not
|
|
/// show (such as a retired one an older server still sends) are ignored.
|
|
class NotificationSettingsController extends ChangeNotifier {
|
|
NotificationSettingsController(this.gateway);
|
|
|
|
final ApiGateway gateway;
|
|
|
|
Map<String, bool>? _values;
|
|
bool _loading = false;
|
|
String? _saving;
|
|
String _error = '';
|
|
bool _loadFailed = false;
|
|
bool _disposed = false;
|
|
|
|
/// The stored values, or null before the first successful load.
|
|
Map<String, bool>? get values => _values;
|
|
bool get loading => _loading;
|
|
|
|
/// The key whose change is being written, if any.
|
|
String? get saving => _saving;
|
|
String get error => _error;
|
|
|
|
/// Whether the latest load failed; the stored values, if any, are kept.
|
|
bool get loadFailed => _loadFailed;
|
|
|
|
/// Whether the checkboxes accept a change now.
|
|
bool get enabled => _values != null && !_loading && _saving == null;
|
|
|
|
Future<void> load() async {
|
|
if (_loading) return;
|
|
_loading = true;
|
|
_error = '';
|
|
_loadFailed = false;
|
|
_notify();
|
|
try {
|
|
final reply = await gateway.call('notification_settings');
|
|
_values = _decode(reply);
|
|
} catch (error) {
|
|
_loadFailed = true;
|
|
_error = 'Could not load notification settings: $error';
|
|
} finally {
|
|
_loading = false;
|
|
_notify();
|
|
}
|
|
}
|
|
|
|
Future<void> toggle(String key, bool value) async {
|
|
final current = _values;
|
|
if (current == null || !enabled) return;
|
|
final previous = current[key];
|
|
_values = {...current, key: value};
|
|
_saving = key;
|
|
_error = '';
|
|
_notify();
|
|
try {
|
|
final reply = await gateway.call('set_notification_settings', {
|
|
'notification_settings': {key: value},
|
|
});
|
|
_values = _decode(reply);
|
|
} catch (error) {
|
|
final reverted = {...?_values};
|
|
if (previous == null) {
|
|
reverted.remove(key);
|
|
} else {
|
|
reverted[key] = previous;
|
|
}
|
|
_values = reverted;
|
|
_error = 'Could not save: $error';
|
|
} finally {
|
|
_saving = null;
|
|
_notify();
|
|
}
|
|
}
|
|
|
|
static Map<String, bool> _decode(JsonMap reply) {
|
|
final raw = reply['notification_settings'];
|
|
if (raw is! Map) {
|
|
throw const FormatException('the reply carried no notification settings');
|
|
}
|
|
final result = <String, bool>{};
|
|
for (final setting in notificationSettings) {
|
|
final value = raw[setting.key];
|
|
if (value is! bool) {
|
|
throw FormatException('the reply is missing ${setting.key}');
|
|
}
|
|
result[setting.key] = value;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void _notify() {
|
|
if (!_disposed) notifyListeners();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_disposed = true;
|
|
super.dispose();
|
|
}
|
|
}
|