From 0295a81e50dd7a664f7c37f8438eec3e8839c648 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 18 Oct 2023 17:41:41 -0700 Subject: [PATCH] wip and on-opened as class static too --- lib/notifications.dart | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/notifications.dart b/lib/notifications.dart index e961b57d17..bbf6b5fad2 100644 --- a/lib/notifications.dart +++ b/lib/notifications.dart @@ -109,31 +109,6 @@ class NotificationService { } } -void _onNotificationOpened(NotificationResponse response) async { - final data = MessageFcmMessage.fromJson(jsonDecode(response.payload!)); - assert(debugLog('opened notif: message ${data.zulipMessageId}, content ${data.content}')); - final navigator = navigatorKey.currentState; - if (navigator == null) return; // TODO(log) handle - - final globalStore = GlobalStoreWidget.of(navigator.context); - final account = globalStore.accounts.firstWhereOrNull((account) => - account.realmUrl == data.realmUri && account.userId == data.userId); - if (account == null) return; // TODO(log) - - final narrow = switch (data.recipient) { - FcmMessageStreamRecipient(:var streamId, :var topic) => - TopicNarrow(streamId, topic), - FcmMessageDmRecipient(:var allRecipientIds) => - DmNarrow(allRecipientIds: allRecipientIds, selfUserId: account.userId), - }; - - assert(debugLog(' account: $account, narrow: $narrow')); - // TODO(nav): Better interact with existing nav stack on notif open - navigator.push(MaterialPageRoute(builder: (context) => - PerAccountStoreWidget(accountId: account.id, - child: MessageListPage(narrow: narrow)))); -} - /// Service for configuring our Android "notification channel". class NotificationChannelManager { static const _kChannelId = 'messages-1'; @@ -213,4 +188,29 @@ class NotificationDisplayManager { // https://url.spec.whatwg.org/#url-code-points return "${data.realmUri}|${data.userId}"; } + + static void _onNotificationOpened(NotificationResponse response) async { + final data = MessageFcmMessage.fromJson(jsonDecode(response.payload!)); + assert(debugLog('opened notif: message ${data.zulipMessageId}, content ${data.content}')); + final navigator = navigatorKey.currentState; + if (navigator == null) return; // TODO(log) handle + + final globalStore = GlobalStoreWidget.of(navigator.context); + final account = globalStore.accounts.firstWhereOrNull((account) => + account.realmUrl == data.realmUri && account.userId == data.userId); + if (account == null) return; // TODO(log) + + final narrow = switch (data.recipient) { + FcmMessageStreamRecipient(:var streamId, :var topic) => + TopicNarrow(streamId, topic), + FcmMessageDmRecipient(:var allRecipientIds) => + DmNarrow(allRecipientIds: allRecipientIds, selfUserId: account.userId), + }; + + assert(debugLog(' account: $account, narrow: $narrow')); + // TODO(nav): Better interact with existing nav stack on notif open + navigator.push(MaterialPageRoute(builder: (context) => + PerAccountStoreWidget(accountId: account.id, + child: MessageListPage(narrow: narrow)))); + } }