150481b57b
The app subscribes to the notification stream on every connection and delivers chat_notify notices: a toast when the page is focused (none if that chat is in view), a browser notification titled '<chat>: <title>' plus a '(n)' tab title count when it is not, and on insecure http pages a toast, the title count and a short chime. Low priority posts only when hidden. Replays within an hour show once; ids persist in the ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.8 KiB
Dart
50 lines
1.8 KiB
Dart
// An agent's notify call for captures of the web notification paths. Off by
|
|
// default.
|
|
//
|
|
// `?agentNotice=<ms>` answers subscribe_notifications with no backlog, then
|
|
// <ms> after it pushes one `chat_notify` notification
|
|
// for the `ui-review` chat (add `ui-review=1` so the
|
|
// chat has its title). `agentNoticePriority=2|3|4`
|
|
// sets its priority (default 3).
|
|
import 'dart:async';
|
|
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
|
|
Map<String, String> _params = const {};
|
|
|
|
void configureAgentNoticeFixture(Map<String, String> params) =>
|
|
_params = params;
|
|
|
|
/// The subscribe reply for [request], or null when the fixture is off or the
|
|
/// request is not a subscription. Schedules the push through [emit].
|
|
JsonMap? agentNoticeReply(JsonMap request, void Function(JsonMap) emit) {
|
|
if (request['type'] != 'subscribe_notifications') return null;
|
|
final delay = int.tryParse(_params['agentNotice'] ?? '');
|
|
if (delay != null) {
|
|
final priority = int.tryParse(_params['agentNoticePriority'] ?? '') ?? 3;
|
|
Timer(Duration(milliseconds: delay), () {
|
|
emit({
|
|
'type': 'notification',
|
|
'notification': {
|
|
'id': 'chat:ui-review:notify:shown_capture',
|
|
'kind': 'chat_notify',
|
|
'title': 'Build finished',
|
|
'message':
|
|
'All 412 tests pass. The release branch is ready to merge.',
|
|
'click': 'pipelines://chat/ui-review',
|
|
'priority': priority,
|
|
'tags': <String>[],
|
|
'created_at': DateTime.now().toUtc().toIso8601String(),
|
|
'group': 'chat:ui-review',
|
|
},
|
|
});
|
|
});
|
|
}
|
|
return {
|
|
'id': request['id'],
|
|
'type': 'notifications_subscribed',
|
|
'notifications': <JsonMap>[],
|
|
'ids': <String>[],
|
|
};
|
|
}
|