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: unread filter and Mark all read with Undo on Home, as Desktop (Tony, task 8c) (#2474)

0xken159faedf318de1
diff --git a/mobile/lib/swarm/swarm_home_list.dart b/mobile/lib/swarm/swarm_home_list.dart
index 4963a080e..eb1e10051 100644
--- a/mobile/lib/swarm/swarm_home_list.dart
+++ b/mobile/lib/swarm/swarm_home_list.dart
@@ -81,6 +81,18 @@ SwarmHomeLists swarmHomeLists(
return (pinned: newest(pinned), recent: newest(recent), quiet: newest(quiet));
}
+/// [lists] under Home's unread filter (`SwarmHomePrefs.unreadOnly`, the
+/// desktop's `_hasUnread`): only the projects with something new in them,
+/// bold or tags waiting, pinned ones too. None of them was folded.
+SwarmHomeLists swarmHomeUnreadOnly(SwarmHomeLists lists) {
+ bool news(SwarmHomeProject p) => p.news.bold || p.news.tags > 0;
+ return (
+ pinned: lists.pinned.where(news).toList(),
+ recent: lists.recent.where(news).toList(),
+ quiet: lists.quiet.where(news).toList(),
+ );
+}
+
/// When each project of [snapshot] last moved: the newest change of its
/// chats ([SuperTabConversation.changedAt]), its project chat and its work
/// alike, closed work too. Not the person's Buddy chat ([buddies]) or a
diff --git a/mobile/lib/swarm/swarm_home_prefs.dart b/mobile/lib/swarm/swarm_home_prefs.dart
index 7feac4357..c63508cc9 100644
--- a/mobile/lib/swarm/swarm_home_prefs.dart
+++ b/mobile/lib/swarm/swarm_home_prefs.dart
@@ -7,9 +7,10 @@ import '../core/local_key_value_store.dart';
import 'swarm_home_list.dart';
/// What the person chose for Swarm Home on this phone (Tony, 2026-10-29):
-/// the projects pinned at its top ([pins]), and the one Swarm it shows
-/// ([swarmId]; none shows them all); and when they last left the app
-/// ([seenAt]), what While you were away counts from; and the projects whose
+/// the projects pinned at its top ([pins]), the one Swarm it shows
+/// ([swarmId]; none shows them all) and its unread filter ([unreadOnly]);
+/// and when they last left the app ([seenAt]), what While you were away
+/// counts from; and the projects whose
/// status card is folded ([folded]), as the desktop keeps it on its computer.
/// Neither the server nor the desktop has pins, so they stay on this phone,
/// under the account ([store]): ids and a time only, nothing read of a Swarm,
@@ -47,6 +48,12 @@ class SwarmHomePrefs extends ChangeNotifier {
String? get swarmId => _swarmId;
String? _swarmId;
+ /// Home lists only the projects with something unread or a tag waiting
+ /// (the desktop's unread filter, `SuperTabController.unreadOnly`), kept on
+ /// this phone as the desktop keeps it on its computer.
+ bool get unreadOnly => _unreadOnly;
+ bool _unreadOnly = false;
+
/// When the person last left the app ([seen]); null before, as on a new
/// phone.
DateTime? get seenAt => _seenAt;
@@ -60,7 +67,7 @@ class SwarmHomePrefs extends ChangeNotifier {
/// unfolded meanwhile, which what is read does not bring back, and whether
/// a Swarm was chosen to show, which stands over the one read.
final _unpinned = <String>{}, _unfolded = <String>{};
- bool _shownChosen = false;
+ bool _shownChosen = false, _unreadChosen = false;
/// The account's Swarms, as [keepOnly] last heard them; null before. What
/// is read back is held to them too.
@@ -122,6 +129,13 @@ class SwarmHomePrefs extends ChangeNotifier {
_changed();
}
+ /// Turns the unread filter on or off ([unreadOnly]).
+ void toggleUnreadOnly() {
+ if (!_loaded) _unreadChosen = true;
+ _unreadOnly = !_unreadOnly;
+ _changed();
+ }
+
/// The person leaves the app at [at]: kept, the later time standing over
/// an earlier one, and written. Home does not draw it, so it tells no
/// one.
@@ -183,8 +197,8 @@ class SwarmHomePrefs extends ChangeNotifier {
}
if (_disposed) return;
_loaded = true;
- final (pins, folds, swarmId, seenAt) = text == null
- ? (const <String>[], const <String>[], null, null)
+ final (pins, folds, swarmId, seenAt, unreadOnly) = text == null
+ ? (const <String>[], const <String>[], null, null, false)
: _decode(text);
// Chosen meanwhile: the pins pinned and cards folded join those read,
// oldest first, those taken off or opened stay so, and a Swarm chosen
@@ -200,6 +214,7 @@ class SwarmHomePrefs extends ChangeNotifier {
merge(_pins, pins, _unpinned);
merge(_folds, folds, _unfolded);
if (!_shownChosen) _swarmId = swarmId;
+ if (!_unreadChosen) _unreadOnly = unreadOnly;
// Left meanwhile: the later time stands.
if (seenAt != null && seenAt.isAfter(_seenAt ?? DateTime(0))) {
_seenAt = seenAt;
@@ -213,15 +228,18 @@ class SwarmHomePrefs extends ChangeNotifier {
notifyListeners();
}
- /// What was kept: written before folds were, it has none.
- static (List<String>, List<String>, String?, DateTime?) _decode(String text) {
+ /// What was kept: written before folds were, it has none; before the
+ /// unread filter, it is off.
+ static (List<String>, List<String>, String?, DateTime?, bool) _decode(
+ String text,
+ ) {
List<String> keys(Object? list) => [
for (final key in list is List ? list : const [])
if (key is String && key.contains('/')) key,
];
try {
final json = jsonDecode(text);
- if (json is! Map) return (const [], const [], null, null);
+ if (json is! Map) return (const [], const [], null, null, false);
return (
keys(json['pins']),
keys(json['folded']),
@@ -230,9 +248,10 @@ class SwarmHomePrefs extends ChangeNotifier {
final int ms when ms > 0 => DateTime.fromMillisecondsSinceEpoch(ms),
_ => null,
},
+ json['unread'] == true,
);
} on FormatException {
- return (const [], const [], null, null);
+ return (const [], const [], null, null, false);
}
}
@@ -243,7 +262,8 @@ class SwarmHomePrefs extends ChangeNotifier {
if (_pins.isEmpty &&
_folds.isEmpty &&
_swarmId == null &&
- _seenAt == null) {
+ _seenAt == null &&
+ !_unreadOnly) {
await store.delete(_key);
} else {
await store.write(
@@ -253,6 +273,7 @@ class SwarmHomePrefs extends ChangeNotifier {
if (_folds.isNotEmpty) 'folded': [..._folds],
'swarm': ?_swarmId,
'seen': ?_seenAt?.millisecondsSinceEpoch,
+ if (_unreadOnly) 'unread': true,
}),
);
}
diff --git a/mobile/lib/swarm/swarm_mark_all.dart b/mobile/lib/swarm/swarm_mark_all.dart
new file mode 100644
index 000000000..8f283e4de
--- /dev/null
+++ b/mobile/lib/swarm/swarm_mark_all.dart
@@ -0,0 +1,100 @@
+import 'dart:async';
+
+import 'model.dart';
+import 'swarm_reader.dart';
+import 'swarm_read_marks.dart';
+
+/// How long Mark all read waits before its marks go to the server, as the
+/// desktop's `SuperTabController.markAllHold`: read marks never move back
+/// there, so Undo works by not sending them yet.
+const swarmMarkAllHold = Duration(seconds: 6);
+
+/// One Mark all read waiting for its Undo, over the Swarms Home shows (the
+/// desktop's `SuperTabMarkAll`): every chat it marked reads as read on this
+/// phone at once ([SwarmReadMarks.holdAllRead]); the marks go to the server
+/// once [hold] passes, or at once when the app leaves the screen or closes
+/// ([commit]); [undo] within it puts every chat back and sends nothing. A
+/// Swarm whose access is lost meanwhile sends nothing ([SwarmReadMarks]
+/// drops what it holds).
+class SwarmMarkAll {
+ SwarmMarkAll._(this._parts, Duration hold, this._onDone)
+ : count = _parts.fold(0, (n, part) => n + part.$2.length) {
+ _timer = Timer(hold, commit);
+ }
+
+ /// Marks every chat shown unread in [marks] read, held for [hold]; null
+ /// when nothing is unread. [onDone] runs once it is sent, undone or
+ /// dropped.
+ static SwarmMarkAll? start(
+ Iterable<SwarmReadMarks> marks, {
+ Duration hold = swarmMarkAllHold,
+ void Function()? onDone,
+ }) {
+ final parts = [
+ for (final m in marks)
+ if (m.holdAllRead() case final through when through.isNotEmpty)
+ (m, through),
+ ];
+ if (parts.isEmpty) return null;
+ return SwarmMarkAll._(parts, hold, onDone);
+ }
+
+ /// How many chats it marked read.
+ final int count;
+ final List<(SwarmReadMarks, Map<String, int>)> _parts;
+ final void Function()? _onDone;
+ late final Timer _timer;
+ bool _done = false;
+
+ /// Whether its marks were sent, or it was undone.
+ bool get done => _done;
+
+ /// Completes once it is sent (true) or undone (false), in the same step:
+ /// whatever waits on it — its toast closing — happens before anything
+ /// that follows, such as a second Mark all read's toast.
+ Future<bool> get settled => _settled.future;
+ final _settled = Completer<bool>.sync();
+
+ /// Puts every chat it marked back as it was, if the marks are not sent.
+ void undo() {
+ if (!_finish(sent: false)) return;
+ for (final (marks, through) in _parts) {
+ marks.dropHeld(through);
+ }
+ }
+
+ /// Sends the marks now: the Undo window is over, or the app leaves.
+ void commit() {
+ if (!_finish(sent: true)) return;
+ for (final (marks, through) in _parts) {
+ marks.sendHeld(through);
+ }
+ }
+
+ bool _finish({required bool sent}) {
+ if (_done) return false;
+ _done = true;
+ _timer.cancel();
+ _settled.complete(sent);
+ _onDone?.call();
+ return true;
+ }
+}
+
+/// Whether Mark all read has anything to mark in [readers]: a chat shown
+/// unread that is not dormant or muted ([SwarmReadMarks.holdAllRead]).
+bool swarmAnyUnread(Iterable<SwarmReader> readers) {
+ for (final reader in readers) {
+ final snapshot = reader.snapshot;
+ final marks = reader.readMarks;
+ if (reader.accessRevoked || snapshot == null || marks == null) continue;
+ for (final SuperTabConversation group in snapshot.conversations) {
+ if (!group.dormant &&
+ snapshot.chatSettings[group.id] != 'muted' &&
+ marks.unread(group)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
diff --git a/mobile/lib/swarm/swarm_page.dart b/mobile/lib/swarm/swarm_page.dart
index b858888a1..cf1dab6ad 100644
--- a/mobile/lib/swarm/swarm_page.dart
+++ b/mobile/lib/swarm/swarm_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/logging/app_log.dart';
import 'package:harness_mobile/phone/out_of_sight.dart';
@@ -18,6 +19,7 @@ import 'swarm_home_rows.dart';
import 'swarm_home_top.dart';
import 'swarm_inbox.dart';
import 'swarm_leaderboard.dart' show swarmProjectPeople;
+import 'swarm_mark_all.dart';
import 'swarm_needs_page.dart';
import 'swarm_new_message_sheet.dart';
import 'swarm_new_project_sheet.dart';
@@ -342,6 +344,9 @@ class _SwarmPageState extends State<SwarmPage> {
swarmStartView(context, session) == null;
return SwarmTabHeader(
title,
+ trailing: listing || session.inbox.swarms.isEmpty
+ ? null
+ : _attention(context, session, shown),
loading: listing,
leading: listing
? _loadingTile
@@ -355,6 +360,66 @@ class _SwarmPageState extends State<SwarmPage> {
);
}
+ /// The unread filter and Mark all read, at the end of the top bar (the
+ /// desktop's, on its Projects heading): the filter lit while on; Mark all
+ /// read greyed with nothing unread in the Swarms [shown].
+ Widget _attention(
+ BuildContext context,
+ SwarmSession session,
+ List<SwarmListing> shown,
+ ) {
+ final home = session.home;
+ final unread = swarmAnyUnread([
+ for (final swarm in shown) ?session.inbox.reader(swarm.id),
+ ]);
+ return Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SwarmIconButton(
+ key: const ValueKey('swarm-unread-only'),
+ icon: LucideIcons.listFilter300,
+ label: home.unreadOnly
+ ? 'Show all projects'
+ : 'Show unread projects only',
+ selected: home.unreadOnly,
+ onPressed: home.toggleUnreadOnly,
+ ),
+ SwarmIconButton(
+ key: const ValueKey('swarm-mark-all-read'),
+ icon: LucideIcons.checkCheck300,
+ label: 'Mark all read',
+ onPressed: unread
+ ? () => _markAllRead(context, session, shown)
+ : null,
+ ),
+ ],
+ );
+ }
+
+ /// Mark all read over the Swarms [shown]: every chat read on this phone at
+ /// once, with an Undo while the marks wait to be sent.
+ void _markAllRead(
+ BuildContext context,
+ SwarmSession session,
+ List<SwarmListing> shown,
+ ) {
+ final held = session.markAllRead([for (final swarm in shown) swarm.id]);
+ if (held == null) return;
+ ScaffoldMessenger.maybeOf(context)
+ ?..hideCurrentSnackBar()
+ ..showSnackBar(
+ SnackBar(
+ key: const ValueKey('swarm-mark-all-toast'),
+ duration: session.markAllHold,
+ // With its Undo it would stay until dismissed; it goes with the
+ // marks ([SwarmMarkAllToast]), and after its time as a backstop.
+ persist: false,
+ content: SwarmMarkAllToast(held),
+ action: SnackBarAction(label: 'Undo', onPressed: held.undo),
+ ),
+ );
+ }
+
/// The Swarms Home shows: the one the switcher picked while it is listed
/// and its read not taken away, else all of them.
List<SwarmListing> _shown(SwarmSession session) {
@@ -536,7 +601,16 @@ class _SwarmPageState extends State<SwarmPage> {
reading.add(swarm.id);
}
}
- final lists = swarmHomeLists(projects, pins: session.home.pins, now: now);
+ final all = swarmHomeLists(projects, pins: session.home.pins, now: now);
+ final unreadOnly = session.home.unreadOnly;
+ final lists = unreadOnly ? swarmHomeUnreadOnly(all) : all;
+ // The filter on with nothing to list: it says so, and offers them all.
+ final nothingUnread =
+ unreadOnly &&
+ projects.isNotEmpty &&
+ lists.pinned.isEmpty &&
+ lists.recent.isEmpty &&
+ lists.quiet.isEmpty;
Widget row(SwarmHomeProject project) => SwarmHomeProjectRow(
key: ValueKey('swarm-project-${project.swarmId}-${project.project.id}'),
project: project,
@@ -565,11 +639,25 @@ class _SwarmPageState extends State<SwarmPage> {
if (lists.recent.isNotEmpty ||
quiet.isNotEmpty ||
empty ||
+ nothingUnread ||
create != null) ...[
SwarmCaption('Projects', first: first && lists.pinned.isEmpty),
SwarmGroup(
children: [
if (empty) const SwarmRow(title: 'No project yet', onTap: null),
+ if (nothingUnread) ...[
+ const SwarmRow(
+ key: ValueKey('swarm-unread-none'),
+ title: 'Nothing unread.',
+ onTap: null,
+ ),
+ SwarmRow(
+ key: const ValueKey('swarm-unread-show-all'),
+ title: 'Show all',
+ chevron: null,
+ onTap: session.home.toggleUnreadOnly,
+ ),
+ ],
for (final p in lists.recent) row(p),
if (quiet.isNotEmpty) ...[
SwarmOtherProjectsRow(
@@ -700,3 +788,38 @@ class _Unavailable extends StatelessWidget {
],
);
}
+
+/// What Mark all read's toast says: how many chats it marked read. Once the
+/// marks are sent — after the Undo window, or before it ends when the app
+/// left the screen or closed, the account changed or a second Mark all read
+/// began — it closes the toast in that same step: its Undo can do nothing
+/// more. Built only while its toast is the one shown, and closing before the
+/// next toast is shown, so it never closes another. Undo closes it itself.
+class SwarmMarkAllToast extends StatefulWidget {
+ const SwarmMarkAllToast(this.held, {super.key});
+
+ final SwarmMarkAll held;
+
+ @override
+ State<SwarmMarkAllToast> createState() => _SwarmMarkAllToastState();
+}
+
+class _SwarmMarkAllToastState extends State<SwarmMarkAllToast> {
+ @override
+ void initState() {
+ super.initState();
+ unawaited(
+ widget.held.settled.then((sent) {
+ if (sent && mounted) {
+ ScaffoldMessenger.maybeOf(context)?.hideCurrentSnackBar();
+ }
+ }),
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final count = widget.held.count;
+ return Text(count == 1 ? 'Marked 1 chat read' : 'Marked $count chats read');
+ }
+}
diff --git a/mobile/lib/swarm/swarm_read_marks.dart b/mobile/lib/swarm/swarm_read_marks.dart
index 005745181..3e53a0805 100644
--- a/mobile/lib/swarm/swarm_read_marks.dart
+++ b/mobile/lib/swarm/swarm_read_marks.dart
@@ -162,6 +162,12 @@ class SwarmReadMarks extends ChangeNotifier {
/// The phone's own thread marks, by chat then thread root.
final _threads = <String, Map<String, int>>{};
+ /// Marks a Mark all read shows on this phone only, by chat, while its
+ /// Undo waits ([holdAllRead]): read marks never move back on the server,
+ /// so Undo works by not sending them yet. Never kept on the phone; access
+ /// lost drops them unsent.
+ final _held = <String, int>{};
+
/// The marks were read back from the phone (or there is no store).
bool _loaded = false;
@@ -182,7 +188,8 @@ class SwarmReadMarks extends ChangeNotifier {
bool unread(SuperTabConversation group) {
if (!_loaded || !_started) return false;
final server = reader.snapshot?.readMarks[group.id] ?? 0;
- return group.mainSequence > max(server, _marks[group.id] ?? 0);
+ return group.mainSequence >
+ max(server, max(_marks[group.id] ?? 0, _held[group.id] ?? 0));
}
/// How far the person has read [conversationId]: the higher of the
@@ -191,7 +198,7 @@ class SwarmReadMarks extends ChangeNotifier {
int? readThrough(String conversationId) => _loaded && !reader.accessRevoked
? max(
reader.snapshot?.readMarks[conversationId] ?? 0,
- _marks[conversationId] ?? 0,
+ max(_marks[conversationId] ?? 0, _held[conversationId] ?? 0),
)
: null;
@@ -202,10 +209,10 @@ class SwarmReadMarks extends ChangeNotifier {
_loaded && !reader.accessRevoked
? max(
reader.snapshot?.readMarks[conversationId] ?? 0,
- switch (_marks[conversationId]) {
+ max(switch (_marks[conversationId]) {
final mark? when mark != _firstRead[conversationId] => mark,
_ => 0,
- },
+ }, _held[conversationId] ?? 0),
)
: null;
@@ -267,6 +274,63 @@ class SwarmReadMarks extends ChangeNotifier {
notifyListeners();
}
+ /// Mark all read (the desktop's `SuperTabController.markAllRead`): every
+ /// chat of this Swarm shown unread — not dormant, not muted — reads as read
+ /// on this phone at once, through its newest message in its main stream,
+ /// and nothing is sent. Returns those marks by chat, for [sendHeld] once
+ /// the Undo window passes or [dropHeld] on Undo; empty with nothing unread,
+ /// before the marks are back, and once access is lost.
+ Map<String, int> holdAllRead() {
+ final snapshot = reader.snapshot;
+ if (_disposed || reader.accessRevoked || snapshot == null) return const {};
+ final through = <String, int>{};
+ for (final group in snapshot.conversations) {
+ if (group.dormant ||
+ snapshot.chatSettings[group.id] == 'muted' ||
+ !unread(group)) {
+ continue;
+ }
+ through[group.id] = _held[group.id] = group.mainSequence;
+ }
+ if (through.isNotEmpty) notifyListeners();
+ return through;
+ }
+
+ /// The Undo window of a Mark all read passed: each of [through] it still
+ /// holds goes to the server, and is kept on the phone, as a chat read is
+ /// ([markRead]). A chat the Swarm's read no longer has sends nothing.
+ void sendHeld(Map<String, int> through) => _sendHeld(through, tell: true);
+
+ void _sendHeld(Map<String, int> through, {required bool tell}) {
+ if (_disposed || reader.accessRevoked) return;
+ var moved = false;
+ for (final MapEntry(key: id, value: sequence) in through.entries) {
+ if (_held[id] != sequence) continue;
+ _held.remove(id);
+ if (reader.snapshot?.conversation(id) == null) continue;
+ _sender.mark(id, sequence, kept: reader.snapshot?.readMarks[id] ?? 0);
+ if (sequence > (_marks[id] ?? 0)) {
+ _marks[id] = sequence;
+ moved = true;
+ }
+ }
+ if (moved) _saveSoon();
+ if (tell) notifyListeners();
+ }
+
+ /// Undo of a Mark all read: each of [through] it still holds reads as it
+ /// did before; a chat read since keeps what it read. Nothing was sent.
+ void dropHeld(Map<String, int> through) {
+ if (_disposed) return;
+ var dropped = false;
+ for (final MapEntry(key: id, value: sequence) in through.entries) {
+ if (_held[id] != sequence) continue;
+ _held.remove(id);
+ dropped = true;
+ }
+ if (dropped) notifyListeners();
+ }
+
Future<void> _load() async {
final held = <String, int>{};
final first = <String, int>{};
@@ -355,7 +419,13 @@ class SwarmReadMarks extends ChangeNotifier {
void _forget() {
_save?.cancel();
_save = null;
- final had = _marks.isNotEmpty || _threads.isNotEmpty || _started;
+ final had =
+ _marks.isNotEmpty ||
+ _threads.isNotEmpty ||
+ _held.isNotEmpty ||
+ _started;
+ // A held Mark all read belongs to the access that is gone: never sent.
+ _held.clear();
_marks.clear();
_firstRead.clear();
_threads.clear();
@@ -423,6 +493,8 @@ class SwarmReadMarks extends ChangeNotifier {
@override
void dispose() {
+ // Closing the Swarm or the app is no Undo: a held Mark all read goes now.
+ if (_held.isNotEmpty) _sendHeld({..._held}, tell: false);
_disposed = true;
// What waited to be written is written now.
if (_save case final save?) {
diff --git a/mobile/lib/swarm/swarm_session.dart b/mobile/lib/swarm/swarm_session.dart
index fd0ef8c6f..dad1c8983 100644
--- a/mobile/lib/swarm/swarm_session.dart
+++ b/mobile/lib/swarm/swarm_session.dart
@@ -16,6 +16,7 @@ import 'swarm_face.dart';
import 'swarm_home_cache.dart';
import 'swarm_home_prefs.dart';
import 'swarm_inbox.dart';
+import 'swarm_mark_all.dart';
import 'swarm_notices.dart';
import 'swarm_profile.dart';
import 'swarm_request.dart';
@@ -35,6 +36,7 @@ class SwarmSession extends ChangeNotifier {
required SwarmNotices notices,
Duration pollInterval = const Duration(seconds: 15),
this.undoWindow = swarmUndoWindow,
+ this.markAllHold = swarmMarkAllHold,
SwarmHomeCache? homeCache,
LocalKeyValueStore? readMarks,
SwarmTold? told,
@@ -83,6 +85,40 @@ class SwarmSession extends ChangeNotifier {
/// How long a decision's answer is held before it is sent.
final Duration undoWindow;
+ /// How long Mark all read waits for its Undo before the marks are sent.
+ final Duration markAllHold;
+
+ /// The one Mark all read waiting for its Undo, if any.
+ SwarmMarkAll? get markAll => _markAll;
+ SwarmMarkAll? _markAll;
+
+ /// Mark all read on Home (the desktop's Shift+Esc): every chat of Swarms
+ /// [swarmIds] shown unread reads as read on this phone at once, and on
+ /// the server once [markAllHold] passes without [SwarmMarkAll.undo]. Null
+ /// when nothing is unread. A second one sends the first's marks before
+ /// it starts; leaving the app or closing the session sends them at once.
+ SwarmMarkAll? markAllRead(Iterable<String> swarmIds) {
+ if (_disposed) return null;
+ _markAll?.commit();
+ late final SwarmMarkAll? held;
+ held = SwarmMarkAll.start(
+ [
+ for (final id in swarmIds)
+ if (inbox.reader(id) case final reader? when !reader.accessRevoked)
+ ?reader.readMarks,
+ ],
+ hold: markAllHold,
+ onDone: () {
+ if (_markAll != held) return;
+ _markAll = null;
+ if (!_disposed) notifyListeners();
+ },
+ );
+ _markAll = held;
+ if (held != null) notifyListeners();
+ return held;
+ }
+
late final SwarmAnnouncer _announcer;
/// What tells of new messages in chats set to All new messages.
@@ -97,8 +133,10 @@ class SwarmSession extends ChangeNotifier {
bool _foreground = false, _disposed = false;
/// Harness is in front: the Swarms are read every poll, and those a screen
- /// watches every few seconds. Behind, nothing is.
+ /// watches every few seconds. Behind, nothing is. Going behind sends a
+ /// held Mark all read at once: the app may not come back to send it.
set foreground(bool value) {
+ if (!value) _markAll?.commit();
_foreground = value;
inbox.shown = value;
_show();
@@ -249,6 +287,8 @@ class SwarmSession extends ChangeNotifier {
@override
void dispose() {
+ // Closing the account or Swarm is no Undo: held marks go now.
+ _markAll?.commit();
_disposed = true;
for (final held in _held.values) {
held.timer.cancel();
diff --git a/mobile/lib/swarm/swarm_style.dart b/mobile/lib/swarm/swarm_style.dart
index 9d488adef..313c1e9a9 100644
--- a/mobile/lib/swarm/swarm_style.dart
+++ b/mobile/lib/swarm/swarm_style.dart
@@ -150,9 +150,9 @@ class SwarmTabHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
- final style = Tty.of(
- context,
- ).style(size: 20, weight: FontWeight.w600).copyWith(height: 1.2);
+ final style = Tty.of(context)
+ .style(size: 20, weight: FontWeight.w600)
+ .copyWith(height: 1.2);
final text = loading
? SkeletonText(
key: const ValueKey('swarm-title-loading'),
@@ -518,12 +518,7 @@ class SwarmAvatar extends StatelessWidget {
),
),
);
- return SwarmStatusFace(
- name: name,
- size: size,
- status: status,
- face: face,
- );
+ return SwarmStatusFace(name: name, size: size, status: status, face: face);
}
}
@@ -755,29 +750,63 @@ class SwarmIconButton extends StatelessWidget {
required this.label,
required this.onPressed,
this.size = 22,
+ this.selected,
});
final IconData icon;
final String label;
- final VoidCallback onPressed;
+
+ /// Null: greyed, and heard as not enabled.
+ final VoidCallback? onPressed;
final double size;
+ /// A switch's state: on, it is tinted in the accent; null for a plain
+ /// button.
+ final bool? selected;
+
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
+ final onPressed = this.onPressed;
+ final on = selected ?? false;
+ final color = onPressed == null
+ ? AppPalette.textFaint
+ : on
+ ? AppPalette.swarmAccent
+ : AppPalette.textPrimary;
return Semantics(
button: true,
+ enabled: onPressed != null,
+ toggled: selected,
label: label,
excludeSemantics: true,
+ onTap: onPressed,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: () {
- HapticFeedback.selectionClick();
- onPressed();
- },
+ onTap: onPressed == null
+ ? null
+ : () {
+ HapticFeedback.selectionClick();
+ onPressed();
+ },
child: SizedBox.square(
dimension: 44,
- child: Icon(icon, size: size, color: AppPalette.textPrimary),
+ child: Center(
+ child: DecoratedBox(
+ decoration: ShapeDecoration(
+ color: on
+ ? AppPalette.swarmAccent.withValues(alpha: .16)
+ : Colors.transparent,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(AppControl.radius),
+ ),
+ ),
+ child: SizedBox.square(
+ dimension: 36,
+ child: Icon(icon, size: size, color: color),
+ ),
+ ),
+ ),
),
),
);
diff --git a/mobile/test/swarm/swarm_mark_all_test.dart b/mobile/test/swarm/swarm_mark_all_test.dart
new file mode 100644
index 000000000..a6cfe00c0
--- /dev/null
+++ b/mobile/test/swarm/swarm_mark_all_test.dart
@@ -0,0 +1,598 @@
+import 'dart:convert';
+
+import 'package:fake_async/fake_async.dart';
+import 'package:flutter/cupertino.dart' show CupertinoPageRoute;
+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/swarm/swarm_home_prefs.dart';
+import 'package:harness_mobile/swarm/swarm_home_rows.dart';
+import 'package:harness_mobile/swarm/swarm_mark_all.dart';
+import 'package:harness_mobile/swarm/swarm_page.dart';
+import 'package:harness_mobile/swarm/swarm_reader.dart';
+import 'package:harness_mobile/swarm/swarm_session.dart';
+import 'package:harness_mobile/swarm/swarm_style.dart';
+
+import '../voice_fakes.dart' show MemoryKeyValueStore;
+import 'swarm_fixture.dart';
+
+/// Mark all read and the unread filter on the phone, as Desktop has them
+/// (#2453): every chat shown unread reads as read at once, and its mark goes
+/// to the server only once 6 s pass without Undo, since read marks never
+/// move back there. Leaving the app or closing the session is no Undo; access
+/// lost sends nothing. The filter lists only the projects with something
+/// unread, kept on this phone.
+void main() {
+ const web = 'project-2';
+ const webLead = 'group-lead-web';
+
+ /// One Swarm: Mobile, whose g1 and g2 are unread past the server's marks,
+ /// a muted chat and a dormant one unread too, and a read one; and Web,
+ /// read.
+ FakeSwarm backend() {
+ final fake = FakeSwarm();
+ fake.routes['/api/super-tabs/list'] = (_) => {
+ 'tabs': [
+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},
+ ],
+ 'next': null,
+ };
+ const derived = {
+ 'readMarks': {
+ leadChat: 2,
+ 'g1': 1,
+ 'g2': 1,
+ 'g-muted': 1,
+ 'g-dormant': 1,
+ 'g-read': 3,
+ webLead: 1,
+ },
+ 'chatSettings': {'g-muted': 'muted'},
+ };
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => firstLoad(
+ derived: derived,
+ head: headData(
+ projects: [
+ ...headData()['projects'] as List,
+ {
+ 'id': web,
+ 'name': 'Web',
+ 'ownerId': me,
+ 'leadConversationId': webLead,
+ 'visibility': 'public',
+ 'members': <Object>[],
+ 'updateMinutes': 5,
+ },
+ ],
+ ),
+ groups: [
+ groupData('g1', title: 'Fix login', lastMessageSequence: 5),
+ groupData('g2', title: 'Ship it', lastMessageSequence: 4),
+ groupData('g-muted', title: 'Noise', lastMessageSequence: 6),
+ groupData(
+ 'g-dormant',
+ title: 'Old',
+ lastMessageSequence: 7,
+ dormant: true,
+ ),
+ groupData('g-read', title: 'Done', lastMessageSequence: 3),
+ {
+ ...groupData(webLead, title: 'Web', lastMessageSequence: 1),
+ 'projectId': web,
+ },
+ ],
+ );
+ 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/'] = (body) => {
+ 'sequence': body?['sequence'],
+ 'messages': <Object>[],
+ 'next': null,
+ };
+ return fake;
+ }
+
+ /// The read marks sent, by chat and mark.
+ List<(String, Object?)> marksSent(FakeSwarm fake) => [
+ for (final call in fake.calls)
+ if (call.method == 'POST' && call.path.endsWith('/read'))
+ (
+ call.path.split('/conversations/').last.split('/').first,
+ call.body?['sequence'],
+ ),
+ ];
+
+ group('Mark all read', () {
+ /// A session over [backend], read once.
+ ({SwarmSession session, FakeSwarm fake, SwarmReader reader}) rig(
+ FakeAsync async, {
+ MemoryKeyValueStore? store,
+ }) {
+ final fake = backend();
+ final session = SwarmSession(
+ accountId: me,
+ request: fake.request,
+ notices: SilentSystemNotices(),
+ readMarks: store ?? MemoryKeyValueStore(),
+ );
+ session.inbox.refresh();
+ async.flushMicrotasks();
+ final reader = session.inbox.reader(tab)!;
+ return (session: session, fake: fake, reader: reader);
+ }
+
+ bool unread(SwarmReader reader, String id) =>
+ reader.readMarks!.unread(reader.snapshot!.conversation(id)!);
+
+ test('every chat shown unread reads as read at once, and nothing is '
+ 'sent before 6 s; then each mark is sent once', () {
+ fakeAsync((async) {
+ final r = rig(async);
+ expect(unread(r.reader, 'g1'), isTrue);
+
+ final held = r.session.markAllRead([tab])!;
+ async.flushMicrotasks();
+
+ expect(held.count, 2);
+ expect(unread(r.reader, 'g1'), isFalse);
+ expect(unread(r.reader, 'g2'), isFalse);
+ async.elapse(const Duration(milliseconds: 5900));
+ expect(marksSent(r.fake), isEmpty);
+
+ async.elapse(const Duration(milliseconds: 200));
+ expect(marksSent(r.fake), [('g1', 5), ('g2', 4)]);
+ expect(r.session.markAll, isNull);
+
+ async.elapse(const Duration(minutes: 1));
+ r.session.dispose();
+ async.flushMicrotasks();
+ expect(marksSent(r.fake), hasLength(2));
+ });
+ });
+
+ test('Undo within 6 s sends nothing, and the chats read unread again', () {
+ fakeAsync((async) {
+ final r = rig(async);
+ final held = r.session.markAllRead([tab])!;
+ async.elapse(const Duration(seconds: 3));
+
+ held.undo();
+ async.elapse(const Duration(seconds: 10));
+
+ expect(marksSent(r.fake), isEmpty);
+ expect(unread(r.reader, 'g1'), isTrue);
+ expect(unread(r.reader, 'g2'), isTrue);
+ expect(r.session.markAll, isNull);
+ r.session.dispose();
+ async.flushMicrotasks();
+ expect(marksSent(r.fake), isEmpty);
+ });
+ });
+
+ test('muted and dormant chats are left as they were, as on Desktop', () {
+ fakeAsync((async) {
+ final r = rig(async);
+ r.session.markAllRead([tab]);
+ async.elapse(const Duration(seconds: 7));
+
+ expect(unread(r.reader, 'g-muted'), isTrue);
+ expect(unread(r.reader, 'g-dormant'), isTrue);
+ expect(marksSent(r.fake).map((m) => m.$1), isNot(contains('g-muted')));
+ expect(
+ marksSent(r.fake).map((m) => m.$1),
+ isNot(contains('g-dormant')),
+ );
+ r.session.dispose();
+ });
+ });
+
+ test('the app going to the background sends the marks at once: it may '
+ 'not come back to send them, and a late Undo changes nothing', () {
+ fakeAsync((async) {
+ final r = rig(async);
+ r.session.foreground = true;
+ final held = r.session.markAllRead([tab])!;
+ async.elapse(const Duration(seconds: 1));
+
+ r.session.foreground = false;
+ async.flushMicrotasks();
+
+ expect(marksSent(r.fake), [('g1', 5), ('g2', 4)]);
+ held.undo();
+ expect(unread(r.reader, 'g1'), isFalse);
+ r.session.dispose();
+ });
+ });
+
+ test('closing the session (app closed, account changed) sends the marks '
+ 'at once', () {
+ fakeAsync((async) {
+ final r = rig(async);
+ r.session.markAllRead([tab]);
+ async.elapse(const Duration(seconds: 1));
+
+ r.session.dispose();
+ async.flushMicrotasks();
+
+ expect(marksSent(r.fake), [('g1', 5), ('g2', 4)]);
+ });
+ });
+
+ test('access lost during the wait sends nothing, and the phone keeps no '
+ 'mark of it', () {
+ fakeAsync((async) {
+ final store = MemoryKeyValueStore();
+ final r = rig(async, store: store);
+ r.session.markAllRead([tab]);
+ async.elapse(const Duration(seconds: 1));
+
+ r.reader.revoke();
+ async.elapse(const Duration(seconds: 10));
+ r.session.dispose();
+ async.flushMicrotasks();
+
+ expect(marksSent(r.fake), isEmpty);
+ expect(store.values['swarm_read_marks.$me.$tab'], isNull);
+ });
+ });
+
+ test('a chat read during the wait keeps its read after Undo', () {
+ fakeAsync((async) {
+ final r = rig(async);
+ final held = r.session.markAllRead([tab])!;
+ r.reader.readMarks!.markRead('g1', 5);
+ async.flushMicrotasks();
+
+ held.undo();
+ async.elapse(const Duration(seconds: 10));
+
+ expect(unread(r.reader, 'g1'), isFalse);
+ expect(unread(r.reader, 'g2'), isTrue);
+ expect(marksSent(r.fake), [('g1', 5)]);
+ r.session.dispose();
+ });
+ });
+
+ test(
+ 'a second Mark all read sends the first\'s marks before it starts',
+ () {
+ fakeAsync((async) {
+ final r = rig(async);
+ r.session.markAllRead([tab]);
+ async.elapse(const Duration(seconds: 1));
+
+ expect(r.session.markAllRead([tab]), isNull);
+ async.flushMicrotasks();
+
+ expect(marksSent(r.fake), [('g1', 5), ('g2', 4)]);
+ r.session.dispose();
+ });
+ },
+ );
+
+ test('before the Swarm is read there is nothing to mark; once a failed '
+ 'first read recovers, Mark all read works', () {
+ fakeAsync((async) {
+ final fake = backend();
+ final load = fake.routes['/api/super-tabs/$tab/parts']!;
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) =>
+ throw const SwarmRequestTestFailure();
+ final session = SwarmSession(
+ accountId: me,
+ request: fake.request,
+ notices: SilentSystemNotices(),
+ readMarks: MemoryKeyValueStore(),
+ );
+ session.inbox.refresh();
+ async.flushMicrotasks();
+ final reader = session.inbox.reader(tab)!;
+ expect(reader.snapshot, isNull);
+ expect(swarmAnyUnread([reader]), isFalse);
+ expect(session.markAllRead([tab]), isNull);
+
+ fake.routes['/api/super-tabs/$tab/parts'] = load;
+ reader.refresh();
+ async.flushMicrotasks();
+
+ expect(swarmAnyUnread([reader]), isTrue);
+ expect(session.markAllRead([tab])?.count, 2);
+ session.dispose();
+ });
+ });
+ });
+
+ group('The unread filter', () {
+ test('is kept on this phone and read back', () async {
+ final store = MemoryKeyValueStore();
+ final prefs = SwarmHomePrefs(accountId: me, store: store);
+ await settle();
+ prefs.toggleUnreadOnly();
+ await settle();
+ prefs.dispose();
+
+ final again = SwarmHomePrefs(accountId: me, store: store);
+ await settle();
+ expect(again.unreadOnly, isTrue);
+
+ again.toggleUnreadOnly();
+ await settle();
+ // Nothing else chosen: nothing left on the phone.
+ expect(store.values['swarm_home.$me'], isNull);
+ again.dispose();
+ });
+
+ test('what an older phone wrote reads with it off; turned on before '
+ 'the choices are back, it stays on', () async {
+ final store = MemoryKeyValueStore()
+ ..values['swarm_home.$me'] = jsonEncode({
+ 'pins': ['$tab/$project'],
+ });
+ final old = SwarmHomePrefs(accountId: me, store: store);
+ await settle();
+ expect(old.unreadOnly, isFalse);
+ expect(old.pins, {'$tab/$project'});
+ old.dispose();
+
+ final early = SwarmHomePrefs(accountId: me, store: store)
+ ..toggleUnreadOnly();
+ await settle();
+ expect(early.unreadOnly, isTrue);
+ expect(early.pins, {'$tab/$project'});
+ expect(
+ jsonDecode(store.values['swarm_home.$me']!),
+ containsPair('unread', true),
+ );
+ early.dispose();
+ });
+ });
+
+ group('Home', () {
+ Future<SwarmHost> pump(
+ WidgetTester tester,
+ FakeSwarm fake, {
+ ValueNotifier<String?>? signedIn,
+ }) async {
+ tester.view.physicalSize = const Size(1170, 2532);
+ tester.view.devicePixelRatio = 3;
+ addTearDown(tester.view.reset);
+ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())
+ ..value = {PhoneExperiment.swarm};
+ final account = signedIn ?? ValueNotifier<String?>(me);
+ final host = SwarmHost(
+ accountId: () => account.value,
+ account: account,
+ request: fake.request,
+ notices: SilentSystemNotices(),
+ features: features,
+ readMarks: MemoryKeyValueStore(),
+ )..foreground = false;
+ addTearDown(host.dispose);
+ await tester.pumpWidget(
+ MaterialApp(
+ builder: (context, child) =>
+ SwarmScope(notifier: host, child: child!),
+ onGenerateRoute: (_) => CupertinoPageRoute<void>(
+ builder: (_) => SwarmPage(
+ now: () => DateTime.fromMillisecondsSinceEpoch(
+ 0,
+ isUtc: true,
+ ).add(const Duration(minutes: 30)),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ return host;
+ }
+
+ Finder key(String value) => find.byKey(ValueKey(value));
+ Finder row(String projectId) => key('swarm-project-$tab-$projectId');
+ bool bold(WidgetTester tester, String projectId) =>
+ tester.widget<SwarmHomeProjectRow>(row(projectId)).project.news.bold;
+ SwarmIconButton button(WidgetTester tester, String k) =>
+ tester.widget<SwarmIconButton>(key(k));
+
+ testWidgets('the filter lists only projects with something unread, '
+ 'and says so when none has, with Show all', (tester) async {
+ await pump(tester, backend());
+ expect(row(project), findsOneWidget);
+ expect(row(web), findsOneWidget);
+ expect(button(tester, 'swarm-unread-only').selected, isFalse);
+
+ await tester.tap(key('swarm-unread-only'));
+ await tester.pumpAndSettle();
+
+ expect(row(project), findsOneWidget);
+ expect(row(web), findsNothing);
+ expect(button(tester, 'swarm-unread-only').selected, isTrue);
+ expect(
+ tester.getSemantics(key('swarm-unread-only')),
+ matchesSemantics(
+ label: 'Show all projects',
+ isButton: true,
+ hasEnabledState: true,
+ isEnabled: true,
+ hasToggledState: true,
+ isToggled: true,
+ hasTapAction: true,
+ ),
+ );
+
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pumpAndSettle();
+ expect(row(project), findsNothing);
+ expect(key('swarm-unread-none'), findsOneWidget);
+
+ await tester.tap(key('swarm-unread-show-all'));
+ await tester.pumpAndSettle();
+ expect(row(project), findsOneWidget);
+ expect(row(web), findsOneWidget);
+ expect(button(tester, 'swarm-unread-only').selected, isFalse);
+ await tester.pump(const Duration(seconds: 7));
+ });
+
+ testWidgets('Mark all read tells how many with Undo; Undo puts the bold '
+ 'back and sends nothing, and with nothing unread it is greyed', (
+ tester,
+ ) async {
+ final fake = backend();
+ await pump(tester, fake);
+ expect(bold(tester, project), isTrue);
+ expect(button(tester, 'swarm-mark-all-read').onPressed, isNotNull);
+
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+
+ expect(find.text('Marked 2 chats read'), findsOneWidget);
+ expect(bold(tester, project), isFalse);
+ expect(button(tester, 'swarm-mark-all-read').onPressed, isNull);
+
+ await tester.tap(find.text('Undo'));
+ await tester.pump();
+ await tester.pump(const Duration(seconds: 7));
+ await tester.pumpAndSettle();
+
+ expect(marksSent(fake), isEmpty);
+ expect(bold(tester, project), isTrue);
+
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pump();
+ await tester.pump(const Duration(seconds: 7));
+ await tester.pumpAndSettle();
+ expect(marksSent(fake), [('g1', 5), ('g2', 4)]);
+ expect(button(tester, 'swarm-mark-all-read').onPressed, isNull);
+ });
+
+ testWidgets('after the 6 s the marks are sent and the Undo toast closes '
+ 'with them', (tester) async {
+ final fake = backend();
+ await pump(tester, fake);
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+ expect(find.text('Undo'), findsOneWidget);
+
+ await tester.pump(const Duration(milliseconds: 5600));
+ await tester.pump(const Duration(seconds: 1));
+
+ expect(marksSent(fake), [('g1', 5), ('g2', 4)]);
+ expect(find.text('Undo'), findsNothing);
+ expect(find.text('Marked 2 chats read'), findsNothing);
+ // And it stays closed.
+ await tester.pump(const Duration(minutes: 1));
+ expect(find.text('Undo'), findsNothing);
+ });
+
+ testWidgets('with a screen reader on, a second Mark all read inside the '
+ '6 s keeps its own toast, and the first one is closed', (tester) async {
+ tester.platformDispatcher.accessibilityFeaturesTestValue =
+ const FakeAccessibilityFeatures(accessibleNavigation: true);
+ addTearDown(
+ tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
+ );
+ final fake = backend();
+ final host = await pump(tester, fake);
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+ expect(find.text('Marked 2 chats read'), findsOneWidget);
+
+ // A new message in a chat that was read: something to mark again.
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => changes(
+ cursor: 'c3',
+ groups: [
+ part(
+ 'g-read',
+ 9,
+ groupData('g-read', title: 'Done', lastMessageSequence: 8),
+ ),
+ ],
+ );
+ await host.session!.inbox.reader(tab)!.refresh();
+ await tester.pump();
+ await tester.tap(key('swarm-mark-all-read'));
+ for (var i = 0; i < 10; i++) {
+ await tester.pump(const Duration(milliseconds: 100));
+ }
+
+ expect(marksSent(fake), [('g1', 5), ('g2', 4)]);
+ expect(find.text('Marked 2 chats read'), findsNothing);
+ expect(find.text('Marked 1 chat read'), findsOneWidget);
+ expect(find.text('Undo'), findsOneWidget);
+
+ await tester.pump(const Duration(seconds: 7));
+ expect(marksSent(fake), [('g1', 5), ('g2', 4), ('g-read', 8)]);
+ expect(find.text('Undo'), findsNothing);
+ });
+
+ testWidgets('the app going to the background sends the marks and '
+ 'closes the Undo toast at once', (tester) async {
+ final fake = backend();
+ final host = await pump(tester, fake);
+ host.foreground = true;
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+ expect(find.text('Undo'), findsOneWidget);
+
+ host.foreground = false;
+ await tester.pump();
+ await tester.pump(const Duration(seconds: 1));
+
+ expect(marksSent(fake), [('g1', 5), ('g2', 4)]);
+ expect(find.text('Undo'), findsNothing);
+ expect(find.text('Marked 2 chats read'), findsNothing);
+ });
+
+ testWidgets('another account signing in sends the marks and closes the '
+ 'Undo toast at once', (tester) async {
+ final fake = backend();
+ final account = ValueNotifier<String?>(me);
+ await pump(tester, fake, signedIn: account);
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+ expect(find.text('Undo'), findsOneWidget);
+
+ account.value = 'person-other';
+ await tester.pump();
+ await tester.pump(const Duration(seconds: 1));
+
+ expect(marksSent(fake), [('g1', 5), ('g2', 4)]);
+ expect(find.text('Undo'), findsNothing);
+ });
+
+ testWidgets('access lost while Home is open: the held marks are never '
+ 'sent, and nothing is left to mark', (tester) async {
+ final fake = backend();
+ final host = await pump(tester, fake);
+ await tester.tap(key('swarm-mark-all-read'));
+ await tester.pump();
+
+ host.session!.inbox.reader(tab)!.revoke();
+ await tester.pump();
+ // Home reads the Swarm again under a skeleton: nothing settles.
+ for (var i = 0; i < 70; i++) {
+ await tester.pump(const Duration(milliseconds: 100));
+ }
+
+ expect(marksSent(fake), isEmpty);
+ expect(row(project), findsNothing);
+ expect(swarmAnyUnread([host.session!.inbox.reader(tab)!]), isFalse);
+ });
+ });
+}
+
+/// A read that fails, as a server that cannot answer.
+class SwarmRequestTestFailure implements Exception {
+ const SwarmRequestTestFailure();
+}