@@ -17,31 +17,23 @@ 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
///
29
25
/// The context argument should be a descendant of the app's main [Navigator] .
30
26
static AccountRoute <void >? routeForNotification ({
31
27
required BuildContext context,
32
- required Uri url ,
28
+ required NotificationOpenPayload data ,
33
29
}) {
34
30
assert (defaultTargetPlatform == TargetPlatform .android);
35
31
36
32
final globalStore = GlobalStoreWidget .of (context);
37
33
38
- assert (debugLog ('got notif: url: $url ' ));
39
- assert (url.scheme == 'zulip' && url.host == 'notification' );
40
- final payload = NotificationOpenPayload .parseAndroidNotificationUrl (url);
41
-
42
34
final account = globalStore.accounts.firstWhereOrNull (
43
- (account) => account.realmUrl.origin == payload .realmUrl.origin
44
- && account.userId == payload .userId);
35
+ (account) => account.realmUrl.origin == data .realmUrl.origin
36
+ && account.userId == data .userId);
45
37
if (account == null ) { // TODO(log)
46
38
final zulipLocalizations = ZulipLocalizations .of (context);
47
39
showErrorDialog (context: context,
@@ -53,14 +45,14 @@ class NotificationOpenService {
53
45
return MessageListPage .buildRoute (
54
46
accountId: account.id,
55
47
// TODO(#82): Open at specific message, not just conversation
56
- narrow: payload .narrow);
48
+ narrow: data .narrow);
57
49
}
58
50
59
51
/// Navigates to the [MessageListPage] of the specific conversation
60
52
/// given the `zulip://notification/…` Android intent data URL,
61
53
/// generated with [NotificationOpenPayload.buildAndroidNotificationUrl]
62
54
/// while creating the notification.
63
- static Future <void > navigateForNotification (Uri url) async {
55
+ static Future <void > navigateForAndroidNotificationUrl (Uri url) async {
64
56
assert (defaultTargetPlatform == TargetPlatform .android);
65
57
assert (debugLog ('opened notif: url: $url ' ));
66
58
@@ -69,7 +61,9 @@ class NotificationOpenService {
69
61
assert (context.mounted);
70
62
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
71
63
72
- final route = routeForNotification (context: context, url: url);
64
+ assert (url.scheme == 'zulip' && url.host == 'notification' );
65
+ final data = NotificationOpenPayload .parseAndroidNotificationUrl (url);
66
+ final route = routeForNotification (context: context, data: data);
73
67
if (route == null ) return ; // TODO(log)
74
68
75
69
// TODO(nav): Better interact with existing nav stack on notif open
0 commit comments