Merge branch 'worktree-agent-abec427641b9e4fa8'
This commit is contained in:
@@ -63,7 +63,7 @@
|
||||
<data android:scheme="pipelines" android:host="chat" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Instant delivery of server notifications without the ntfy app.
|
||||
<!-- Instant delivery of server notifications while the app is closed.
|
||||
specialUse: a persistent push connection to a self-hosted server
|
||||
has no dedicated type, and dataSync is time-limited on Android 15. -->
|
||||
<service
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ data class ServerNotification(
|
||||
val title: String,
|
||||
val message: String,
|
||||
val click: String,
|
||||
/** ntfy-style priority, clamped to 1..5 (3 is the default). */
|
||||
/** Priority, clamped to 1..5 (3 is the default). */
|
||||
val priority: Int,
|
||||
val tags: List<String>,
|
||||
val createdAt: String,
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Keeps one authenticated websocket to the configured Pipelines server while
|
||||
* the app is in the background, like ntfy's instant delivery: no Flutter
|
||||
* the app is in the background, for instant delivery: no Flutter
|
||||
* engine runs here. It subscribes with the replay cursor, posts each pushed
|
||||
* notification, mirrors cross-device clears and sends the user's own clears.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// An agent's own notification: the `chat_notify` app notification the server
|
||||
/// records when a chat's model calls the `notify` tool, as the notification
|
||||
/// stream carries it (see docs/ntfy.md).
|
||||
/// stream carries it (see docs/notifications.md).
|
||||
library;
|
||||
|
||||
/// The stream kind of an agent's notify call.
|
||||
@@ -30,7 +30,7 @@ class AgentNotice {
|
||||
final String title;
|
||||
final String message;
|
||||
|
||||
/// The ntfy-style priority: 2 low, 3 default, 4 high.
|
||||
/// The priority, 1-5: 2 low, 3 default, 4 high.
|
||||
final int priority;
|
||||
final DateTime? createdAt;
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ import '../../../../../core/api_gateway.dart';
|
||||
import 'chat_shown_surface.dart';
|
||||
|
||||
/// What a `notify` entry says: where the notification went (the server's
|
||||
/// `channels`: the operator's signed-in Pipelines `apps` and/or their `phone`),
|
||||
/// or why it was not sent.
|
||||
/// `channels`: the operator's signed-in Pipelines `apps`; `phone` appears only
|
||||
/// in entries recorded before the server stopped publishing to a phone push
|
||||
/// service), or why it was not sent.
|
||||
String chatShownNotifyText(JsonMap item) {
|
||||
final title = chatShownTitle(item, 'notification');
|
||||
if (item['delivered'] == true) return '${_notifiedWhere(item)}: $title';
|
||||
|
||||
@@ -12,8 +12,8 @@ export 'notification_service_status.dart';
|
||||
|
||||
/// The app's handle on Android background delivery: a native foreground
|
||||
/// service (android/…/notify/NotificationService.kt) that keeps its own
|
||||
/// socket to the server and shows the server's notifications, so the ntfy app
|
||||
/// is not needed. Other platforms have no service ([supported] is false).
|
||||
/// socket to the server and shows the server's notifications while the app
|
||||
/// is closed. Other platforms have no service ([supported] is false).
|
||||
abstract interface class NotificationServiceBridge {
|
||||
bool get supported;
|
||||
|
||||
|
||||
+16
-24
@@ -2,9 +2,9 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
|
||||
/// One server-side ntfy notification choice, in the server's wire key.
|
||||
class NtfySetting {
|
||||
const NtfySetting(this.key, this.label, {this.subtitle});
|
||||
/// 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;
|
||||
@@ -13,36 +13,30 @@ class NtfySetting {
|
||||
final String? subtitle;
|
||||
}
|
||||
|
||||
/// The server's global notification choices, in display order.
|
||||
/// 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 ntfySettings = <NtfySetting>[
|
||||
NtfySetting(
|
||||
const notificationSettings = <NotificationSetting>[
|
||||
NotificationSetting(
|
||||
'run_finished',
|
||||
'Notify when any run ends',
|
||||
subtitle: 'Otherwise only runs started with Notify me',
|
||||
),
|
||||
NtfySetting('chat_needs_you', 'Chat needs your answer or approval'),
|
||||
NtfySetting('chat_reply_finished', 'Chat reply finished'),
|
||||
NotificationSetting('chat_needs_you', 'Chat needs your answer or approval'),
|
||||
NotificationSetting('chat_reply_finished', 'Chat reply finished'),
|
||||
];
|
||||
|
||||
/// The server's switch for also publishing to ntfy. Optional: older servers
|
||||
/// do not send it, and Settings hides the switch then.
|
||||
const ntfyEnabledSetting = NtfySetting(
|
||||
'ntfy_enabled',
|
||||
'Also send to ntfy',
|
||||
subtitle: 'For devices that still use the ntfy app',
|
||||
);
|
||||
|
||||
/// Loads and changes the server's ntfy notification settings through the
|
||||
/// shared gateway (`notification_settings` / `set_notification_settings`).
|
||||
/// 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.
|
||||
class NtfySettingsController extends ChangeNotifier {
|
||||
NtfySettingsController(this.gateway);
|
||||
/// 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;
|
||||
|
||||
@@ -119,15 +113,13 @@ class NtfySettingsController extends ChangeNotifier {
|
||||
throw const FormatException('the reply carried no notification settings');
|
||||
}
|
||||
final result = <String, bool>{};
|
||||
for (final setting in ntfySettings) {
|
||||
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;
|
||||
}
|
||||
final ntfy = raw[ntfyEnabledSetting.key];
|
||||
if (ntfy is bool) result[ntfyEnabledSetting.key] = ntfy;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ const deviceDeliveryTitle = 'Notifications in Pipelines';
|
||||
const deviceDeliverySwitchLabel = 'Receive notifications in Pipelines';
|
||||
const deviceDeliveryNote =
|
||||
'Pipelines keeps its own connection to the server and shows its '
|
||||
'notifications, so the ntfy app is no longer needed. Android shows a '
|
||||
'quiet "Pipelines is connected" notification while it runs.';
|
||||
'notifications even while the app is closed. Android shows a quiet '
|
||||
'"Pipelines is connected" notification while it runs.';
|
||||
const deviceDeliveryBatteryLabel = 'Allow background delivery';
|
||||
const deviceDeliveryNotificationsLabel = 'Allow notifications';
|
||||
const deviceDeliveryWarningTitle = 'Delivery can pause while idle';
|
||||
|
||||
+34
-35
@@ -3,35 +3,33 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
import 'ntfy_settings_controller.dart';
|
||||
import 'notification_settings_controller.dart';
|
||||
import 'settings_group.dart';
|
||||
import 'settings_theme.dart';
|
||||
|
||||
/// The section title for the server's ntfy notification choices.
|
||||
const ntfySectionTitle = 'Phone notifications';
|
||||
/// The section title for the server's notification choices.
|
||||
const notificationEventsTitle = 'Notification events';
|
||||
|
||||
/// One line explaining where these notifications go.
|
||||
const ntfySectionSubtitle =
|
||||
'Sent through ntfy to the devices subscribed to this server.';
|
||||
|
||||
/// The subtitle once the server delivers to the app itself (it reports
|
||||
/// `ntfy_enabled`).
|
||||
const ntfySectionAppSubtitle =
|
||||
'What the server notifies about: shown by the Pipelines app and, when '
|
||||
'enabled, also sent through ntfy.';
|
||||
/// One line explaining that these choices are shared.
|
||||
const notificationEventsSubtitle =
|
||||
'What the server notifies about. Stored on the server, so these apply to '
|
||||
'every device signed in to it.';
|
||||
|
||||
/// Shown instead of loading while the shared connection is down.
|
||||
const ntfyOfflineText = 'Connect to a server to change these.';
|
||||
const notificationEventsOfflineText = 'Connect to a server to change these.';
|
||||
|
||||
ValueKey<String> ntfySettingKey(String key) => ValueKey<String>('ntfy-$key');
|
||||
const ntfyErrorKey = ValueKey<String>('ntfy-settings-error');
|
||||
ValueKey<String> notificationSettingKey(String key) =>
|
||||
ValueKey<String>('notification-setting-$key');
|
||||
const notificationSettingsErrorKey = ValueKey<String>(
|
||||
'notification-settings-error',
|
||||
);
|
||||
|
||||
/// The server-side notification checkboxes in Settings: run finished, chat
|
||||
/// needs you and chat reply finished. Values load from the server whenever
|
||||
/// [connected] becomes true and every toggle is written at once; a refusal is
|
||||
/// shown inline and the checkbox reverts.
|
||||
class SettingsNtfySection extends StatefulWidget {
|
||||
const SettingsNtfySection({
|
||||
class SettingsNotificationSettingsSection extends StatefulWidget {
|
||||
const SettingsNotificationSettingsSection({
|
||||
super.key,
|
||||
required this.gateway,
|
||||
required this.connected,
|
||||
@@ -41,13 +39,14 @@ class SettingsNtfySection extends StatefulWidget {
|
||||
final bool connected;
|
||||
|
||||
@override
|
||||
State<SettingsNtfySection> createState() => _SettingsNtfySectionState();
|
||||
State<SettingsNotificationSettingsSection> createState() =>
|
||||
_SettingsNotificationSettingsSectionState();
|
||||
}
|
||||
|
||||
class _SettingsNtfySectionState extends State<SettingsNtfySection> {
|
||||
late NtfySettingsController _controller = NtfySettingsController(
|
||||
widget.gateway,
|
||||
);
|
||||
class _SettingsNotificationSettingsSectionState
|
||||
extends State<SettingsNotificationSettingsSection> {
|
||||
late NotificationSettingsController _controller =
|
||||
NotificationSettingsController(widget.gateway);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -56,11 +55,11 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SettingsNtfySection oldWidget) {
|
||||
void didUpdateWidget(SettingsNotificationSettingsSection oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.gateway != widget.gateway) {
|
||||
_controller.dispose();
|
||||
_controller = NtfySettingsController(widget.gateway);
|
||||
_controller = NotificationSettingsController(widget.gateway);
|
||||
}
|
||||
if (widget.connected &&
|
||||
(!oldWidget.connected || oldWidget.gateway != widget.gateway)) {
|
||||
@@ -84,16 +83,12 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
|
||||
final values = _controller.values;
|
||||
final enabled = widget.connected && _controller.enabled;
|
||||
final status = !widget.connected
|
||||
? ntfyOfflineText
|
||||
? notificationEventsOfflineText
|
||||
: _controller.loading && values == null
|
||||
? 'Loading…'
|
||||
: '';
|
||||
final hasNtfySwitch = values?.containsKey(ntfyEnabledSetting.key) ?? false;
|
||||
final tiles = <Widget>[
|
||||
for (final setting in [
|
||||
...ntfySettings,
|
||||
if (hasNtfySwitch) ntfyEnabledSetting,
|
||||
])
|
||||
for (final setting in notificationSettings)
|
||||
_tile(
|
||||
setting,
|
||||
values?[setting.key] ?? false,
|
||||
@@ -106,18 +101,18 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
|
||||
!_controller.loading &&
|
||||
(values == null || _controller.loadFailed);
|
||||
return SettingsGroup(
|
||||
title: ntfySectionTitle,
|
||||
title: notificationEventsTitle,
|
||||
footer: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Text(hasNtfySwitch ? ntfySectionAppSubtitle : ntfySectionSubtitle),
|
||||
const Text(notificationEventsSubtitle),
|
||||
if (status.isNotEmpty) Text(status),
|
||||
if (_controller.error.isNotEmpty)
|
||||
Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
_controller.error,
|
||||
key: ntfyErrorKey,
|
||||
key: notificationSettingsErrorKey,
|
||||
style: TextStyle(color: settingsErrorColor(context)),
|
||||
),
|
||||
),
|
||||
@@ -135,9 +130,13 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tile(NtfySetting setting, bool value, ValueChanged<bool>? onChanged) {
|
||||
Widget _tile(
|
||||
NotificationSetting setting,
|
||||
bool value,
|
||||
ValueChanged<bool>? onChanged,
|
||||
) {
|
||||
return CheckboxListTile(
|
||||
key: ntfySettingKey(setting.key),
|
||||
key: notificationSettingKey(setting.key),
|
||||
title: Text(setting.label),
|
||||
subtitle: setting.subtitle == null ? null : Text(setting.subtitle!),
|
||||
value: value,
|
||||
@@ -151,11 +151,13 @@ extension _SettingsPageSections on _SettingsScreenState {
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'phone-notifications',
|
||||
title: ntfySectionTitle,
|
||||
keywords: 'ntfy push phone run finished chat needs you',
|
||||
id: 'notification-events',
|
||||
title: notificationEventsTitle,
|
||||
keywords:
|
||||
'notifications push phone events all devices run finished '
|
||||
'chat needs you reply finished',
|
||||
lazy: true,
|
||||
builder: (_) => SettingsNtfySection(
|
||||
builder: (_) => SettingsNotificationSettingsSection(
|
||||
gateway: widget.client,
|
||||
connected:
|
||||
widget.client.state.kind == transport.ConnectionKind.connected,
|
||||
|
||||
@@ -12,7 +12,7 @@ const settingsPhoneFirstIds = [
|
||||
'sign-in',
|
||||
'notifications',
|
||||
'device-delivery',
|
||||
'phone-notifications',
|
||||
'notification-events',
|
||||
];
|
||||
|
||||
/// [sections] reordered for a phone: [settingsPhoneFirstIds] first.
|
||||
|
||||
@@ -25,7 +25,7 @@ import 'health/settings_health_section.dart';
|
||||
import 'settings_search_page.dart';
|
||||
import 'settings_section.dart';
|
||||
import 'settings_notifications_section.dart';
|
||||
import 'settings_ntfy_section.dart';
|
||||
import 'settings_notification_settings_section.dart';
|
||||
import 'settings_device_delivery_section.dart';
|
||||
import '../notification_service/notification_service_bridge.dart';
|
||||
import '../notification_service/notification_service_controller.dart';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
- `android/.../notify/NotificationThreads.kt` (new): `ThreadEntry`, `ThreadHistory`
|
||||
(bounded per-thread entries, bounded thread count, persisted through the
|
||||
ledger's `LedgerStore` under `threads.history`), and naming helpers. Threads are
|
||||
keyed by the server `group` (`chat:<id>` or `run:<id>`, per `docs/ntfy.md`).
|
||||
keyed by the server `group` (`chat:<id>` or `run:<id>`, per `docs/notifications.md`).
|
||||
- `NotificationPresenter.kt`: a grouped notification posts one conversation
|
||||
notification per thread with a stable id (`thread:<group>`), the latest 5 lines
|
||||
(sender = chat title, run title for runs), the unread count (`setNumber`), and a
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# ntfy removal (app side)
|
||||
|
||||
Operator decision: ntfy is removed from Pipelines. Every client gets
|
||||
notifications from the server's own app notification stream: browser
|
||||
Notification on web, the "Receive notifications in Pipelines" background
|
||||
service or the in-app bridge on Android, the in-app bridge on iOS/macOS.
|
||||
|
||||
## Change
|
||||
|
||||
- Settings "Phone notifications" (ntfy) section replaced by **Notification
|
||||
events** (`lib/features/settings/settings_notification_settings_section.dart`,
|
||||
controller `notification_settings_controller.dart`; section id
|
||||
`notification-events`, still in the phone-first order). It shows the three
|
||||
server-stored switches `run_finished`, `chat_needs_you`,
|
||||
`chat_reply_finished` with the subtitle "What the server notifies about.
|
||||
Stored on the server, so these apply to every device signed in to it."
|
||||
- The `ntfy_enabled` switch is gone; a reply that still carries it is ignored
|
||||
(only the three known keys are decoded) and writes send only the toggled key.
|
||||
- Search keywords no longer mention ntfy.
|
||||
- "Notifications in Pipelines" note no longer mentions the ntfy app.
|
||||
- Comments in `agent_notice.dart` (docs/notifications.md, priority 1-5),
|
||||
`notification_service_bridge.dart`, `AndroidManifest.xml`,
|
||||
`NotificationService.kt`, `NotificationProtocol.kt` drop ntfy.
|
||||
- `chat_shown_notify_row.dart` still renders a `phone` channel for transcript
|
||||
entries recorded before the change; new entries only carry `apps`.
|
||||
|
||||
## Checks
|
||||
|
||||
- `tool/analyze.sh`: clean.
|
||||
- memwatch `test/features/settings`: 216 passed; `test/features/attention`:
|
||||
159 passed; `test/features/notification_service`: 11 passed.
|
||||
- No browser capture taken for the renamed section.
|
||||
@@ -11,7 +11,7 @@ not only on the web and then I have to clear again on mobile."
|
||||
device has open, records a per-session `chat_seen` watermark in epoch ms.
|
||||
|
||||
ntfy notifications already shown on a phone cannot be retracted (see
|
||||
`docs/ntfy.md`, "Clearing notifications across devices").
|
||||
`docs/notifications.md`, "Clearing notifications across devices").
|
||||
|
||||
## Protocol (server, `internal/protocol/attention_acks.go`)
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ bool _switchValue(WidgetTester tester) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('shows the switch, status and ntfy note', (tester) async {
|
||||
testWidgets('shows the switch, status and delivery note', (tester) async {
|
||||
final service = FakeNotificationService();
|
||||
await tester.pumpWidget(_host(service));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
+76
-84
@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_ntfy_section.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_notification_settings_section.dart';
|
||||
|
||||
/// A scripted gateway: records every request and answers from [respond].
|
||||
class _Gateway implements ApiGateway {
|
||||
@@ -32,24 +32,31 @@ JsonMap _reply(bool run, bool needs, bool reply) => {
|
||||
},
|
||||
};
|
||||
|
||||
Widget _host(ApiGateway gateway) {
|
||||
Widget _host(ApiGateway gateway, {bool connected = true}) {
|
||||
final body = SingleChildScrollView(
|
||||
child: SettingsNtfySection(gateway: gateway, connected: true),
|
||||
child: SettingsNotificationSettingsSection(
|
||||
gateway: gateway,
|
||||
connected: connected,
|
||||
),
|
||||
);
|
||||
return MaterialApp(home: Scaffold(body: body));
|
||||
}
|
||||
|
||||
bool _checked(WidgetTester tester, String key) {
|
||||
final tile = find.byKey(ntfySettingKey(key));
|
||||
return tester.widget<CheckboxListTile>(tile).value!;
|
||||
}
|
||||
Finder _tile(String key) => find.byKey(notificationSettingKey(key));
|
||||
|
||||
bool _checked(WidgetTester tester, String key) =>
|
||||
tester.widget<CheckboxListTile>(_tile(key)).value!;
|
||||
|
||||
void main() {
|
||||
testWidgets('loads the stored values', (tester) async {
|
||||
testWidgets('shows the three shared switches with stored values', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _Gateway((_, _) => _reply(true, false, true));
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls.single.$1, 'notification_settings');
|
||||
expect(find.text(notificationEventsTitle), findsOneWidget);
|
||||
expect(find.text(notificationEventsSubtitle), findsOneWidget);
|
||||
expect(find.text('Notify when any run ends'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Otherwise only runs started with Notify me'),
|
||||
@@ -57,14 +64,13 @@ void main() {
|
||||
);
|
||||
expect(find.text('Chat needs your answer or approval'), findsOneWidget);
|
||||
expect(find.text('Chat reply finished'), findsOneWidget);
|
||||
expect(find.text(ntfySectionSubtitle), findsOneWidget);
|
||||
expect(find.byType(CheckboxListTile), findsNWidgets(3));
|
||||
expect(_checked(tester, 'run_finished'), isTrue);
|
||||
expect(_checked(tester, 'chat_needs_you'), isFalse);
|
||||
expect(_checked(tester, 'chat_reply_finished'), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('shows the server default: only marked runs', (tester) async {
|
||||
// The server's defaults: run ends notify only for "Notify me" runs.
|
||||
final gateway = _Gateway((_, _) => _reply(false, true, false));
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -73,24 +79,53 @@ void main() {
|
||||
expect(_checked(tester, 'chat_reply_finished'), isFalse);
|
||||
});
|
||||
|
||||
testWidgets('toggling writes only that setting', (tester) async {
|
||||
final gateway = _Gateway((type, fields) {
|
||||
if (type == 'set_notification_settings') {
|
||||
return _reply(true, true, true);
|
||||
}
|
||||
return _reply(true, true, false);
|
||||
for (final key in ['run_finished', 'chat_needs_you', 'chat_reply_finished']) {
|
||||
testWidgets('toggling $key writes only that setting', (tester) async {
|
||||
final gateway = _Gateway((type, fields) {
|
||||
if (type == 'set_notification_settings') {
|
||||
return _reply(true, true, true);
|
||||
}
|
||||
return _reply(false, false, false);
|
||||
});
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_tile(key));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls, hasLength(2));
|
||||
expect(gateway.calls.last.$1, 'set_notification_settings');
|
||||
expect(gateway.calls.last.$2, {
|
||||
'notification_settings': {key: true},
|
||||
});
|
||||
expect(_checked(tester, key), isTrue);
|
||||
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a legacy ntfy_enabled key in the reply is ignored', (
|
||||
tester,
|
||||
) async {
|
||||
JsonMap legacy() => {
|
||||
'type': 'notification_settings',
|
||||
'notification_settings': {
|
||||
...(_reply(true, true, false)['notification_settings'] as Map),
|
||||
'ntfy_enabled': true,
|
||||
},
|
||||
};
|
||||
final gateway = _Gateway((_, _) => legacy());
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(ntfySettingKey('chat_reply_finished')));
|
||||
expect(find.byType(CheckboxListTile), findsNWidgets(3));
|
||||
expect(_tile('ntfy_enabled'), findsNothing);
|
||||
expect(find.textContaining('ntfy'), findsNothing);
|
||||
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
|
||||
|
||||
// A write after such a reply still sends only the toggled key.
|
||||
await tester.tap(_tile('chat_reply_finished'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls, hasLength(2));
|
||||
expect(gateway.calls.last.$1, 'set_notification_settings');
|
||||
expect(gateway.calls.last.$2, {
|
||||
'notification_settings': {'chat_reply_finished': true},
|
||||
});
|
||||
expect(_checked(tester, 'chat_reply_finished'), isTrue);
|
||||
expect(find.byKey(ntfyErrorKey), findsNothing);
|
||||
expect(find.byType(CheckboxListTile), findsNWidgets(3));
|
||||
});
|
||||
|
||||
testWidgets('failure reverts and shows the refusal', (tester) async {
|
||||
@@ -101,53 +136,50 @@ void main() {
|
||||
});
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
|
||||
await tester.tap(_tile('run_finished'));
|
||||
await tester.pump();
|
||||
// The change shows at once and the group is disabled while it saves.
|
||||
expect(_checked(tester, 'run_finished'), isFalse);
|
||||
await tester.tap(find.byKey(ntfySettingKey('chat_needs_you')));
|
||||
await tester.tap(_tile('chat_needs_you'));
|
||||
await tester.pump();
|
||||
expect(gateway.calls, hasLength(2));
|
||||
pending.completeError(const ProtocolError('settings are read-only'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_checked(tester, 'run_finished'), isTrue);
|
||||
expect(_checked(tester, 'chat_needs_you'), isTrue);
|
||||
expect(
|
||||
find.text('Could not save: settings are read-only'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Could not save: settings are read-only'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('disabled while loading and offline', (tester) async {
|
||||
testWidgets('disabled while loading', (tester) async {
|
||||
final pending = Completer<JsonMap>();
|
||||
final gateway = _Gateway((_, _) => pending.future);
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pump();
|
||||
expect(find.text('Loading…'), findsOneWidget);
|
||||
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
|
||||
await tester.tap(_tile('run_finished'));
|
||||
await tester.pump();
|
||||
expect(gateway.calls, hasLength(1));
|
||||
expect(
|
||||
tester
|
||||
.widget<CheckboxListTile>(find.byKey(ntfySettingKey('run_finished')))
|
||||
.onChanged,
|
||||
tester.widget<CheckboxListTile>(_tile('run_finished')).onChanged,
|
||||
isNull,
|
||||
);
|
||||
pending.complete(_reply(true, true, false));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Loading…'), findsNothing);
|
||||
});
|
||||
|
||||
final offline = _Gateway((_, _) => _reply(true, true, false));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SettingsNtfySection(gateway: offline, connected: false),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('offline: no request, the offline text, switches disabled', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _Gateway((_, _) => _reply(true, true, false));
|
||||
await tester.pumpWidget(_host(gateway, connected: false));
|
||||
await tester.pumpAndSettle();
|
||||
expect(offline.calls, isEmpty);
|
||||
expect(find.text(ntfyOfflineText), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
expect(find.text(notificationEventsOfflineText), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<CheckboxListTile>(_tile('chat_needs_you')).onChanged,
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a load failure is shown with a retry', (tester) async {
|
||||
@@ -165,47 +197,7 @@ void main() {
|
||||
fail = false;
|
||||
await tester.tap(find.text('Retry'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(ntfyErrorKey), findsNothing);
|
||||
expect(
|
||||
tester
|
||||
.widget<CheckboxListTile>(find.byKey(ntfySettingKey('run_finished')))
|
||||
.value,
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
group('ntfy_enabled', () {
|
||||
JsonMap withNtfy(bool ntfy) => {
|
||||
'type': 'notification_settings',
|
||||
'notification_settings': {
|
||||
...(_reply(true, true, false)['notification_settings'] as Map),
|
||||
'ntfy_enabled': ntfy,
|
||||
},
|
||||
};
|
||||
|
||||
testWidgets('hidden when the server does not send it', (tester) async {
|
||||
final gateway = _Gateway((_, _) => _reply(true, true, false));
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(ntfySettingKey('ntfy_enabled')), findsNothing);
|
||||
expect(find.text(ntfySectionSubtitle), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows and writes it', (tester) async {
|
||||
final gateway = _Gateway(
|
||||
(type, _) => withNtfy(type == 'set_notification_settings'),
|
||||
);
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Also send to ntfy'), findsOneWidget);
|
||||
expect(find.text(ntfySectionAppSubtitle), findsOneWidget);
|
||||
expect(_checked(tester, 'ntfy_enabled'), isFalse);
|
||||
await tester.tap(find.byKey(ntfySettingKey('ntfy_enabled')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls.last.$2, {
|
||||
'notification_settings': {'ntfy_enabled': true},
|
||||
});
|
||||
expect(_checked(tester, 'ntfy_enabled'), isTrue);
|
||||
});
|
||||
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
|
||||
expect(_checked(tester, 'run_finished'), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -164,8 +164,8 @@ void main() {
|
||||
'ping',
|
||||
'notification_settings',
|
||||
]);
|
||||
await openSettingsSection(tester, 'Phone notifications');
|
||||
_answerNtfySettings(factory.last);
|
||||
await openSettingsSection(tester, 'Notification events');
|
||||
_answerNotificationSettings(factory.last);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(factory.last.decodedOutgoing, hasLength(2));
|
||||
@@ -203,8 +203,8 @@ void main() {
|
||||
expect(find.text(serverDetailsPending), findsNothing);
|
||||
expect(find.text('Server build unavailable'), findsOneWidget);
|
||||
expect(find.text('Server time unavailable'), findsOneWidget);
|
||||
await openSettingsSection(tester, 'Phone notifications');
|
||||
_answerNtfySettings(factory.last);
|
||||
await openSettingsSection(tester, 'Notification events');
|
||||
_answerNotificationSettings(factory.last);
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
@@ -521,8 +521,8 @@ Future<void> _pump(
|
||||
await openSettingsSection(tester, 'Connection');
|
||||
}
|
||||
|
||||
/// Answers the Settings screen's queued ntfy-settings load on [channel].
|
||||
void _answerNtfySettings(FakeChannel channel) {
|
||||
/// Answers the Settings screen's queued notification-settings load on [channel].
|
||||
void _answerNotificationSettings(FakeChannel channel) {
|
||||
final request = channel.decodedOutgoing.last;
|
||||
expect(request['type'], 'notification_settings');
|
||||
channel.reply(<String, dynamic>{
|
||||
|
||||
@@ -48,7 +48,7 @@ void main() {
|
||||
..._filler(6),
|
||||
SettingsSection(
|
||||
id: 'server',
|
||||
title: 'Phone notifications',
|
||||
title: 'Notification events',
|
||||
lazy: true,
|
||||
builder: (_) => ServerSettingsView<int>(
|
||||
load: load,
|
||||
@@ -60,11 +60,11 @@ void main() {
|
||||
// The local sections are built and the server section is only a skeleton:
|
||||
// no request runs until the list reaches it.
|
||||
expect(find.text('filler body'), findsWidgets);
|
||||
expect(find.text('Phone notifications'), findsOneWidget);
|
||||
expect(find.text('Notification events'), findsOneWidget);
|
||||
expect(fetches, 0);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.ensureVisible(find.text('Phone notifications'));
|
||||
await tester.ensureVisible(find.text('Notification events'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(fetches, 1);
|
||||
@@ -131,8 +131,8 @@ void main() {
|
||||
..._filler(6),
|
||||
SettingsSection(
|
||||
id: 'server',
|
||||
title: 'Phone notifications',
|
||||
keywords: 'ntfy push',
|
||||
title: 'Notification events',
|
||||
keywords: 'push devices',
|
||||
lazy: true,
|
||||
builder: (_) => ServerSettingsView<int>(
|
||||
load: load,
|
||||
@@ -144,7 +144,7 @@ void main() {
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const ValueKey('settings.search')),
|
||||
'ntfy',
|
||||
'devices',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
Reference in New Issue
Block a user