open roomID on click notification (#1216)

pull/1544/head
ggurdin 11 months ago committed by GitHub
parent e38c1a08ee
commit c845c971d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -83,6 +83,8 @@ class BackgroundPush {
// #Pangea
onLogin ??=
client.onLoginStateChanged.stream.listen(handleLoginStateChanged);
FirebaseMessaging.instance.getInitialMessage().then(_onOpenNotification);
FirebaseMessaging.onMessageOpenedApp.listen(_onOpenNotification);
// Pangea#
await _flutterLocalNotificationsPlugin.initialize(
const InitializationSettings(
@ -123,6 +125,35 @@ class BackgroundPush {
_init();
}
// #Pangea
Future<void> _onOpenNotification(RemoteMessage? message) async {
if (message == null ||
!message.data.containsKey('room_id') ||
message.data['room_id'] == null ||
message.data['room_id'].isEmpty) {
return;
}
try {
final roomId = message.data['room_id'];
await client.roomsLoading;
await client.accountDataLoading;
if (client.getRoomById(roomId) == null) {
await client
.waitForRoomInSync(roomId)
.timeout(const Duration(seconds: 30));
}
FluffyChatApp.router.go(
client.getRoomById(roomId)?.membership == Membership.invite
? '/rooms'
: '/rooms/$roomId',
);
} catch (err, s) {
ErrorHandler.logError(e: err, s: s);
}
}
// Pangea#
factory BackgroundPush.clientOnly(Client client) {
return _instance ??= BackgroundPush._(client);
}

Loading…
Cancel
Save