Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Phone: per-chat notifications All / Mentions / Muted, as on Desktop (Tony, task 8b) (#2476)

harness-for-autonomous[bot]7ea838ac41fa
diff --git a/mobile/lib/swarm/swarm_buddies_page.dart b/mobile/lib/swarm/swarm_buddies_page.dart
index 2bcc248a8..2f1904267 100644
--- a/mobile/lib/swarm/swarm_buddies_page.dart
+++ b/mobile/lib/swarm/swarm_buddies_page.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:harness_mobile/phone/fzf.dart' show fzfAge;
import 'package:harness_mobile/phone/out_of_sight.dart';
@@ -249,7 +250,8 @@ class _Note extends StatelessWidget {
/// bold and bright while its Buddy chat has something unread, quiet
/// otherwise — with how its Buddy stands after it and when the chat last
/// moved at the end; under them the chat's last message ([line]), and a dot
-/// at its end while unread.
+/// at its end while unread. A muted chat is never unread, and has a crossed
+/// bell after its name, as the desktop's sidebar draws one.
class SwarmBuddiesRow extends StatelessWidget {
const SwarmBuddiesRow({
super.key,
@@ -280,6 +282,7 @@ class SwarmBuddiesRow extends StatelessWidget {
'${row.name} $state',
if (line.isNotEmpty) line,
if (unread) 'Unread messages',
+ if (row.muted) 'Muted',
].join(', '),
excludeSemantics: true,
child: Material(
@@ -327,6 +330,17 @@ class SwarmBuddiesRow extends StatelessWidget {
),
),
),
+ if (row.muted) ...[
+ const SizedBox(width: AppSpace.xs),
+ Icon(
+ LucideIcons.bellOff,
+ key: ValueKey(
+ 'swarm-buddies-muted-${row.key}',
+ ),
+ size: 13,
+ color: AppPalette.textFaint,
+ ),
+ ],
const SizedBox(width: AppSpace.s),
Text(
state,
diff --git a/mobile/lib/swarm/swarm_buddy_chat.dart b/mobile/lib/swarm/swarm_buddy_chat.dart
index e666b966c..d47537b75 100644
--- a/mobile/lib/swarm/swarm_buddy_chat.dart
+++ b/mobile/lib/swarm/swarm_buddy_chat.dart
@@ -14,6 +14,7 @@ import 'package:harness_mobile/theme/app_theme.dart' show AppColors;
import 'model.dart';
import 'swarm_buddy.dart';
+import 'swarm_chat_menu.dart' show swarmNotifySection;
import 'swarm_conversation_page.dart';
import 'swarm_reader.dart';
import 'swarm_request.dart';
@@ -437,8 +438,9 @@ class _Field extends StatelessWidget {
/// At the end of the person's own Buddy chat's header, while they may
/// write: ⋮, with Rename Buddy, and Remove Buddy while one runs, which asks
-/// first, then stops it; the chat stays (the desktop's Buddy options).
-/// Nothing in anyone else's Buddy chat.
+/// first, then stops it; the chat stays (the desktop's Buddy options); and
+/// the chat's Notifications, as its menu on the desktop has. Nothing in
+/// anyone else's Buddy chat.
class SwarmBuddyMenuButton extends StatelessWidget {
const SwarmBuddyMenuButton({
super.key,
@@ -452,24 +454,53 @@ class SwarmBuddyMenuButton extends StatelessWidget {
/// rather than its project. Null while that chat is not known yet.
final String? chatId;
- Future<void> _open(BuildContext context, String chatId) => showPhoneSheet(
- context,
- title: swarmBuddyName(actions.reader, actions.projectId),
- actions: [
- PhoneSheetAction(
- icon: LucideIcons.pencil,
- label: 'Rename Buddy',
- onTap: () => unawaited(_rename(context, chatId)),
- ),
- if (swarmBuddy(actions.reader, actions.projectId) != null)
- PhoneSheetAction(
- icon: LucideIcons.userMinus,
- label: 'Remove Buddy',
- destructive: true,
- onTap: () => unawaited(_confirmRemove(context)),
+ /// The sheet, with the chat's Notifications under the Buddy's own rows
+ /// ([swarmNotifySection]). It goes once the chat is no longer the
+ /// person's own Buddy chat to read: access lost, or signed out.
+ Future<void> _open(BuildContext context, String chatId) async {
+ final reader = actions.reader;
+ Route<void>? sheet;
+ void moved() {
+ final route = sheet;
+ if (route == null ||
+ (!reader.accessRevoked && swarmIsOwnBuddyChat(reader, chatId))) {
+ return;
+ }
+ sheet = null;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (route.isActive) route.navigator?.removeRoute(route);
+ });
+ }
+
+ reader.addListener(moved);
+ try {
+ await showPhoneSheet(
+ context,
+ title: swarmBuddyName(reader, actions.projectId),
+ onShown: (route) => sheet = route,
+ rebuildOn: reader,
+ rows: () => (
+ actions: [
+ PhoneSheetAction(
+ icon: LucideIcons.pencil,
+ label: 'Rename Buddy',
+ onTap: () => unawaited(_rename(context, chatId)),
+ ),
+ if (swarmBuddy(reader, actions.projectId) != null)
+ PhoneSheetAction(
+ icon: LucideIcons.userMinus,
+ label: 'Remove Buddy',
+ destructive: true,
+ onTap: () => unawaited(_confirmRemove(context)),
+ ),
+ ],
+ sections: [swarmNotifySection(context, reader, chatId)],
),
- ],
- );
+ );
+ } finally {
+ reader.removeListener(moved);
+ }
+ }
Future<void> _rename(BuildContext context, String chatId) async {
if (!context.mounted) return;
diff --git a/mobile/lib/swarm/swarm_buddy_list.dart b/mobile/lib/swarm/swarm_buddy_list.dart
index b56e5afa5..0a6d63fdc 100644
--- a/mobile/lib/swarm/swarm_buddy_list.dart
+++ b/mobile/lib/swarm/swarm_buddy_list.dart
@@ -3,9 +3,11 @@ import 'package:flutter/foundation.dart';
import 'identity.dart';
import 'model.dart';
import 'swarm_buddy.dart';
+import 'swarm_chat_notify.dart';
import 'swarm_inbox.dart';
import 'swarm_reader.dart';
import 'swarm_session.dart';
+import 'swarm_unread.dart';
/// One project on Buddies (Tony's prototype C2): the person's own Buddy in
/// [project] of Swarm [swarmId], by its [name] ("Buddy" while none runs) and
@@ -23,6 +25,7 @@ class SwarmBuddyRow {
this.chat,
this.last,
this.unread = false,
+ this.muted = false,
});
final String swarmId;
@@ -31,8 +34,13 @@ class SwarmBuddyRow {
final String? note;
final SuperTabConversation? chat;
final SuperTabMessage? last;
+
+ /// Its chat has something unread, and is not muted.
final bool unread;
+ /// The person muted its chat ([SwarmNotify.muted]): greyed, never unread.
+ final bool muted;
+
/// When the chat last moved: its last message, or the chat's own change
/// until that is read.
DateTime? get at => last?.createdAt ?? chat?.changedAt;
@@ -199,7 +207,10 @@ class SwarmBuddyList extends ChangeNotifier {
note: swarmBuddyNote(reader, project.id),
chat: chat,
last: peek?.messages.where((m) => m.inMainStream).lastOrNull,
- unread: chat != null && (reader.readMarks?.unread(chat) ?? false),
+ // A muted chat never shows unread or counts (the desktop's
+ // `buddyUnread`).
+ unread: chat != null && swarmUnreadShown(reader, chat),
+ muted: chat != null && swarmMuted(reader, chat),
),
);
}
diff --git a/mobile/lib/swarm/swarm_chat_menu.dart b/mobile/lib/swarm/swarm_chat_menu.dart
new file mode 100644
index 000000000..efe80e17a
--- /dev/null
+++ b/mobile/lib/swarm/swarm_chat_menu.dart
@@ -0,0 +1,216 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/phone/phone_sheet.dart';
+import 'package:harness_mobile/shared/theme/app_icon_size.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/shared/widgets/touch_target.dart';
+
+import 'swarm_chat_notify.dart';
+import 'swarm_reader.dart';
+
+/// The chat menu's Notifications rows (the desktop's chat menu, Slack's
+/// channel notifications): one per [SwarmNotify], the reader's own setting
+/// for chat [chatId] ticked (✓), kept on every device of theirs. A tap sets it
+/// ([swarmSetNotify]).
+PhoneSheetSection swarmNotifySection(
+ BuildContext context,
+ SwarmReader reader,
+ String chatId,
+) {
+ final now = reader.notifyOf(chatId);
+ return PhoneSheetSection(
+ caption: 'Notifications',
+ actions: [
+ for (final level in SwarmNotify.values)
+ PhoneSheetAction(
+ icon: level == now
+ ? LucideIcons.check300
+ : switch (level) {
+ SwarmNotify.all => LucideIcons.bellRing300,
+ SwarmNotify.mentions => LucideIcons.atSign300,
+ SwarmNotify.muted => LucideIcons.bellOff300,
+ },
+ label: level.label,
+ // The sheet draws no icons: the one set says so at its end.
+ value: level == now ? '✓' : null,
+ valueColor: AppPalette.textPrimary,
+ onTap: () =>
+ unawaited(swarmSetNotify(context, reader, chatId, level)),
+ ),
+ ],
+ );
+}
+
+/// Sets [level] for chat [chatId] ([SwarmReader.setNotify]), and says so
+/// when the server did not keep it — not once the chat's page is gone or
+/// the Swarm can no longer be read.
+Future<void> swarmSetNotify(
+ BuildContext context,
+ SwarmReader reader,
+ String chatId,
+ SwarmNotify level,
+) async {
+ final messenger = ScaffoldMessenger.maybeOf(context);
+ if (await reader.setNotify(chatId, level) ||
+ !context.mounted ||
+ reader.accessRevoked ||
+ reader.snapshot?.conversation(chatId) == null) {
+ return;
+ }
+ messenger?.showSnackBar(
+ const SnackBar(
+ key: ValueKey('swarm-notify-failed'),
+ content: Text('Could not change notifications. Try again.'),
+ ),
+ );
+}
+
+/// The sheet of chat [chatId]'s Notifications, titled with its name: from
+/// its ⋮, or the project page's for its project chat. It goes once the chat
+/// can no longer be read — access lost, signed out, or the chat gone.
+Future<void> showSwarmNotifySheet(
+ BuildContext context,
+ SwarmReader reader,
+ String chatId, {
+ void Function(Route<void> route)? onShown,
+}) async {
+ Route<void>? sheet;
+ void moved() {
+ final route = sheet;
+ if (route == null ||
+ (!reader.accessRevoked &&
+ reader.snapshot?.conversation(chatId) != null)) {
+ return;
+ }
+ sheet = null;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (route.isActive) route.navigator?.removeRoute(route);
+ });
+ }
+
+ reader.addListener(moved);
+ try {
+ await showPhoneSheet(
+ context,
+ title: reader.snapshot?.conversation(chatId)?.title ?? '',
+ onShown: (route) {
+ sheet = route;
+ onShown?.call(route);
+ },
+ // A setting changed on another device meanwhile ticks here too.
+ rebuildOn: reader,
+ rows: () => (
+ actions: const [],
+ sections: [swarmNotifySection(context, reader, chatId)],
+ ),
+ );
+ } finally {
+ reader.removeListener(moved);
+ }
+}
+
+/// At the end of a chat's header: ⋮, whose sheet holds the chat's
+/// Notifications ([swarmNotifySection]), as the desktop's chat menu does for
+/// every chat a person reads, a viewer's too. Nothing while the chat is not
+/// known. The sheet goes once the chat can no longer be read — access lost,
+/// signed out, or the chat gone — or this header does.
+class SwarmChatMenuButton extends StatefulWidget {
+ const SwarmChatMenuButton({
+ super.key,
+ required this.reader,
+ required this.chatId,
+ });
+
+ final SwarmReader reader;
+ final String chatId;
+
+ @override
+ State<SwarmChatMenuButton> createState() => _SwarmChatMenuButtonState();
+}
+
+class _SwarmChatMenuButtonState extends State<SwarmChatMenuButton> {
+ Route<void>? _sheet;
+
+ bool get _readable =>
+ !widget.reader.accessRevoked &&
+ widget.reader.snapshot?.conversation(widget.chatId) != null;
+
+ @override
+ void initState() {
+ super.initState();
+ widget.reader.addListener(_moved);
+ }
+
+ @override
+ void didUpdateWidget(SwarmChatMenuButton old) {
+ super.didUpdateWidget(old);
+ if (old.reader == widget.reader && old.chatId == widget.chatId) return;
+ old.reader.removeListener(_moved);
+ widget.reader.addListener(_moved);
+ _closeSheet();
+ }
+
+ @override
+ void dispose() {
+ widget.reader.removeListener(_moved);
+ _closeSheet();
+ super.dispose();
+ }
+
+ void _moved() {
+ if (!_readable) _closeSheet();
+ if (mounted) setState(() {});
+ }
+
+ /// Takes the sheet down, once this frame is done: a header that lost its
+ /// chat may not change the navigator while it builds.
+ void _closeSheet() {
+ final sheet = _sheet;
+ _sheet = null;
+ if (sheet == null) return;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (sheet.isActive) sheet.navigator?.removeRoute(sheet);
+ });
+ }
+
+ Future<void> _open() => showSwarmNotifySheet(
+ context,
+ widget.reader,
+ widget.chatId,
+ onShown: (route) => _sheet = route,
+ ).whenComplete(() => _sheet = null);
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ if (!_readable) return const SizedBox.shrink();
+ return Semantics(
+ key: const ValueKey('swarm-chat-menu'),
+ button: true,
+ label: 'Chat options',
+ excludeSemantics: true,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ HapticFeedback.selectionClick();
+ unawaited(_open());
+ },
+ child: SizedBox.square(
+ dimension: minTouchTarget,
+ child: Align(
+ alignment: AlignmentDirectional.centerEnd,
+ child: Icon(
+ LucideIcons.ellipsisVertical300,
+ size: AppIconSize.standalone,
+ color: AppPalette.textPrimary,
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/swarm/swarm_chat_notify.dart b/mobile/lib/swarm/swarm_chat_notify.dart
new file mode 100644
index 000000000..99b079eb6
--- /dev/null
+++ b/mobile/lib/swarm/swarm_chat_notify.dart
@@ -0,0 +1,30 @@
+import 'model.dart';
+import 'swarm_reader.dart';
+
+/// A person's notification setting for one chat, as Slack's channel settings
+/// and the desktop's `SuperTabNotify` (backend chatSettings.ts): every new
+/// message, only tags of them (the default), or muted: greyed, never bold,
+/// never counting. Kept per person on the server, so it follows them to every
+/// device.
+enum SwarmNotify {
+ all('All new messages'),
+ mentions('Mentions only'),
+ muted('Muted');
+
+ const SwarmNotify(this.label);
+
+ /// What the chat menu calls it, as the desktop's does.
+ final String label;
+
+ /// The server's word for it; anything else, or none, is the default.
+ static SwarmNotify parse(String? value) => switch (value) {
+ 'all' => all,
+ 'muted' => muted,
+ _ => mentions,
+ };
+}
+
+/// Whether [group] is muted for the reader: the setting they just chose on
+/// this phone, else the one the server last said ([SwarmReader.notifyOf]).
+bool swarmMuted(SwarmReader reader, SuperTabConversation group) =>
+ reader.notifyOf(group.id) == SwarmNotify.muted;
diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dart
index 77cf558ab..a2586eb09 100644
--- a/mobile/lib/swarm/swarm_conversation_page.dart
+++ b/mobile/lib/swarm/swarm_conversation_page.dart
@@ -25,6 +25,7 @@ import 'swarm_post_line.dart';
import 'swarm_attach.dart';
import 'swarm_buddy.dart';
import 'swarm_buddy_chat.dart';
+import 'swarm_chat_menu.dart';
import 'swarm_file_links.dart';
import 'swarm_choices.dart';
import 'swarm_conversation.dart';
@@ -1215,13 +1216,15 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>
? view.title
: null,
project: view.project,
- // The person's own Buddy chat: Rename Buddy, Remove Buddy.
+ // The person's own Buddy chat: its Notifications, Rename Buddy,
+ // Remove Buddy. Any other chat: its Notifications (the desktop's
+ // chat menu).
action: switch (_buddy) {
final buddy? => SwarmBuddyMenuButton(
actions: buddy,
chatId: widget.conversationId,
),
- null => null,
+ null => SwarmChatMenuButton(reader: c.reader, chatId: c.id),
},
),
),
diff --git a/mobile/lib/swarm/swarm_notices.dart b/mobile/lib/swarm/swarm_notices.dart
index 6620cd795..890ac4103 100644
--- a/mobile/lib/swarm/swarm_notices.dart
+++ b/mobile/lib/swarm/swarm_notices.dart
@@ -3,7 +3,9 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import '../notify/system_notices.dart';
+import 'swarm_chat_notify.dart';
import 'swarm_inbox.dart';
+import 'swarm_reader.dart';
/// The notice that tells the person about [need]: who asks, and in which
/// project.
@@ -66,8 +68,9 @@ class SwarmAnnouncer {
final SwarmNotices notices;
- /// The person sees [need] where they are: no notice.
- final bool Function(SwarmNeed need) quiet;
+ /// The person sees [need] where they are: no notice. Null asks for a
+ /// chat's new messages ([announceChat]).
+ final bool Function(SwarmNeed? need) quiet;
/// What this phone has told the account already: never told again.
final SwarmTold told;
@@ -108,6 +111,11 @@ class SwarmAnnouncer {
_takeDown(key);
}
}
+ if (readable != null) {
+ for (final MapEntry(:key, :value) in _chats.entries.toList()) {
+ if (!readable.contains(value.swarmId)) _takeDownChat(key);
+ }
+ }
if (needs.length != _badge) {
_badge = needs.length;
unawaited(notices.setSwarmBadge(needs.length));
@@ -133,6 +141,59 @@ class SwarmAnnouncer {
}
}
+ /// The notices of chats set to All new messages ([SwarmChatNotices]):
+ /// each key's Swarm, chat and how far it went.
+ final _chats = <String, ({String swarmId, String chatId, int sequence})>{};
+
+ /// Posts or moves on chat [chatId]'s "New messages" notice: one per chat,
+ /// which a newer message replaces, as nothing waits to be answered. Names
+ /// the project only: a notice can be read on a locked phone, and the chat's
+ /// name is read in the app ([swarmNotice]).
+ void announceChat({
+ required String swarmId,
+ required String chatId,
+ required String project,
+ required int sequence,
+ }) {
+ if (quiet(null)) return;
+ final key = 'chat:$swarmId:$chatId';
+ _chats[key] = (swarmId: swarmId, chatId: chatId, sequence: sequence);
+ unawaited(
+ notices.showSwarm((
+ key: key,
+ title: 'New messages',
+ subtitle: project,
+ body: 'Open Harness to read them.',
+ target: (
+ swarmId: swarmId,
+ conversationId: chatId,
+ messageId: null,
+ decisionId: null,
+ ),
+ )),
+ );
+ }
+
+ /// Takes a chat's notice down once what it told is read, the chat is no
+ /// longer in Swarm [swarmId] as [reader] reads it, or that can no longer
+ /// be read at all.
+ void chatsRead(String swarmId, SwarmReader reader) {
+ for (final MapEntry(:key, :value) in _chats.entries.toList()) {
+ if (value.swarmId != swarmId) continue;
+ final read = reader.readMarks?.readThrough(value.chatId);
+ if (reader.accessRevoked ||
+ reader.snapshot?.conversation(value.chatId) == null ||
+ (read != null && read >= value.sequence)) {
+ _takeDownChat(key);
+ }
+ }
+ }
+
+ void _takeDownChat(String key) {
+ _chats.remove(key);
+ unawaited(notices.cancelSwarm(key));
+ }
+
void _takeDown(String key) {
_posted.remove(key);
_missed.remove(key);
@@ -145,6 +206,9 @@ class SwarmAnnouncer {
for (final key in _posted.keys.toList()) {
_takeDown(key);
}
+ for (final key in _chats.keys.toList()) {
+ _takeDownChat(key);
+ }
settle(const []);
}
}
@@ -206,3 +270,56 @@ void swarmBadgeOffWhileSignedOut(
app.addListener(check);
check();
}
+
+/// What tells of each new message in a chat set to All new messages
+/// ([SwarmNotify.all]), as the desktop's `SuperTabChatNotices`: after a read
+/// of its Swarm, a chat whose newest main-stream message moved past what the
+/// last read held, and past what the person has read. The first look at a
+/// chat is not news; nor is a read under another hold of the Swarm (a first
+/// load again, or access moved), which starts over telling nothing. Muted and
+/// Mentions only chats tell nothing here: their tags are told as needs.
+class SwarmChatNotices {
+ SwarmChatNotices(this.announcer);
+
+ final SwarmAnnouncer announcer;
+
+ /// How far each chat went at the last read, by Swarm; with the hold
+ /// ([SwarmReader.generation]) it was read under.
+ final _seen = <String, ({int generation, Map<String, int> tops})>{};
+
+ /// Swarm [swarmId] was read by [reader].
+ void read(String swarmId, SwarmReader reader) {
+ final snapshot = reader.snapshot;
+ if (reader.accessRevoked || snapshot == null) {
+ _seen.remove(swarmId);
+ announcer.chatsRead(swarmId, reader);
+ return;
+ }
+ final held = _seen[swarmId];
+ final first = held == null || held.generation != reader.generation;
+ final tops = <String, int>{};
+ for (final group in snapshot.conversations) {
+ final top = group.mainSequence;
+ tops[group.id] = top;
+ if (first) continue;
+ final before = held.tops[group.id];
+ if (before == null || top <= before) continue;
+ if (reader.notifyOf(group.id) != SwarmNotify.all) continue;
+ final read = reader.readMarks?.readThrough(group.id);
+ // Marks not back yet: nothing says it is unread.
+ if (read == null || top <= read) continue;
+ announcer.announceChat(
+ swarmId: swarmId,
+ chatId: group.id,
+ project: snapshot.projectById(group.projectId)?.name ?? '',
+ sequence: top,
+ );
+ }
+ _seen[swarmId] = (generation: reader.generation, tops: tops);
+ announcer.chatsRead(swarmId, reader);
+ }
+
+ /// Only [swarms] are read now: the rest are forgotten.
+ void keepOnly(Set<String> swarms) =>
+ _seen.removeWhere((id, _) => !swarms.contains(id));
+}
diff --git a/mobile/lib/swarm/swarm_project_page.dart b/mobile/lib/swarm/swarm_project_page.dart
index 432b3676a..a23710a61 100644
--- a/mobile/lib/swarm/swarm_project_page.dart
+++ b/mobile/lib/swarm/swarm_project_page.dart
@@ -16,6 +16,7 @@ import 'package:harness_mobile/theme/app_theme.dart' show AppColors;
import 'model.dart';
import 'swarm_buddy.dart';
import 'swarm_buddy_chat.dart';
+import 'swarm_chat_menu.dart';
import 'swarm_conversation_page.dart';
import 'swarm_home_keeper.dart';
import 'swarm_home_rows.dart';
@@ -529,10 +530,27 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {
actions: _buddy!,
chatId: swarmBuddyChat(_buddy!.reader, widget.projectId)?.id,
),
+ // The project chat's Notifications (the desktop's chat menu): its
+ // header is the project's, so they are here.
+ if (_tab == SwarmProjectTab.chat && !_homeC)
+ SwarmChatMenuButton(
+ reader: reader,
+ chatId: project.leadConversationId,
+ ),
if (_homeC)
_ProjectMenu(
onLeaderboard: _openLeaderboardSheet,
onTeam: _openTeamSheet,
+ onNotifications:
+ snapshot.conversation(project.leadConversationId) == null
+ ? null
+ : () => unawaited(
+ showSwarmNotifySheet(
+ context,
+ reader,
+ project.leadConversationId,
+ ),
+ ),
)
else
SwarmIconButton(
@@ -738,12 +756,18 @@ class _Frame extends StatelessWidget {
}
/// ⋮ at the end of a Swarm Home C project's header: a small menu, on the
-/// design system's menu surface (the theme's), of its Leaderboard and its Team.
-/// It goes with the header: losing the project closes it.
+/// design system's menu surface (the theme's), of its Leaderboard, its Team
+/// and its project chat's Notifications ([showSwarmNotifySheet]), while that
+/// chat is read. It goes with the header: losing the project closes it.
class _ProjectMenu extends StatelessWidget {
- const _ProjectMenu({required this.onLeaderboard, required this.onTeam});
+ const _ProjectMenu({
+ required this.onLeaderboard,
+ required this.onTeam,
+ this.onNotifications,
+ });
final VoidCallback onLeaderboard, onTeam;
+ final VoidCallback? onNotifications;
@override
Widget build(BuildContext context) {
@@ -765,6 +789,8 @@ class _ProjectMenu extends StatelessWidget {
menuChildren: [
row('swarm-project-menu-leaderboard', 'Leaderboard', onLeaderboard),
row('swarm-project-menu-team', 'Team', onTeam),
+ if (onNotifications case final onTap?)
+ row('swarm-project-menu-notifications', 'Notifications', onTap),
],
builder: (context, menu, _) => SwarmIconButton(
key: const ValueKey('swarm-project-menu'),
diff --git a/mobile/lib/swarm/swarm_reader.dart b/mobile/lib/swarm/swarm_reader.dart
index 90391cd2a..c5926c38d 100644
--- a/mobile/lib/swarm/swarm_reader.dart
+++ b/mobile/lib/swarm/swarm_reader.dart
@@ -8,6 +8,7 @@ import 'package:harness_mobile/logging/app_log.dart';
import 'model.dart';
import 'parts.dart';
import 'swarm_buddy.dart';
+import 'swarm_chat_notify.dart';
import 'swarm_read_marks.dart';
import 'swarm_request.dart';
import 'waiting_work.dart';
@@ -194,10 +195,15 @@ class SwarmReader extends ChangeNotifier {
Future<void> _read() async {
var changed = false;
final failedBefore = error;
+ final serial = ++_readSerial;
try {
final read = await _readParts();
if (_disposed || accessRevoked) return;
final parts = _parts!;
+ // Sent before this read began: what it holds is the server's own now.
+ final settled = _notifyKept.length;
+ _notifyKept.removeWhere((_, kept) => kept.$2 < serial);
+ if (_notifyKept.length != settled) changed = true;
if (read.changed || snapshot == null) {
final views = _views;
final view = read.view ?? await _view(parts, accountId, big: _bigParts);
@@ -312,6 +318,8 @@ class SwarmReader extends ChangeNotifier {
void _forget() {
accessRevoked = true;
+ _notifySending.clear();
+ _notifyKept.clear();
snapshot = null;
partners = const {};
buddies = SwarmBuddies.none;
@@ -323,6 +331,66 @@ class SwarmReader extends ChangeNotifier {
_poll?.cancel();
}
+ /// The reader's notification setting for chat [id] (backend
+ /// chatSettings.ts): the one being sent, else the one the server kept and
+ /// no read has carried yet, else the last read's, else Mentions only.
+ SwarmNotify notifyOf(String id) =>
+ _notifySending[id] ??
+ _notifyKept[id]?.$1 ??
+ SwarmNotify.parse(snapshot?.chatSettings[id]);
+
+ /// Settings sent and not yet answered: the newest choice per chat, with
+ /// its number.
+ final _notifySending = <String, SwarmNotify>{};
+ final _notifyAsked = <String, int>{};
+
+ /// Settings the server kept, until a read carries them, with the number of
+ /// the newest read begun when it answered: one begun after it carries the
+ /// setting. Without it a chat would flick back to the last read's setting
+ /// meanwhile.
+ final _notifyKept = <String, (SwarmNotify, int)>{};
+
+ /// Reads begun, in order ([_read]).
+ int _readSerial = 0;
+
+ /// Keeps [level] for chat [id] on every device of the reader, through the
+ /// desktop's own call: shown at once, and the old setting back when the
+ /// server did not keep it. A later choice for the same chat wins over one
+ /// still on its way. False only when the newest choice was not kept; an
+ /// answer after access went changes nothing.
+ Future<bool> setNotify(String id, SwarmNotify level) async {
+ if (_disposed || accessRevoked || snapshot?.conversation(id) == null) {
+ return false;
+ }
+ final asked = (_notifyAsked[id] ?? 0) + 1;
+ _notifyAsked[id] = asked;
+ _notifySending[id] = level;
+ notifyListeners();
+ var kept = false;
+ try {
+ final answer = superTabMap(
+ await request(
+ 'POST',
+ '$_path/conversations/${Uri.encodeComponent(id)}/notifications',
+ body: {'notify': level.name},
+ ),
+ );
+ kept = answer['notify'] == level.name;
+ } catch (_) {
+ kept = false;
+ }
+ // A newer choice for this chat settles it; access gone takes it away.
+ if (_disposed || accessRevoked || _notifyAsked[id] != asked) return true;
+ _notifyAsked.remove(id);
+ _notifySending.remove(id);
+ // Kept only while the chat is still one the reader reads.
+ if (kept && snapshot?.conversation(id) != null) {
+ _notifyKept[id] = (level, _readSerial);
+ }
+ notifyListeners();
+ return kept;
+ }
+
/// A dormant stub says a held group closed, not how: its data is read again
/// by id. Best effort: a failure leaves it as it was until the next read.
Future<bool> _refreshStale(SuperTabParts parts) async {
diff --git a/mobile/lib/swarm/swarm_session.dart b/mobile/lib/swarm/swarm_session.dart
index e4b9475cb..fd0ef8c6f 100644
--- a/mobile/lib/swarm/swarm_session.dart
+++ b/mobile/lib/swarm/swarm_session.dart
@@ -52,6 +52,7 @@ class SwarmSession extends ChangeNotifier {
quiet: (_) => !swarmLocalNotices || _screens > 0,
told: told,
);
+ _chatNotices = SwarmChatNotices(_announcer);
inbox
..onArrived = announce
..onSwarmRead = _swarmRead
@@ -83,6 +84,9 @@ class SwarmSession extends ChangeNotifier {
final Duration undoWindow;
late final SwarmAnnouncer _announcer;
+
+ /// What tells of new messages in chats set to All new messages.
+ late final SwarmChatNotices _chatNotices;
int _screens = 0;
final _watching = <String, int>{};
final _held = <String, ({int choice, Timer timer})>{};
@@ -112,6 +116,7 @@ class SwarmSession extends ChangeNotifier {
final _readsToCount = <String>{};
void _swarmRead(String id) {
+ if (inbox.reader(id) case final reader?) _chatNotices.read(id, reader);
_readsToCount.add(id);
_countReads();
}
@@ -209,7 +214,9 @@ class SwarmSession extends ChangeNotifier {
void _needsChanged() {
_show();
if (inbox.loaded) {
- home.keepOnly({for (final swarm in inbox.swarms) swarm.id});
+ final listed = {for (final swarm in inbox.swarms) swarm.id};
+ home.keepOnly(listed);
+ _chatNotices.keepOnly(listed);
}
// What was read of a Swarm off the list, or out of reach, leaves memory.
peeks.keepOnly([for (final swarm in inbox.swarms) ?inbox.reader(swarm.id)]);
diff --git a/mobile/lib/swarm/swarm_threads.dart b/mobile/lib/swarm/swarm_threads.dart
index 5063553a1..00752d4c6 100644
--- a/mobile/lib/swarm/swarm_threads.dart
+++ b/mobile/lib/swarm/swarm_threads.dart
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import 'model.dart';
import 'swarm_asks.dart';
+import 'swarm_chat_notify.dart';
import 'swarm_inbox.dart' show SwarmListing;
import 'swarm_reader.dart';
import 'swarm_request.dart';
@@ -154,7 +155,7 @@ class SwarmThreads extends ChangeNotifier {
if (root == null || snapshot.conversation(m.conversationId) == null) {
continue;
}
- if (snapshot.chatSettings[m.conversationId] == 'muted') continue;
+ if (reader.notifyOf(m.conversationId) == SwarmNotify.muted) continue;
final through = marks.threadThrough(m.conversationId, root);
if (through == null) return 0;
if ((m.messageSequence ?? _unknown) > through) count++;
diff --git a/mobile/lib/swarm/swarm_unread.dart b/mobile/lib/swarm/swarm_unread.dart
index 99c5a640b..2fe1850ee 100644
--- a/mobile/lib/swarm/swarm_unread.dart
+++ b/mobile/lib/swarm/swarm_unread.dart
@@ -1,5 +1,6 @@
import 'model.dart';
import 'swarm_asks.dart';
+import 'swarm_chat_notify.dart';
import 'swarm_reader.dart';
/// What a row says is new in a chat or a project (desktop design system,
@@ -19,7 +20,7 @@ SwarmRowNews swarmChatNews(
SuperTabConversation group,
) {
final tags = swarmChatCount(reader, asks, group);
- return (bold: _unreadShown(reader, group) || tags > 0, tags: tags);
+ return (bold: swarmUnreadShown(reader, group) || tags > 0, tags: tags);
}
/// The `@` count of [group], as the desktop's red number counts
@@ -56,7 +57,7 @@ int _countIn(
) {
final snapshot = reader.snapshot;
if (reader.accessRevoked || snapshot == null) return 0;
- if (snapshot.chatSettings[group.id] == 'muted') return 0;
+ if (swarmMuted(reader, group)) return 0;
var count = 0;
if (reader.readMarks?.tagsReadThrough(group.id) case final through?) {
for (final m in mentions) {
@@ -65,7 +66,7 @@ int _countIn(
}
}
}
- if (asked > 0 && _unreadShown(reader, group)) count += asked;
+ if (asked > 0 && swarmUnreadShown(reader, group)) count += asked;
return count;
}
@@ -75,9 +76,8 @@ const _unknown = 1 << 52;
/// Whether [group] shows as unread: unread, and not muted. A muted chat stays
/// listed and never counts (the desktop's `unreadShown`).
-bool _unreadShown(SwarmReader reader, SuperTabConversation group) =>
- reader.snapshot?.chatSettings[group.id] != 'muted' &&
- (reader.readMarks?.unread(group) ?? false);
+bool swarmUnreadShown(SwarmReader reader, SuperTabConversation group) =>
+ !swarmMuted(reader, group) && (reader.readMarks?.unread(group) ?? false);
/// Each project's row with something new, by project id: bold while its
/// project chat or any of its open work shows unread, as the desktop's
@@ -109,7 +109,7 @@ Map<String, SwarmRowNews> swarmProjectNews(
continue;
}
final projectId = group.projectId;
- if (!unread.contains(projectId) && _unreadShown(reader, group)) {
+ if (!unread.contains(projectId) && swarmUnreadShown(reader, group)) {
unread.add(projectId);
}
final count = _countIn(
diff --git a/mobile/test/swarm/swarm_buddy_chat_test.dart b/mobile/test/swarm/swarm_buddy_chat_test.dart
index 4beda4bea..11650d880 100644
--- a/mobile/test/swarm/swarm_buddy_chat_test.dart
+++ b/mobile/test/swarm/swarm_buddy_chat_test.dart
@@ -499,6 +499,45 @@ void main() {
]);
});
+ testWidgets('⋮ holds the chat\'s Notifications too: Muted is kept, and '
+ 'access lost while the sheet is open closes it', (tester) async {
+ final fake = backend(buddy: wren());
+ const notify = '/api/super-tabs/$tab/conversations/$chat/notifications';
+ fake.routes[notify] = (body) => {'notify': body!['notify']};
+ final host = await pump(tester, fake);
+
+ await tester.tap(key('swarm-buddy-menu'));
+ await tester.pumpAndSettle();
+ expect(find.text('Rename Buddy'), findsOneWidget);
+ expect(find.text('notifications'), findsOneWidget);
+ await tester.tap(find.text('Muted'));
+ await tester.pumpAndSettle();
+ expect(
+ [
+ for (final call in fake.calls)
+ if (call.path == notify) call.body,
+ ],
+ [
+ {'notify': 'muted'},
+ ],
+ );
+
+ await tester.tap(key('swarm-buddy-menu'));
+ await tester.pumpAndSettle();
+ expect(find.text('Muted'), findsOneWidget);
+ const refused = SuperTabFailure(
+ 'FORBIDDEN',
+ 'You cannot read this Swarm.',
+ statusCode: 403,
+ );
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => throw refused;
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => throw refused;
+ await readAgain(tester, host);
+
+ expect(find.text('Muted'), findsNothing);
+ expect(find.text('Rename Buddy'), findsNothing);
+ });
+
testWidgets('⋮ Remove Buddy asks first; Cancel removes nothing, Remove '
'stops it', (tester) async {
final fake = backend(buddy: wren());
diff --git a/mobile/test/swarm/swarm_buddy_list_test.dart b/mobile/test/swarm/swarm_buddy_list_test.dart
index 9529c8d15..80fe458bf 100644
--- a/mobile/test/swarm/swarm_buddy_list_test.dart
+++ b/mobile/test/swarm/swarm_buddy_list_test.dart
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/notify/system_notices.dart';
import 'package:harness_mobile/swarm/swarm_buddy_list.dart';
+import 'package:harness_mobile/swarm/swarm_chat_notify.dart';
import 'package:harness_mobile/swarm/swarm_request.dart';
import 'package:harness_mobile/swarm/swarm_session.dart';
@@ -132,6 +133,44 @@ void main() {
expect((docs.name, docs.note), ('Buddy', 'not started'));
});
+ test('a muted Buddy chat is never unread and never counts on the badge, '
+ 'muted on the desktop or chosen on this phone', () async {
+ final fake = buddiesBackend();
+ final load = fake.routes['/api/super-tabs/$tab/parts']!;
+ fake.routes['/api/super-tabs/$tab/parts'] = (body) {
+ final answer = Map<String, dynamic>.of(
+ load(body) as Map<String, dynamic>,
+ );
+ answer['derived'] = {
+ ...answer['derived'] as Map<String, dynamic>,
+ 'chatSettings': {buddiesMobileChat: 'muted'},
+ };
+ return answer;
+ };
+ final session = await start(fake);
+ final list = session.buddyList..watch();
+ await settle();
+
+ expect(row(list, project).unread, isFalse);
+ expect(row(list, project).muted, isTrue);
+ expect(row(list, buddiesWeb).muted, isFalse);
+ expect(list.badge, 0);
+
+ // Back to Mentions only from this phone: unread again at once.
+ fake.routes['/api/super-tabs/$tab/conversations/$buddiesMobileChat/'
+ 'notifications'] = (_) =>
+ Completer<Object?>().future;
+ unawaited(
+ session.inbox
+ .reader(tab)!
+ .setNotify(buddiesMobileChat, SwarmNotify.mentions),
+ );
+ await settle();
+ expect(row(list, project).unread, isTrue);
+ expect(row(list, project).muted, isFalse);
+ expect(list.badge, 1);
+ });
+
test('a chat past its read mark is unread; the badge counts those', () async {
final session = await start(buddiesBackend());
final list = session.buddyList..watch();
diff --git a/mobile/test/swarm/swarm_chat_menu_test.dart b/mobile/test/swarm/swarm_chat_menu_test.dart
new file mode 100644
index 000000000..f8a84d242
--- /dev/null
+++ b/mobile/test/swarm/swarm_chat_menu_test.dart
@@ -0,0 +1,326 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+import 'package:harness_mobile/notify/system_notices.dart';
+import 'package:harness_mobile/settings/experimental_features.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;
+import 'package:harness_mobile/swarm/model.dart';
+import 'package:harness_mobile/swarm/swarm_buddies_page.dart';
+import 'package:harness_mobile/swarm/swarm_buddy_list.dart';
+import 'package:harness_mobile/swarm/swarm_chat_notify.dart';
+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';
+import 'package:harness_mobile/swarm/swarm_project_page.dart';
+import 'package:harness_mobile/swarm/swarm_project_tabs.dart';
+import 'package:harness_mobile/swarm/swarm_request.dart';
+import 'package:harness_mobile/swarm/swarm_session.dart';
+
+import '../voice_fakes.dart';
+import 'swarm_fixture.dart';
+
+/// The chat menu's Notifications (the desktop's chat menu, #2453): ⋮ at the
+/// end of a chat's header, its sheet with All new messages, Mentions only
+/// and Muted, the reader's own ticked; a tap keeps it on every device.
+void main() {
+ const chat = 'g1';
+ const notifications =
+ '/api/super-tabs/$tab/conversations/$chat/notifications';
+ const leadNotifications =
+ '/api/super-tabs/$tab/conversations/$leadChat/notifications';
+ const refused = SuperTabFailure(
+ 'FORBIDDEN',
+ 'You cannot read this Swarm.',
+ statusCode: 403,
+ );
+
+ FakeSwarm backend({Map<String, String> settings = const {}}) {
+ final fake = FakeSwarm();
+ final derived = {if (settings.isNotEmpty) 'chatSettings': settings};
+ fake.routes['/api/super-tabs/list'] = (_) => {
+ 'tabs': [
+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},
+ ],
+ 'next': null,
+ };
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => firstLoad(
+ groups: [groupData(chat, title: 'Fix login', number: 7)],
+ derived: derived,
+ );
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>
+ changes(cursor: 'c2', derived: derived);
+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {
+ 'decisions': <Object>[],
+ };
+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {
+ 'mentions': <Object>[],
+ };
+ fake.routes['/api/super-tabs/$tab/conversations/$chat/messages'] = (_) => {
+ 'messages': <Object>[],
+ 'next': null,
+ };
+ fake.routes['/api/super-tabs/$tab/conversations/$leadChat/messages'] = (
+ _,
+ ) => {'messages': <Object>[], 'next': null};
+ fake.routes[notifications] = (body) => {'notify': body!['notify']};
+ fake.routes[leadNotifications] = (body) => {'notify': body!['notify']};
+ return fake;
+ }
+
+ Future<SwarmHost> pump(
+ WidgetTester tester,
+ FakeSwarm fake, {
+ Widget home = const SwarmConversationPage(
+ swarmId: tab,
+ conversationId: chat,
+ ),
+ }) async {
+ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())
+ ..value = {PhoneExperiment.swarm};
+ final account = ValueNotifier<String?>(me);
+ final host = SwarmHost(
+ accountId: () => account.value,
+ account: account,
+ request: fake.request,
+ upload: refuseSwarmUpload,
+ notices: SilentSystemNotices(),
+ features: features,
+ )..foreground = false;
+ addTearDown(host.dispose);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ builder: (context, child) => SwarmScope(notifier: host, child: child!),
+ home: home,
+ ),
+ );
+ await tester.pumpAndSettle();
+ return host;
+ }
+
+ Finder key(String value) => find.byKey(ValueKey(value));
+
+ /// The level ticked in the open sheet.
+ String? ticked(WidgetTester tester) {
+ for (final level in SwarmNotify.values) {
+ final row = find.ancestor(
+ of: find.text(level.label),
+ matching: find.byType(Row),
+ );
+ if (find
+ .descendant(of: row.first, matching: find.text('✓'))
+ .evaluate()
+ .isNotEmpty) {
+ return level.label;
+ }
+ }
+ return null;
+ }
+
+ Future<void> open(WidgetTester tester) async {
+ await tester.tap(key('swarm-chat-menu'));
+ await tester.pumpAndSettle();
+ }
+
+ List<Map<String, dynamic>?> sent(
+ FakeSwarm fake, {
+ String path = notifications,
+ }) => [
+ for (final call in fake.calls)
+ if (call.path == path) call.body,
+ ];
+
+ testWidgets('⋮ holds Notifications, the setting ticked; Muted is kept on '
+ 'every device and ticked next time', (tester) async {
+ final fake = backend();
+ await pump(tester, fake);
+
+ await open(tester);
+ expect(find.text('notifications'), findsOneWidget);
+ for (final level in SwarmNotify.values) {
+ expect(find.text(level.label), findsOneWidget);
+ }
+ expect(ticked(tester), 'Mentions only');
+
+ await tester.tap(find.text('Muted'));
+ await tester.pumpAndSettle();
+ expect(find.text('notifications'), findsNothing, reason: 'sheet closed');
+ expect(sent(fake), [
+ {'notify': 'muted'},
+ ]);
+ expect(key('swarm-notify-failed'), findsNothing);
+
+ await open(tester);
+ expect(ticked(tester), 'Muted');
+ });
+
+ testWidgets('a setting made on the desktop is the one ticked', (
+ tester,
+ ) async {
+ await pump(tester, backend(settings: {chat: 'all'}));
+
+ await open(tester);
+ expect(ticked(tester), 'All new messages');
+ });
+
+ testWidgets('refused: it says so, and the old setting is ticked again', (
+ tester,
+ ) async {
+ final fake = backend();
+ fake.routes[notifications] = (_) => throw const SuperTabFailure(
+ 'CHAT_SETTING_BUSY',
+ 'Busy',
+ statusCode: 503,
+ );
+ await pump(tester, fake);
+
+ await open(tester);
+ await tester.tap(find.text('All new messages'));
+ await tester.pumpAndSettle();
+ expect(
+ find.text('Could not change notifications. Try again.'),
+ findsOneWidget,
+ );
+
+ await open(tester);
+ expect(ticked(tester), 'Mentions only');
+ });
+
+ testWidgets('access lost while the sheet is open: it closes, and ⋮ goes', (
+ tester,
+ ) async {
+ final fake = backend();
+ final host = await pump(tester, fake);
+ await open(tester);
+ expect(find.text('Muted'), findsOneWidget);
+
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => throw refused;
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => throw refused;
+ unawaited(host.session!.inbox.reader(tab)!.refresh());
+ await tester.pumpAndSettle();
+
+ expect(find.text('Muted'), findsNothing);
+ expect(find.text('Fix login'), findsNothing, reason: 'nothing names it');
+ expect(key('swarm-chat-menu'), findsNothing);
+ });
+
+ testWidgets('access lost while a choice is on its way: its answer shows '
+ 'nothing, no error either', (tester) async {
+ final fake = backend();
+ final answer = Completer<Object?>();
+ fake.routes[notifications] = (_) => answer.future;
+ final host = await pump(tester, fake);
+ await open(tester);
+ await tester.tap(find.text('Muted'));
+ await tester.pumpAndSettle();
+
+ host.session!.inbox.reader(tab)!.revoke();
+ await tester.pumpAndSettle();
+ answer.completeError(Exception('lost'));
+ await tester.pumpAndSettle();
+
+ expect(key('swarm-notify-failed'), findsNothing);
+ expect(key('swarm-chat-menu'), findsNothing);
+ });
+
+ group('the project chat, which opens inside its project page with the '
+ "project's header", () {
+ testWidgets("Swarm Home C: the project's ⋮ has Notifications for its "
+ 'chat; Muted is kept, and access lost closes the sheet', (
+ tester,
+ ) async {
+ final fake = backend();
+ final host = await pump(
+ tester,
+ fake,
+ home: const SwarmProjectPage(
+ swarmId: tab,
+ projectId: project,
+ tabs: SwarmProjectTab.homeC,
+ ),
+ );
+
+ await tester.tap(key('swarm-project-menu'));
+ await tester.pumpAndSettle();
+ await tester.tap(key('swarm-project-menu-notifications'));
+ await tester.pumpAndSettle();
+ expect(ticked(tester), 'Mentions only');
+ await tester.tap(find.text('Muted'));
+ await tester.pumpAndSettle();
+ expect(sent(fake, path: leadNotifications), [
+ {'notify': 'muted'},
+ ]);
+
+ await tester.tap(key('swarm-project-menu'));
+ await tester.pumpAndSettle();
+ await tester.tap(key('swarm-project-menu-notifications'));
+ await tester.pumpAndSettle();
+ expect(ticked(tester), 'Muted');
+
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => throw refused;
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => throw refused;
+ unawaited(host.session!.inbox.reader(tab)!.refresh());
+ await tester.pumpAndSettle();
+ expect(find.text('Muted'), findsNothing);
+ });
+
+ testWidgets("with tabs: ⋮ for the project chat's Notifications while its "
+ 'Chat tab is shown, and not on another tab', (tester) async {
+ final fake = backend();
+ await pump(
+ tester,
+ fake,
+ home: const SwarmProjectPage(
+ swarmId: tab,
+ projectId: project,
+ tabs: SwarmProjectTab.homeB,
+ ),
+ );
+
+ expect(key('swarm-chat-menu'), findsOneWidget);
+ await open(tester);
+ await tester.tap(find.text('All new messages'));
+ await tester.pumpAndSettle();
+ expect(sent(fake, path: leadNotifications), [
+ {'notify': 'all'},
+ ]);
+
+ await tester.tap(key('swarm-project-tab-tasks'));
+ await tester.pumpAndSettle();
+ expect(key('swarm-chat-menu'), findsNothing);
+ });
+ });
+
+ testWidgets('a muted Buddy chat on Buddies: greyed with a crossed bell, '
+ 'no dot', (tester) async {
+ final row = SwarmBuddyRow(
+ swarmId: tab,
+ project: SuperTabProject.fromJson({
+ 'id': project,
+ 'name': 'Mobile',
+ 'ownerId': me,
+ 'leadConversationId': leadChat,
+ 'visibility': 'public',
+ 'members': <Object>[],
+ }),
+ name: 'Wren',
+ muted: true,
+ );
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: SwarmBuddiesRow(
+ row: row,
+ line: 'Done',
+ now: DateTime.utc(2026, 11, 1),
+ onTap: () {},
+ ),
+ ),
+ ),
+ );
+
+ expect(key('swarm-buddies-muted-${row.key}'), findsOneWidget);
+ expect(key('swarm-buddies-unread-${row.key}'), findsNothing);
+ });
+}
diff --git a/mobile/test/swarm/swarm_chat_notices_test.dart b/mobile/test/swarm/swarm_chat_notices_test.dart
new file mode 100644
index 000000000..d7d0befdd
--- /dev/null
+++ b/mobile/test/swarm/swarm_chat_notices_test.dart
@@ -0,0 +1,261 @@
+import 'dart:async';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/notify/system_notices.dart';
+import 'package:harness_mobile/swarm/swarm_chat_notify.dart';
+import 'package:harness_mobile/swarm/swarm_session.dart';
+
+import '../voice_fakes.dart' show MemoryKeyValueStore;
+import 'swarm_fixture.dart';
+
+/// The phone's notices follow each chat's setting as the desktop's do
+/// (#2453): All new messages tells of each new message in a chat the person
+/// is not looking at; Mentions only and Muted tell of none, and a tag is
+/// told whatever the chat's setting, as on the desktop. A notice names the
+/// project only (lock screen, Lead 10-27).
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ late _Notices notices;
+ late _Backend backend;
+
+ setUp(() {
+ notices = _Notices();
+ backend = _Backend();
+ });
+
+ Future<SwarmSession> start({bool disposeAtEnd = true}) async {
+ final session = SwarmSession(
+ accountId: me,
+ request: backend.fake.request,
+ notices: notices,
+ readMarks: MemoryKeyValueStore(),
+ );
+ if (disposeAtEnd) addTearDown(session.dispose);
+ await session.inbox.refresh();
+ await settle();
+ return session;
+ }
+
+ /// The next read of the list and its Swarm.
+ Future<void> poll(SwarmSession session) async {
+ await session.inbox.refresh();
+ await settle();
+ }
+
+ List<String> told() => [for (final n in notices.shown) n.key];
+ const g1Notice = 'chat:$tab:g1';
+
+ test('All new messages: each new message in the chat is told, one notice '
+ 'for the chat that the next replaces, naming the project only', () async {
+ backend.settings = {'g1': 'all'};
+ final session = await start();
+ expect(told(), isEmpty, reason: 'the first look is not news');
+
+ backend.move('g1', 4);
+ await poll(session);
+ expect(told(), [g1Notice]);
+ final notice = notices.shown.single;
+ expect(notice.title, 'New messages');
+ expect(notice.subtitle, 'Mobile');
+ expect(notice.body, 'Open Harness to read them.');
+ expect(notice.target.conversationId, 'g1');
+ expect(
+ '${notice.title} ${notice.subtitle} ${notice.body}',
+ isNot(contains('Fix login')),
+ reason: 'the chat is named in the app only',
+ );
+
+ backend.move('g1', 5);
+ await poll(session);
+ expect(told(), [g1Notice, g1Notice]);
+
+ // Read again with nothing new: nothing told again.
+ backend.version++;
+ await poll(session);
+ expect(told(), hasLength(2));
+ });
+
+ test('Mentions only and Muted tell of no new message; a tag is told in '
+ 'either, as on the desktop', () async {
+ backend.settings = {'g2': 'muted'};
+ final session = await start();
+
+ backend
+ ..move('g1', 4)
+ ..move('g2', 4)
+ ..mention('t1', 'g2');
+ await poll(session);
+
+ expect(told(), ['mention:t1']);
+ });
+
+ test('chosen on this phone, it tells at once: before any read carries the '
+ 'setting', () async {
+ final session = await start();
+ backend.fake.routes['/api/super-tabs/$tab/conversations/g1/'
+ 'notifications'] = (_) =>
+ Completer<Object?>().future;
+ unawaited(session.inbox.reader(tab)!.setNotify('g1', SwarmNotify.all));
+
+ backend.move('g1', 4);
+ await poll(session);
+ expect(told(), [g1Notice]);
+ });
+
+ test('nothing is told while a Swarm screen is up', () async {
+ backend.settings = {'g1': 'all'};
+ final session = await start();
+ session.enter();
+
+ backend.move('g1', 4);
+ await poll(session);
+ expect(told(), isEmpty);
+ });
+
+ test('a message already read on the phone is not news', () async {
+ backend.settings = {'g1': 'all'};
+ final session = await start();
+ session.inbox.reader(tab)!.readMarks!.markRead('g1', 4);
+
+ backend.move('g1', 4);
+ await poll(session);
+ expect(told(), isEmpty);
+ });
+
+ test('its notice goes once the chat is read, or the Swarm can no longer be '
+ 'read', () async {
+ backend.settings = {'g1': 'all', 'g2': 'all'};
+ final session = await start();
+ backend
+ ..move('g1', 4)
+ ..move('g2', 4);
+ await poll(session);
+ expect(told(), [g1Notice, 'chat:$tab:g2']);
+
+ session.inbox.reader(tab)!.readMarks!.markRead('g1', 4);
+ backend.version++;
+ await poll(session);
+ expect(notices.cancelled, [g1Notice]);
+
+ backend.gone = true;
+ await poll(session);
+ expect(notices.cancelled, [g1Notice, 'chat:$tab:g2']);
+ });
+
+ test('signed out or Swarm turned off: every chat notice goes', () async {
+ backend.settings = {'g1': 'all'};
+ final session = await start(disposeAtEnd: false);
+ backend.move('g1', 4);
+ await poll(session);
+ expect(told(), [g1Notice]);
+
+ session.dispose();
+ expect(notices.cancelled, contains(g1Notice));
+ });
+
+ test('a Swarm read again from nothing starts over: what it holds then is '
+ 'not news', () async {
+ backend.settings = {'g1': 'all'};
+ final session = await start();
+
+ backend
+ ..reload = true
+ ..move('g1', 4);
+ await poll(session);
+ expect(told(), isEmpty);
+ });
+}
+
+class _Notices extends SilentSystemNotices {
+ final shown = <SwarmNoticeMessage>[];
+ final cancelled = <String>[];
+
+ @override
+ Future<void> showSwarm(SwarmNoticeMessage message) async =>
+ shown.add(message);
+
+ @override
+ Future<void> cancelSwarm(String key) async => cancelled.add(key);
+}
+
+/// Swarm [tab] with work g1 and g2 in Mobile; each [move] moves one on and
+/// the Swarm's last change with it, so the next poll reads it.
+class _Backend {
+ final fake = FakeSwarm();
+ var settings = <String, String>{};
+ final sequences = <String, int>{'g1': 3, 'g2': 3};
+ final mentions = <Map<String, dynamic>>[];
+ var version = 2;
+ var reload = false;
+
+ /// The account no longer reads the Swarm: off the list.
+ var gone = false;
+
+ List<Map<String, dynamic>> get groups => [
+ for (final MapEntry(:key, :value) in sequences.entries)
+ groupData(
+ key,
+ title: key == 'g1' ? 'Fix login' : 'Ship it',
+ lastMessageSequence: value,
+ ),
+ ];
+
+ Map<String, dynamic> get derived => {
+ 'mentionsWaiting': mentions.length,
+ 'chatSettings': settings,
+ };
+
+ _Backend() {
+ fake.routes['/api/super-tabs/list'] = (_) => {
+ 'tabs': [
+ if (!gone)
+ {
+ 'id': tab,
+ 'name': 'Phone Swarm',
+ 'ownerId': me,
+ 'lastChangedAt': version,
+ },
+ ],
+ 'next': null,
+ };
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) {
+ reload = false;
+ return firstLoad(
+ groups: groups,
+ derived: derived,
+ lastChangedAt: version,
+ );
+ };
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => reload
+ ? {'reload': true}
+ : changes(
+ cursor: 'c$version',
+ derived: derived,
+ lastChangedAt: version,
+ groups: [
+ for (final g in groups) part(g['id'] as String, version, g),
+ ],
+ );
+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {
+ 'decisions': <Object>[],
+ };
+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {
+ 'mentions': mentions,
+ };
+ }
+
+ void move(String id, int sequence) {
+ sequences[id] = sequence;
+ version++;
+ }
+
+ void mention(String id, String conversationId) => mentions.add({
+ 'id': id,
+ 'conversationId': conversationId,
+ 'messageId': 'm-$id',
+ 'projectId': project,
+ 'projectName': 'Mobile',
+ 'leadName': 'River',
+ });
+}
diff --git a/mobile/test/swarm/swarm_chat_notify_test.dart b/mobile/test/swarm/swarm_chat_notify_test.dart
new file mode 100644
index 000000000..a49167b3f
--- /dev/null
+++ b/mobile/test/swarm/swarm_chat_notify_test.dart
@@ -0,0 +1,350 @@
+import 'dart:async';
+
+import 'package:flutter_test/flutter_test.dart';
+
+import 'package:harness_mobile/swarm/swarm_asks.dart';
+import 'package:harness_mobile/swarm/swarm_chat_notify.dart';
+import 'package:harness_mobile/swarm/swarm_read_marks.dart';
+import 'package:harness_mobile/swarm/swarm_reader.dart';
+import 'package:harness_mobile/swarm/swarm_request.dart';
+import 'package:harness_mobile/swarm/swarm_threads.dart';
+import 'package:harness_mobile/swarm/swarm_unread.dart';
+
+import 'swarm_fixture.dart';
+
+/// Each person's notification setting per chat (the desktop's #2453, Slack's
+/// channel notifications): All new messages, Mentions only (the default) or
+/// Muted, set from the phone through the desktop's own call, and followed at
+/// once by every count on the phone.
+void main() {
+ const notifications = '/api/super-tabs/$tab/conversations/g1/notifications';
+
+ Map<String, dynamic> tag(
+ String id, {
+ String conversationId = 'g1',
+ String? threadId,
+ int? messageSequence,
+ }) => {
+ 'id': id,
+ 'threadId': ?threadId,
+ 'messageSequence': ?messageSequence,
+ 'projectId': project,
+ 'projectName': 'Mobile',
+ 'conversationId': conversationId,
+ 'conversationTitle': 'Fix login',
+ 'messageId': 'msg-$id',
+ 'leadName': 'River',
+ 'text': 'Look',
+ 'createdAt': '2026-10-27T01:00:00.000Z',
+ };
+
+ /// Swarm [tab] with work g1 and g2, read once: [settings] are the reader's
+ /// own settings, [tags] wait. Its next change read answers [next] (the
+ /// settings it carries, by chat), and moves g1 on to [g1Sequence].
+ late Map<String, dynamic> next;
+ Future<({FakeSwarm swarm, SwarmReader reader, SwarmAsks asks})> rig({
+ Map<String, String> settings = const {},
+ List<Map<String, dynamic>> tags = const [],
+ }) async {
+ final swarm = FakeSwarm();
+ next = {};
+ final derived = {
+ 'mentionsWaiting': tags.length,
+ if (settings.isNotEmpty) 'chatSettings': settings,
+ };
+ swarm.routes['/api/super-tabs/$tab/parts'] = (_) => firstLoad(
+ groups: [
+ groupData('g1', title: 'Fix login', lastMessageSequence: 3),
+ groupData('g2', title: 'Ship it', lastMessageSequence: 1),
+ ],
+ derived: derived,
+ );
+ swarm.routes['/api/super-tabs/$tab/changes'] = (_) =>
+ changes(cursor: 'c2', derived: {...derived, 'chatSettings': next});
+ swarm.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {
+ 'mentions': tags,
+ };
+ swarm.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {
+ 'decisions': <Object>[],
+ };
+ final reader = SwarmReader(
+ tabId: tab,
+ accountId: me,
+ request: swarm.request,
+ );
+ final marks = reader.readMarks = SwarmReadMarks(reader, store: null);
+ final asks = SwarmAsks(reader);
+ addTearDown(() {
+ asks.dispose();
+ marks.dispose();
+ reader.dispose();
+ });
+ await reader.refresh();
+ await settle();
+ return (swarm: swarm, reader: reader, asks: asks);
+ }
+
+ /// The setting route answers each choice when the test completes it.
+ List<({Map<String, dynamic> body, Completer<Object?> answer})> hold(
+ FakeSwarm swarm, {
+ String chat = 'g1',
+ }) {
+ final held = <({Map<String, dynamic> body, Completer<Object?> answer})>[];
+ swarm.routes['/api/super-tabs/$tab/conversations/$chat/notifications'] =
+ (body) {
+ final answer = Completer<Object?>();
+ held.add((body: body!, answer: answer));
+ return answer.future;
+ };
+ return held;
+ }
+
+ group('the setting', () {
+ test('is Mentions only until the server says otherwise; its word for '
+ 'each, and nothing it does not know', () async {
+ final r = await rig(settings: {'g2': 'all'});
+
+ expect(r.reader.notifyOf('g1'), SwarmNotify.mentions);
+ expect(r.reader.notifyOf('g2'), SwarmNotify.all);
+ expect(SwarmNotify.parse('loud'), SwarmNotify.mentions);
+ expect(
+ [for (final n in SwarmNotify.values) n.label],
+ ['All new messages', 'Mentions only', 'Muted'],
+ );
+ });
+
+ test('a choice shows at once and is sent through the desktop\'s call; '
+ 'kept, it stays until a read carries it', () async {
+ final r = await rig();
+ final held = hold(r.swarm);
+
+ final saved = r.reader.setNotify('g1', SwarmNotify.muted);
+ expect(r.reader.notifyOf('g1'), SwarmNotify.muted);
+ expect(r.swarm.calls.last.method, 'POST');
+ expect(r.swarm.calls.last.path, notifications);
+ expect(held.single.body, {'notify': 'muted'});
+
+ held.single.answer.complete({'notify': 'muted'});
+ expect(await saved, isTrue);
+ expect(
+ r.reader.snapshot!.chatSettings['g1'],
+ isNull,
+ reason: 'no read since',
+ );
+ expect(r.reader.notifyOf('g1'), SwarmNotify.muted);
+
+ next = {'g1': 'muted'};
+ await r.reader.refresh();
+ expect(r.reader.notifyOf('g1'), SwarmNotify.muted);
+ // Changed on the desktop since: the read's word now.
+ next = {'g1': 'all'};
+ await r.reader.refresh();
+ expect(r.reader.notifyOf('g1'), SwarmNotify.all);
+ });
+
+ test('a read begun before the answer does not flick it back', () async {
+ final r = await rig();
+ final held = hold(r.swarm);
+ final gate = Completer<void>();
+ r.swarm.routes['/api/super-tabs/$tab/changes'] = (_) async {
+ await gate.future;
+ return changes(cursor: 'c2');
+ };
+
+ final reading = r.reader.refresh();
+ final saved = r.reader.setNotify('g1', SwarmNotify.all);
+ held.single.answer.complete({'notify': 'all'});
+ expect(await saved, isTrue);
+ gate.complete();
+ await reading;
+
+ expect(r.reader.notifyOf('g1'), SwarmNotify.all);
+ });
+
+ test('refused, or not answered as asked: the old setting is back, and it '
+ 'says so', () async {
+ final r = await rig(settings: {'g1': 'all'});
+ final held = hold(r.swarm);
+
+ final refused = r.reader.setNotify('g1', SwarmNotify.muted);
+ held.single.answer.completeError(
+ const SuperTabFailure('CHAT_SETTING_BUSY', 'Busy', statusCode: 503),
+ );
+ expect(await refused, isFalse);
+ expect(r.reader.notifyOf('g1'), SwarmNotify.all);
+
+ final odd = r.reader.setNotify('g1', SwarmNotify.muted);
+ held.last.answer.complete({'notify': 'mentions'});
+ expect(await odd, isFalse);
+ expect(r.reader.notifyOf('g1'), SwarmNotify.all);
+ });
+
+ test('a later choice for the same chat wins over one still on its way, '
+ 'whichever answers first', () async {
+ final r = await rig();
+ final held = hold(r.swarm);
+
+ final first = r.reader.setNotify('g1', SwarmNotify.muted);
+ final second = r.reader.setNotify('g1', SwarmNotify.all);
+ held[1].answer.complete({'notify': 'all'});
+ expect(await second, isTrue);
+ held[0].answer.completeError(Exception('lost'));
+ expect(await first, isTrue, reason: 'nothing to say: overtaken');
+
+ expect(r.reader.notifyOf('g1'), SwarmNotify.all);
+ });
+
+ test('choices for two chats at once each settle on their own', () async {
+ final r = await rig();
+ final one = hold(r.swarm);
+ final two = hold(r.swarm, chat: 'g2');
+
+ final g1 = r.reader.setNotify('g1', SwarmNotify.muted);
+ final g2 = r.reader.setNotify('g2', SwarmNotify.all);
+ two.single.answer.complete({'notify': 'all'});
+ expect(await g2, isTrue);
+ one.single.answer.completeError(Exception('lost'));
+ expect(await g1, isFalse);
+
+ expect(r.reader.notifyOf('g1'), SwarmNotify.mentions);
+ expect(r.reader.notifyOf('g2'), SwarmNotify.all);
+ });
+
+ test('access lost while a choice is on its way: nothing of it stays, '
+ 'and its answer changes nothing', () async {
+ final r = await rig();
+ final held = hold(r.swarm);
+ final saved = r.reader.setNotify('g1', SwarmNotify.muted);
+
+ r.reader.revoke();
+ expect(r.reader.notifyOf('g1'), SwarmNotify.mentions);
+ var told = 0;
+ r.reader.addListener(() => told++);
+ held.single.answer.complete({'notify': 'muted'});
+
+ expect(await saved, isTrue, reason: 'no error once access is gone');
+ expect(r.reader.notifyOf('g1'), SwarmNotify.mentions);
+ expect(told, 0);
+ });
+
+ test(
+ 'a chat the reader does not read — another project\'s, a private '
+ 'or Buddy chat not theirs, or none — is refused alike, unasked',
+ () async {
+ final r = await rig();
+ final before = r.swarm.calls.length;
+
+ for (final id in ['other-project-chat', 'buddy-ann', '']) {
+ expect(await r.reader.setNotify(id, SwarmNotify.muted), isFalse);
+ expect(r.reader.notifyOf(id), SwarmNotify.mentions);
+ }
+ expect(r.swarm.calls, hasLength(before));
+ },
+ );
+
+ test(
+ 'a first read that failed and later recovers can still set it',
+ () async {
+ final swarm = FakeSwarm();
+ var fail = true;
+ swarm.routes['/api/super-tabs/$tab/parts'] = (_) {
+ if (fail) throw Exception('offline');
+ return firstLoad(groups: [groupData('g1')]);
+ };
+ final reader = SwarmReader(
+ tabId: tab,
+ accountId: me,
+ request: swarm.request,
+ );
+ addTearDown(reader.dispose);
+ await reader.refresh();
+ expect(await reader.setNotify('g1', SwarmNotify.muted), isFalse);
+ expect(reader.loading, isFalse, reason: 'no stuck Loading');
+
+ fail = false;
+ await reader.refresh();
+ final held = hold(swarm);
+ final saved = reader.setNotify('g1', SwarmNotify.muted);
+ held.single.answer.complete({'notify': 'muted'});
+ expect(await saved, isTrue);
+ expect(reader.notifyOf('g1'), SwarmNotify.muted);
+ },
+ );
+
+ test('a chat id reused in another Swarm keeps its own setting', () async {
+ final r = await rig(settings: {'g1': 'muted'});
+ final swarm = FakeSwarm();
+ swarm.routes['/api/super-tabs/tab-2/parts'] = (_) =>
+ firstLoad(tabId: 'tab-2', groups: [groupData('g1')]);
+ final other = SwarmReader(
+ tabId: 'tab-2',
+ accountId: me,
+ request: swarm.request,
+ );
+ addTearDown(other.dispose);
+ await other.refresh();
+
+ expect(r.reader.notifyOf('g1'), SwarmNotify.muted);
+ expect(other.notifyOf('g1'), SwarmNotify.mentions);
+ });
+ });
+
+ group('counts follow the choice made on the phone at once', () {
+ /// g1 moved on past what was read, with a tag waiting in it.
+ Future<({FakeSwarm swarm, SwarmReader reader, SwarmAsks asks})>
+ unreadAndTagged() async {
+ final r = await rig(tags: [tag('t1', messageSequence: 4)]);
+ r.swarm.routes['/api/super-tabs/$tab/changes'] = (_) => changes(
+ cursor: 'c3',
+ groups: [
+ part(
+ 'g1',
+ 20,
+ groupData('g1', title: 'Fix login', lastMessageSequence: 4),
+ ),
+ ],
+ );
+ await r.reader.refresh();
+ await settle();
+ return r;
+ }
+
+ SwarmRowNews news(
+ ({FakeSwarm swarm, SwarmReader reader, SwarmAsks asks}) r,
+ ) =>
+ swarmChatNews(r.reader, r.asks, r.reader.snapshot!.conversation('g1')!);
+
+ test('muted while the answer is on its way: no bold, no count, on the '
+ 'chat and its project; back as it was when refused', () async {
+ final r = await unreadAndTagged();
+ expect(news(r), (bold: true, tags: 1));
+ expect(swarmProjectNews(r.reader, r.asks), {
+ project: (bold: true, tags: 1),
+ });
+
+ final held = hold(r.swarm);
+ final saved = r.reader.setNotify('g1', SwarmNotify.muted);
+ expect(news(r), (bold: false, tags: 0));
+ expect(swarmProjectNews(r.reader, r.asks), isEmpty);
+ expect(r.asks.mentions, hasLength(1), reason: 'still in Activity');
+
+ held.single.answer.completeError(Exception('lost'));
+ await saved;
+ expect(news(r), (bold: true, tags: 1));
+ });
+
+ test('a muted chat\'s threads stop counting at once too', () async {
+ final r = await rig(
+ tags: [tag('t1', threadId: 'm1', messageSequence: 2)],
+ );
+ final threads = SwarmThreads(r.reader, asks: r.asks);
+ addTearDown(threads.dispose);
+ await settle();
+ expect(threads.threadMentions, 1);
+
+ hold(r.swarm);
+ unawaited(r.reader.setNotify('g1', SwarmNotify.muted));
+ expect(threads.threadMentions, 0);
+ });
+ });
+}