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.

fix(mobile): going to an agent takes its notice out of the notification centre

Dev jacobcd023dd4ddb6
diff --git a/mobile/lib/notify/agent_announcer.dart b/mobile/lib/notify/agent_announcer.dart
index 40c7ec55c..09aba5971 100644
--- a/mobile/lib/notify/agent_announcer.dart
+++ b/mobile/lib/notify/agent_announcer.dart
@@ -27,6 +27,12 @@ class AgentAnnouncer {
final SystemNotices system;
final unread = AgentUnread();
final _asked = AskedQuestions();
+
+ /// Agents with a notice up in the OS centre right now. What lets going to
+ /// an agent take its notice down — a notice about news already read is a
+ /// second thing to dismiss by hand — without asking the OS for one that was
+ /// never posted.
+ final _posted = <AgentRef>{};
final Future<void> Function() _chime;
final bool Function() _inFront;
@@ -99,22 +105,33 @@ class AgentAnnouncer {
if (!_asked.forget(ref, requestId: requestId)) return;
if (unread.kindFor(ref) != NoticeKind.question) return;
unread.clear(ref, kind: NoticeKind.question);
- system.cancel(ref);
+ _withdraw(ref);
+ }
+
+ /// The person went to the agent — tapped its row, its notice, or came back
+ /// to the app on it. Whatever it was carrying has been read: the mark AND
+ /// the notice still sitting in the OS centre come down together.
+ void seen(AgentRef ref) {
+ unread.clear(ref);
+ _withdraw(ref);
}
/// The agent is gone. An agent that no longer exists cannot be gone to, and
/// a notice about it would open nothing.
void forgetAgent(AgentRef ref) {
_asked.forget(ref);
- if (!unread.contains(ref)) return;
- unread.clear(ref);
- system.cancel(ref);
+ seen(ref);
}
/// Signed out: nothing any of it was about is this person's any more.
void reset() {
unread.clearAll();
_asked.clear();
+ _posted.toList().forEach(_withdraw);
+ }
+
+ void _withdraw(AgentRef ref) {
+ if (_posted.remove(ref)) system.cancel(ref);
}
void _deliver(
@@ -126,6 +143,7 @@ class AgentAnnouncer {
if (notice.chimes && inFront) _chime();
if (notice.marks) unread.mark(agent.ref, kind);
if (!notice.alerts) return;
+ _posted.add(agent.ref);
system.show((
agent: agent.ref,
kind: kind,
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index c01fb1584..f10957357 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -7097,7 +7097,7 @@ class AppNotifier extends ChangeNotifier {
void _seeWatchedAgent() {
final watched = _watchedAgent;
- if (watched != null) agentNotices.unread.clear(watched);
+ if (watched != null) agentNotices.seen(watched);
}
/// [agent] on [machine], as a notice names it.
diff --git a/mobile/test/notify/agent_announcer_test.dart b/mobile/test/notify/agent_announcer_test.dart
index 4e9470191..5bd2f149e 100644
--- a/mobile/test/notify/agent_announcer_test.dart
+++ b/mobile/test/notify/agent_announcer_test.dart
@@ -107,6 +107,41 @@ void main() {
expect(announcer.unread.count, 0);
});
+ group('going to the agent', () {
+ test('takes down its mark and the notice still in the OS centre', () {
+ front = false;
+ announcer.turnEnded(agent, news, watching: () => false);
+ front = true;
+ announcer.seen(ref);
+ expect(announcer.unread.contains(ref), isFalse);
+ expect(system.cancelled, [ref]);
+ });
+
+ test('never asks the OS to cancel a notice it did not post', () {
+ announcer.turnEnded(agent, news, watching: () => false);
+ announcer.seen(ref);
+ expect(announcer.unread.contains(ref), isFalse);
+ expect(system.cancelled, isEmpty);
+ });
+
+ test('a notice is taken down once, not every time the agent is seen', () {
+ front = false;
+ announcer.turnEnded(agent, news, watching: () => false);
+ announcer
+ ..seen(ref)
+ ..seen(ref);
+ expect(system.cancelled, [ref]);
+ });
+
+ test('signing out takes every posted notice down', () {
+ front = false;
+ announcer.turnEnded(agent, news, watching: () => false);
+ announcer.reset();
+ expect(system.cancelled, [ref]);
+ expect(announcer.unread.count, 0);
+ });
+ });
+
group('questions', () {
AgentNotice ask({String id = 'q1', bool watching = false}) =>
announcer.questionAsked(