Skip to content

Commit

Permalink
wip and on-opened as class static too
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Oct 19, 2023
1 parent 064f019 commit 0295a81
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions lib/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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))));
}
}

0 comments on commit 0295a81

Please sign in to comment.