@@ -17,29 +17,21 @@ import '../widgets/store.dart';
17
17
/// Responds to the user opening a notification.
18
18
class NotificationOpenService {
19
19
20
- /// Provides the route and the account ID by parsing the notification URL.
21
- ///
22
- /// The URL must have been generated using
23
- /// [NotificationOpenPayload.buildAndroidNotificationUrl] while creating the
24
- /// notification.
20
+ /// Provides the route to open by parsing the notification payload.
25
21
///
26
22
/// Returns null and shows an error dialog if the associated account is not
27
23
/// found in the global store.
28
24
static AccountRoute <void >? routeForNotification ({
29
25
required BuildContext context,
30
- required Uri url ,
26
+ required NotificationOpenPayload data ,
31
27
}) {
32
28
assert (defaultTargetPlatform == TargetPlatform .android);
33
29
34
30
final globalStore = GlobalStoreWidget .of (context);
35
31
36
- assert (debugLog ('got notif: url: $url ' ));
37
- assert (url.scheme == 'zulip' && url.host == 'notification' );
38
- final payload = NotificationOpenPayload .parseAndroidNotificationUrl (url);
39
-
40
32
final account = globalStore.accounts.firstWhereOrNull (
41
- (account) => account.realmUrl.origin == payload .realmUrl.origin
42
- && account.userId == payload .userId);
33
+ (account) => account.realmUrl.origin == data .realmUrl.origin
34
+ && account.userId == data .userId);
43
35
if (account == null ) { // TODO(log)
44
36
final zulipLocalizations = ZulipLocalizations .of (context);
45
37
showErrorDialog (context: context,
@@ -51,14 +43,14 @@ class NotificationOpenService {
51
43
return MessageListPage .buildRoute (
52
44
accountId: account.id,
53
45
// TODO(#82): Open at specific message, not just conversation
54
- narrow: payload .narrow);
46
+ narrow: data .narrow);
55
47
}
56
48
57
49
/// Navigates to the [MessageListPage] of the specific conversation
58
50
/// given the `zulip://notification/…` Android intent data URL,
59
51
/// generated with [NotificationOpenPayload.buildAndroidNotificationUrl]
60
52
/// while creating the notification.
61
- static Future <void > navigateForNotification (Uri url) async {
53
+ static Future <void > navigateForAndroidNotificationUrl (Uri url) async {
62
54
assert (defaultTargetPlatform == TargetPlatform .android);
63
55
assert (debugLog ('opened notif: url: $url ' ));
64
56
@@ -67,7 +59,9 @@ class NotificationOpenService {
67
59
assert (context.mounted);
68
60
if (! context.mounted) return ; // TODO(linter): this is impossible as there's no actual async gap, but the use_build_context_synchronously lint doesn't see that
69
61
70
- final route = routeForNotification (context: context, url: url);
62
+ assert (url.scheme == 'zulip' && url.host == 'notification' );
63
+ final data = NotificationOpenPayload .parseAndroidNotificationUrl (url);
64
+ final route = routeForNotification (context: context, data: data);
71
65
if (route == null ) return ; // TODO(log)
72
66
73
67
// TODO(nav): Better interact with existing nav stack on notif open
0 commit comments