@@ -8,19 +8,16 @@ import 'package:http/http.dart' as http;
8
8
9
9
import '../api/model/model.dart' ;
10
10
import '../api/notifications.dart' ;
11
- import '../generated/l10n/zulip_localizations.dart' ;
12
11
import '../host/android_notifications.dart' ;
13
12
import '../log.dart' ;
14
13
import '../model/binding.dart' ;
15
14
import '../model/localizations.dart' ;
16
15
import '../model/narrow.dart' ;
17
16
import '../widgets/app.dart' ;
18
17
import '../widgets/color.dart' ;
19
- import '../widgets/dialog.dart' ;
20
18
import '../widgets/message_list.dart' ;
21
- import '../widgets/page.dart' ;
22
- import '../widgets/store.dart' ;
23
19
import '../widgets/theme.dart' ;
20
+ import 'navigate.dart' ;
24
21
25
22
AndroidNotificationHostApi get _androidHost => ZulipBinding .instance.androidNotificationHost;
26
23
@@ -481,42 +478,6 @@ class NotificationDisplayManager {
481
478
482
479
static String _personKey (Uri realmUrl, int userId) => "$realmUrl |$userId " ;
483
480
484
- /// Provides the route and the account ID by parsing the notification URL.
485
- ///
486
- /// The URL must have been generated using [NotificationOpenPayload.buildUrl]
487
- /// while creating the notification.
488
- ///
489
- /// Returns null and shows an error dialog if the associated account is not
490
- /// found in the global store.
491
- static AccountRoute <void >? routeForNotification ({
492
- required BuildContext context,
493
- required Uri url,
494
- }) {
495
- assert (defaultTargetPlatform == TargetPlatform .android);
496
-
497
- final globalStore = GlobalStoreWidget .of (context);
498
-
499
- assert (debugLog ('got notif: url: $url ' ));
500
- assert (url.scheme == 'zulip' && url.host == 'notification' );
501
- final payload = NotificationNavigationData .parseAndroidNotificationUrl (url);
502
-
503
- final account = globalStore.accounts.firstWhereOrNull (
504
- (account) => account.realmUrl.origin == payload.realmUrl.origin
505
- && account.userId == payload.userId);
506
- if (account == null ) { // TODO(log)
507
- final zulipLocalizations = ZulipLocalizations .of (context);
508
- showErrorDialog (context: context,
509
- title: zulipLocalizations.errorNotificationOpenTitle,
510
- message: zulipLocalizations.errorNotificationOpenAccountNotFound);
511
- return null ;
512
- }
513
-
514
- return MessageListPage .buildRoute (
515
- accountId: account.id,
516
- // TODO(#82): Open at specific message, not just conversation
517
- narrow: payload.narrow);
518
- }
519
-
520
481
/// Navigates to the [MessageListPage] of the specific conversation
521
482
/// given the `zulip://notification/…` Android intent data URL,
522
483
/// generated with [NotificationOpenPayload.buildUrl] while creating
@@ -530,7 +491,12 @@ class NotificationDisplayManager {
530
491
assert (context.mounted);
531
492
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
532
493
533
- final route = routeForNotification (context: context, url: url);
494
+ assert (url.scheme == 'zulip' && url.host == 'notification' );
495
+ final payload =
496
+ NotificationNavigationService .tryParseAndroidNotificationUrl (context, url);
497
+ if (payload == null ) return ; // TODO(log)
498
+
499
+ final route = NotificationNavigationService .routeForNotification (context, payload);
534
500
if (route == null ) return ; // TODO(log)
535
501
536
502
// TODO(nav): Better interact with existing nav stack on notif open
@@ -550,88 +516,3 @@ class NotificationDisplayManager {
550
516
return null ;
551
517
}
552
518
}
553
-
554
- /// The data from a notification that describes what to do
555
- /// when the user opens the notification.
556
- class NotificationNavigationData {
557
- final Uri realmUrl;
558
- final int userId;
559
- final SendableNarrow narrow;
560
-
561
- NotificationNavigationData ({
562
- required this .realmUrl,
563
- required this .userId,
564
- required this .narrow,
565
- });
566
-
567
- /// Parses the internal Android notification url, that was created using
568
- /// [buildAndroidNotificationUrl] , and retrieves the information required
569
- /// for navigation.
570
- factory NotificationNavigationData .parseAndroidNotificationUrl (Uri url) {
571
- if (url case Uri (
572
- scheme: 'zulip' ,
573
- host: 'notification' ,
574
- queryParameters: {
575
- 'realm_url' : var realmUrlStr,
576
- 'user_id' : var userIdStr,
577
- 'narrow_type' : var narrowType,
578
- // In case of narrowType == 'topic':
579
- // 'channel_id' and 'topic' handled below.
580
-
581
- // In case of narrowType == 'dm':
582
- // 'all_recipient_ids' handled below.
583
- },
584
- )) {
585
- final realmUrl = Uri .parse (realmUrlStr);
586
- final userId = int .parse (userIdStr, radix: 10 );
587
-
588
- final SendableNarrow narrow;
589
- switch (narrowType) {
590
- case 'topic' :
591
- final channelIdStr = url.queryParameters['channel_id' ]! ;
592
- final channelId = int .parse (channelIdStr, radix: 10 );
593
- final topicStr = url.queryParameters['topic' ]! ;
594
- narrow = TopicNarrow (channelId, TopicName (topicStr));
595
- case 'dm' :
596
- final allRecipientIdsStr = url.queryParameters['all_recipient_ids' ]! ;
597
- final allRecipientIds = allRecipientIdsStr.split (',' )
598
- .map ((idStr) => int .parse (idStr, radix: 10 ))
599
- .toList (growable: false );
600
- narrow = DmNarrow (allRecipientIds: allRecipientIds, selfUserId: userId);
601
- default :
602
- throw const FormatException ();
603
- }
604
-
605
- return NotificationNavigationData (
606
- realmUrl: realmUrl,
607
- userId: userId,
608
- narrow: narrow,
609
- );
610
- } else {
611
- // TODO(dart): simplify after https://github.com/dart-lang/language/issues/2537
612
- throw const FormatException ();
613
- }
614
- }
615
-
616
- Uri buildAndroidNotificationUrl () {
617
- return Uri (
618
- scheme: 'zulip' ,
619
- host: 'notification' ,
620
- queryParameters: < String , String > {
621
- 'realm_url' : realmUrl.toString (),
622
- 'user_id' : userId.toString (),
623
- ...(switch (narrow) {
624
- TopicNarrow (streamId: var channelId, : var topic) => {
625
- 'narrow_type' : 'topic' ,
626
- 'channel_id' : channelId.toString (),
627
- 'topic' : topic.apiName,
628
- },
629
- DmNarrow (: var allRecipientIds) => {
630
- 'narrow_type' : 'dm' ,
631
- 'all_recipient_ids' : allRecipientIds.join (',' ),
632
- },
633
- })
634
- },
635
- );
636
- }
637
- }
0 commit comments