File tree Expand file tree Collapse file tree 5 files changed +31
-3
lines changed
examples/push_notifications/lib Expand file tree Collapse file tree 5 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ class MyApp extends StatelessWidget {
2525 // This widget is the root of your application.
2626 @override
2727 Widget build (BuildContext context) {
28- // final session = Session(appId: 'Hku1c4Pt');
29- final session = Session (appId: 'tuM9UrY8' ); // For local testing
28+ final session = Session (appId: 'Hku1c4Pt' , enablePushNotifications : true );
29+ // final session = Session(appId: 'tuM9UrY8', enablePushNotifications: true ); // For local testing
3030
3131 final me = session.getUser (
3232 id: '123456' ,
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import './chatoptions.dart';
1414import './user.dart' ;
1515import './message.dart' ;
1616import './predicate.dart' ;
17+ import './notification.dart' ;
1718
1819typedef SendMessageHandler = void Function (SendMessageEvent event);
1920typedef TranslationToggledHandler = void Function (TranslationToggledEvent event);
@@ -217,6 +218,17 @@ class ChatBoxState extends State<ChatBox> {
217218 execute ('options["me"] = $variableName ;' );
218219
219220 execute ('const session = new Talk.Session(options);' );
221+
222+ // TODO: This part has to be moved in the Session once we have the data layer SDK ready
223+ if (widget.session.enablePushNotifications) {
224+ if (fcmToken != null ) {
225+ execute ('session.setPushRegistration({provider: "fcm", pushRegistrationId: "$fcmToken "});' );
226+ }
227+ } else {
228+ if (fcmToken != null ) {
229+ execute ('session.unsetPushRegistration({provider: "fcm", pushRegistrationId: "$fcmToken "});' );
230+ }
231+ }
220232 }
221233
222234 void _createChatBox () {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import './conversation.dart';
1313import './user.dart' ;
1414import './predicate.dart' ;
1515import './chatbox.dart' ;
16+ import './notification.dart' ;
1617
1718typedef SelectConversationHandler = void Function (SelectConversationEvent event);
1819
@@ -176,6 +177,17 @@ class ConversationListState extends State<ConversationList> {
176177 execute ('options["me"] = $variableName ;' );
177178
178179 execute ('const session = new Talk.Session(options);' );
180+
181+ // TODO: This part has to be moved in the Session once we have the data layer SDK ready
182+ if (widget.session.enablePushNotifications) {
183+ if (fcmToken != null ) {
184+ execute ('session.setPushRegistration({provider: "fcm", pushRegistrationId: "$fcmToken "});' );
185+ }
186+ } else {
187+ if (fcmToken != null ) {
188+ execute ('session.unsetPushRegistration({provider: "fcm", pushRegistrationId: "$fcmToken "});' );
189+ }
190+ }
179191 }
180192
181193 void _createConversationList () {
Original file line number Diff line number Diff line change @@ -287,6 +287,8 @@ void _onFCMTokenRefresh(String token) {
287287 print ('📘 Firebase onTokenRefresh: $token ' );
288288
289289 fcmToken = token;
290+
291+ // TODO: Update the token on the Talkjs server once we have the data layer SDK ready
290292}
291293
292294Future <void > registerAndroidPushNotificationHandlers (AndroidChannel androidChannel) async {
Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ class Session with ChangeNotifier {
3535 /// code.
3636 final String ? signature;
3737
38- Session ({required this .appId, this .signature});
38+ final bool enablePushNotifications;
39+
40+ Session ({required this .appId, this .signature, this .enablePushNotifications = false });
3941
4042 User getUser ({
4143 required String id,
You can’t perform that action at this time.
0 commit comments