Skip to content

Commit f98cfef

Browse files
author
Franco Bugnano
committed
Remove Talk.initPushNotificationHandlers and add AndoridSettings.registerBackgroundHandler
1 parent acad16d commit f98cfef

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

lib/src/notification.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class AndroidSettings {
7171
final AndroidVisibility? visibility;
7272
final bool? vibrate;
7373
final Int64List? vibrationPattern;
74+
final bool? registerBackgroundHandler;
7475

7576
const AndroidSettings({
7677
required this.channelId,
@@ -84,6 +85,7 @@ class AndroidSettings {
8485
this.visibility,
8586
this.vibrate,
8687
this.vibrationPattern,
88+
this.registerBackgroundHandler,
8789
});
8890

8991
AndroidSettings.fromJson(Map<String, dynamic> json)
@@ -107,7 +109,8 @@ class AndroidSettings {
107109
? null
108110
: Int64List.fromList(List.from(
109111
(json['vibrationPattern'] as List<dynamic>)
110-
.map((e) => e as int)));
112+
.map((e) => e as int))),
113+
registerBackgroundHandler = json['registerBackgroundHandler'];
111114

112115
Map<String, dynamic> toJson() {
113116
return {
@@ -128,7 +131,8 @@ class AndroidSettings {
128131
'importance': importance?.name,
129132
'visibility': visibility?.name,
130133
'vibrate': vibrate,
131-
'vibrationPattern': vibrationPattern
134+
'vibrationPattern': vibrationPattern,
135+
'registerBackgroundHandler': registerBackgroundHandler,
132136
};
133137
}
134138
}
@@ -377,7 +381,7 @@ void _onFCMTokenRefresh(String token) {
377381
// TODO: Update the token on the Talkjs server once we have the data layer SDK ready
378382
}
379383

380-
Future<void> initAndroidPushNotificationHandlers(
384+
Future<void> registerAndroidPushNotificationHandlers(
381385
AndroidSettings androidSettings,
382386
) async {
383387
// Get the token each time the application loads
@@ -438,14 +442,16 @@ Future<void> initAndroidPushNotificationHandlers(
438442
// PlatformException is raised on Android < 6.0
439443
// Simply ignoring this part
440444
}
441-
}
442445

443-
Future<void> registerAndroidPushNotificationHandlers(
444-
AndroidSettings androidSettings,
445-
) async {
446-
await initAndroidPushNotificationHandlers(androidSettings);
446+
// Default to registering the background handler for backward compatibility
447+
final registerBackgroundHandler =
448+
androidSettings.registerBackgroundHandler == null
449+
? true
450+
: androidSettings.registerBackgroundHandler!;
447451

448-
FirebaseMessaging.onBackgroundMessage(_onFCMBackgroundMessage);
452+
if (registerBackgroundHandler) {
453+
FirebaseMessaging.onBackgroundMessage(_onFCMBackgroundMessage);
454+
}
449455
}
450456

451457
Future<void> _onPush(String name, ApnsRemoteMessage message) async {
@@ -459,7 +465,7 @@ Future<void> _onPush(String name, ApnsRemoteMessage message) async {
459465
}
460466
}
461467

462-
Future<void> initIOSPushNotificationHandlers(
468+
Future<void> registerIOSPushNotificationHandlers(
463469
IOSSettings iosSettings,
464470
) async {
465471
final connector = ApnsPushConnectorOnly();
@@ -483,9 +489,3 @@ Future<void> initIOSPushNotificationHandlers(
483489
});
484490
}
485491
}
486-
487-
Future<void> registerIOSPushNotificationHandlers(
488-
IOSSettings iosSettings,
489-
) async {
490-
await initIOSPushNotificationHandlers(iosSettings);
491-
}

lib/talkjs_flutter.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,5 @@ class Talk {
4545
}
4646
}
4747

48-
static Future<void> initPushNotificationHandlers({
49-
AndroidSettings? androidSettings,
50-
IOSSettings? iosSettings,
51-
}) async {
52-
if ((Platform.isAndroid) && (androidSettings != null)) {
53-
await initAndroidPushNotificationHandlers(androidSettings);
54-
} else if ((Platform.isIOS) && (iosSettings != null)) {
55-
await initIOSPushNotificationHandlers(iosSettings);
56-
}
57-
}
58-
5948
static const handleFCMBackgroundMessage = handleTalkJSFCMBackgroundMessage;
6049
}

0 commit comments

Comments
 (0)