Report delivered device count from the test-notification endpoint

POST /api/notifications/test previously returned a blanket 200 even when there
were no registered devices, so a test that reached nobody looked like a success.
push::send now returns the number of devices the relay confirmed delivery to, and
the endpoint returns it as {"delivered": N}. Settings shows "sent to N device(s)"
on success and an explicit "No devices are registered..." warning when N is 0,
which is the case that previously masqueraded as success.

Backend, API and widget tests updated; clippy and dart analyze clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-06-09 14:06:56 -04:00
co-authored by Claude Opus 4.8
parent 0075072196
commit 475edcb2cf
8 changed files with 82 additions and 33 deletions
+15 -5
View File
@@ -143,12 +143,22 @@ class _SettingsState extends State<Settings> {
Future<void> _sendTestNotification() async {
setState(() => _testBusy = true);
try {
await BackendAPI.instance.sendTestNotification();
final delivered = await BackendAPI.instance.sendTestNotification();
if (!mounted) return;
UISnackbars.showSuccess(
context,
'Test notification sent. It should arrive shortly.',
);
if (delivered == 0) {
// The request succeeded but no device received it — usually the backend
// lost this device's token (e.g. after a restart); re-toggle to re-register.
UISnackbars.showError(
context,
'No devices are registered to receive push notifications.',
);
} else {
final devices = delivered == 1 ? 'device' : 'devices';
UISnackbars.showSuccess(
context,
'Test notification sent to $delivered $devices.',
);
}
} catch (e) {
debugPrint('Failed to send test notification: $e');
if (!mounted) return;