Skip to content

Commit 790c6df

Browse files
committed
notif: Preserve target account context on back navigation after opening a notification
Fixes: #1210
1 parent a198f72 commit 790c6df

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Diff for: lib/notifications/display.dart

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../model/narrow.dart';
1717
import '../widgets/app.dart';
1818
import '../widgets/color.dart';
1919
import '../widgets/dialog.dart';
20+
import '../widgets/home.dart';
2021
import '../widgets/message_list.dart';
2122
import '../widgets/page.dart';
2223
import '../widgets/store.dart';
@@ -502,6 +503,18 @@ class NotificationDisplayManager {
502503
final route = routeForNotification(context: context, url: url);
503504
if (route == null) return; // TODO(log)
504505

506+
Route<dynamic>? topRoute;
507+
navigator.popUntil((r) {
508+
topRoute = r;
509+
return true;
510+
});
511+
512+
if (topRoute == null || topRoute is! AccountRoute
513+
|| (topRoute as AccountRoute).accountId != route.accountId) {
514+
HomePage.navigate(context, accountId: route.accountId);
515+
navigator = await ZulipApp.navigator;
516+
}
517+
505518
// TODO(nav): Better interact with existing nav stack on notif open
506519
unawaited(navigator.push(route));
507520
}

Diff for: test/notifications/display_test.dart

+43
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,49 @@ void main() {
11761176
takeStartingRoutes(account: accountB);
11771177
matchesNavigation(check(pushedRoutes).single, accountB, message);
11781178
});
1179+
1180+
testWidgets('back navigation after opening a notification will preserve target account context', (tester) async {
1181+
addTearDown(testBinding.reset);
1182+
1183+
final accountA = eg.selfAccount;
1184+
final accountB = eg.otherAccount;
1185+
final message = eg.streamMessage();
1186+
1187+
await testBinding.globalStore.add(accountA, eg.initialSnapshot());
1188+
await testBinding.globalStore.add(accountB, eg.initialSnapshot());
1189+
1190+
await prepare(tester, early: true);
1191+
await tester.pump();
1192+
takeStartingRoutes(account: accountA);
1193+
1194+
Route<dynamic>? topRoute;
1195+
final navigator = await ZulipApp.navigator;
1196+
navigator.popUntil((r) {
1197+
topRoute = r;
1198+
return true;
1199+
});
1200+
check(topRoute).isA<AccountRoute>().accountId.equals(accountA.id);
1201+
await openNotification(tester, accountB, message);
1202+
1203+
navigator.popUntil((r) {
1204+
topRoute = r;
1205+
return true;
1206+
});
1207+
check(topRoute).isA<MaterialAccountWidgetRoute>()
1208+
..accountId.equals(accountB.id)
1209+
..page.isA<MessageListPage>();
1210+
1211+
navigator.pop();
1212+
await tester.pumpAndSettle();
1213+
1214+
navigator.popUntil((r) {
1215+
topRoute = r;
1216+
return true;
1217+
});
1218+
check(topRoute).isA<MaterialAccountWidgetRoute>()
1219+
..accountId.equals(accountB.id)
1220+
..page.isA<HomePage>();
1221+
});
11791222
});
11801223

11811224
group('NotificationOpenPayload', () {

0 commit comments

Comments
 (0)