From f64e7e532fe3cdc16bc22e92d7f50ab76ccec672 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 22 Jun 2023 01:01:49 +0530 Subject: [PATCH] chore: bump firebase and migrate code. Signed-off-by: xsahil03x --- packages/stream_chat_v1/lib/app.dart | 2 +- .../lib/utils/notifications_service.dart | 60 +++++++++---------- packages/stream_chat_v1/pubspec.yaml | 7 ++- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/packages/stream_chat_v1/lib/app.dart b/packages/stream_chat_v1/lib/app.dart index 744bde9..a986c89 100644 --- a/packages/stream_chat_v1/lib/app.dart +++ b/packages/stream_chat_v1/lib/app.dart @@ -210,7 +210,7 @@ class _StreamChatSampleAppState extends State // Navigates to Channel page, which is associated with the notification. GoRouter.of(_navigatorKey.currentContext!).pushNamed( Routes.CHANNEL_PAGE.name, - params: Routes.CHANNEL_PAGE.params(channel), + pathParameters: Routes.CHANNEL_PAGE.params(channel), ); }; } diff --git a/packages/stream_chat_v1/lib/utils/notifications_service.dart b/packages/stream_chat_v1/lib/utils/notifications_service.dart index 96d1fc5..0e858cc 100644 --- a/packages/stream_chat_v1/lib/utils/notifications_service.dart +++ b/packages/stream_chat_v1/lib/utils/notifications_service.dart @@ -11,52 +11,48 @@ void showLocalNotification( String currentUserId, BuildContext context, ) async { + // Don't show notification if the event is from the current user. + if (event.user!.id == currentUserId) return; + + // Don't show notification if the event is not a message. if (![ - EventType.messageNew, - EventType.notificationMessageNew, - ].contains(event.type) || - event.user!.id == currentUserId) { - return; - } + EventType.messageNew, + EventType.notificationMessageNew, + ].contains(event.type)) return; + + // Return if the message is null. if (event.message == null) return; + final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); - const initializationSettingsAndroid = - AndroidInitializationSettings('ic_notification_in_app'); - const initializationSettingsIOS = IOSInitializationSettings(); const initializationSettings = InitializationSettings( - android: initializationSettingsAndroid, - iOS: initializationSettingsIOS, + iOS: DarwinInitializationSettings(), + android: AndroidInitializationSettings('ic_notification_in_app'), ); final appLocalizations = AppLocalizations.of(context); await flutterLocalNotificationsPlugin.initialize( initializationSettings, - onSelectNotification: (channelCid) async { - if (channelCid != null) { - final client = StreamChat.of(context).client; - final router = GoRouter.of(context); + onDidReceiveNotificationResponse: (response) async { + final channelCid = response.payload; + if (channelCid == null) return; - var channel = client.state.channels[channelCid]; + final channelType = channelCid.split(':')[0]; + final channelId = channelCid.split(':')[1]; - if (channel == null) { - final splits = channelCid.split(':'); - final type = splits[0]; - final id = splits[1]; - channel = client.channel( - type, - id: id, - ); - await channel.watch(); - } + final client = StreamChat.of(context).client; + final router = GoRouter.of(context); - router.pushNamed( - Routes.CHANNEL_PAGE.name, - pathParameters: Routes.CHANNEL_PAGE.params(channel), - ); - } + final channel = client.channel(channelType, id: channelId); + await channel.watch(); + + router.pushNamed( + Routes.CHANNEL_PAGE.name, + pathParameters: Routes.CHANNEL_PAGE.params(channel), + ); }, ); + await flutterLocalNotificationsPlugin.show( event.message!.id.hashCode, event.message!.user!.name, @@ -69,7 +65,7 @@ void showLocalNotification( priority: Priority.high, importance: Importance.high, ), - iOS: const IOSNotificationDetails(), + iOS: const DarwinNotificationDetails(), ), payload: '${event.channelType}:${event.channelId}', ); diff --git a/packages/stream_chat_v1/pubspec.yaml b/packages/stream_chat_v1/pubspec.yaml index e9277c0..d6597b8 100644 --- a/packages/stream_chat_v1/pubspec.yaml +++ b/packages/stream_chat_v1/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: "none" version: 2.2.0 environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=1.17.0" dependencies: @@ -26,7 +26,7 @@ dependencies: url: https://github.com/GetStream/stream-chat-flutter.git ref: develop path: packages/stream_chat_localizations - flutter_local_notifications: ^9.0.0 + flutter_local_notifications: ^14.1.1 flutter_svg: ^2.0.7 flutter_secure_storage: ^8.0.0 yaml: ^3.1.2 @@ -39,7 +39,8 @@ dependencies: go_router: ^8.0.5 provider: ^6.0.5 video_player: ^2.6.1 - firebase_messaging: ^14.5.0 + firebase_core: ^2.14.0 + firebase_messaging: ^14.6.3 dev_dependencies: flutter_launcher_icons: ^0.13.1