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(desktop): a tag newer than what was read earlier opens at its message (#2023)

0xken1597a7ce132f40
diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dart
index 9db6833fe..21b782878 100644
--- a/desktop/lib/super_tabs/view.dart
+++ b/desktop/lib/super_tabs/view.dart
@@ -1132,22 +1132,26 @@ class _SuperTabViewState extends State<SuperTabView>
bool get _notificationsVisible =>
_showNotifications && !_devicesVisible && !c.accessRevoked;
- /// Opens the conversation a tag is in, at its message, replying to it. Older
- /// pages are read first, until the message is among them; one that is not
- /// found says so, and the list stays.
+ /// Opens the conversation a tag is in, at its message, replying to it. What
+ /// is held is looked in first, then what arrived after it, then older pages,
+ /// until the message is among them; one that is not found says so, and the
+ /// list stays.
Future<void> _openMention(SuperTabMention mention) async {
final id = mention.conversationId;
if (c.snapshot?.conversation(id) == null) return;
- SuperTabMessage? message;
- // Up to 50 pages (5,000 messages) back.
- for (var page = 0; page < 50; page++) {
- await c.loadMessages(id, older: c.messages(id).isNotEmpty);
+ SuperTabMessage? held() => c
+ .messages(id)
+ .where((m) => m.id == mention.messageId)
+ .firstOrNull;
+ var message = held();
+ // Up to 50 pages (5,000 messages). A tag newer than what was read earlier
+ // is after it, so the first read is up to the latest; the rest go back.
+ for (var page = 0; message == null && page < 50; page++) {
+ final older = page > 0;
+ if (older && !c.hasOlder(id)) break;
+ await c.loadMessages(id, older: older);
if (!mounted) return;
- message = c
- .messages(id)
- .where((m) => m.id == mention.messageId)
- .firstOrNull;
- if (message != null || !c.hasOlder(id)) break;
+ message = held();
}
if (message == null) {
ScaffoldMessenger.maybeOf(context)?.showSnackBar(
diff --git a/desktop/test/super_tab_mentions_test.dart b/desktop/test/super_tab_mentions_test.dart
index 5f6efa858..54b87ca9a 100644
--- a/desktop/test/super_tab_mentions_test.dart
+++ b/desktop/test/super_tab_mentions_test.dart
@@ -498,6 +498,74 @@ void main() {
expect(c.selectedId, isNot('group'));
});
+ testWidgets('a tag newer than what was read earlier opens at its message', (
+ tester,
+ ) async {
+ final server = ConversationServer();
+ server.state['conversations'] = [
+ ...server.state['conversations'] as List,
+ conversationFixture('group', 'Release'),
+ ];
+ for (var i = 1; i <= 100; i++) {
+ server.append('Note $i', conversationId: 'group');
+ }
+ final c = await showView(tester, server);
+ // Read earlier up to 100, then 100 more arrived while away.
+ await c.loadMessages('group');
+ expect(c.messages('group').last.id, 'message-100');
+ for (var i = 101; i <= 200; i++) {
+ server.append('Note $i', conversationId: 'group');
+ }
+ server.tag('message-150', conversationId: 'group', text: 'Note 150');
+ await tester.tap(notificationsEntry());
+ await tester.pumpAndSettle();
+ await tester.tap(find.byKey(const ValueKey('super-mention-mention-1')));
+ await tester.pumpAndSettle();
+ expect(
+ find.text('This message is no longer in the conversation.'),
+ findsNothing,
+ );
+ expect(c.selectedId, 'group');
+ expect(
+ find.byKey(const ValueKey('super-message-message-150')).hitTestable(),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('a tag among more than a page that arrived since opens too', (
+ tester,
+ ) async {
+ final server = ConversationServer();
+ server.state['conversations'] = [
+ ...server.state['conversations'] as List,
+ conversationFixture('group', 'Release'),
+ ];
+ for (var i = 1; i <= 100; i++) {
+ server.append('Note $i', conversationId: 'group');
+ }
+ final c = await showView(tester, server);
+ await c.loadMessages('group');
+ // More than a page since: the latest page (151..250) replaces what is
+ // held, and the tag is on the page before it.
+ for (var i = 101; i <= 250; i++) {
+ server.append('Note $i', conversationId: 'group');
+ }
+ server.tag('message-120', conversationId: 'group', text: 'Note 120');
+ await tester.tap(notificationsEntry());
+ await tester.pumpAndSettle();
+ await tester.tap(find.byKey(const ValueKey('super-mention-mention-1')));
+ await tester.pumpAndSettle();
+ expect(
+ find.text('This message is no longer in the conversation.'),
+ findsNothing,
+ );
+ expect(c.selectedId, 'group');
+ expect(
+ find.byKey(const ValueKey('super-message-message-120')).hitTestable(),
+ findsOneWidget,
+ );
+ });
+
testWidgets('opening a tag shows its message with the reply box on it', (
tester,
) async {