|
|
|
|
@ -41,7 +41,7 @@ import '../config/setting_keys.dart';
|
|
|
|
|
import '../widgets/matrix.dart';
|
|
|
|
|
import 'platform_infos.dart';
|
|
|
|
|
|
|
|
|
|
//<GOOGLE_SERVICES>import 'package:fcm_shared_isolate/fcm_shared_isolate.dart';
|
|
|
|
|
import 'package:fcm_shared_isolate/fcm_shared_isolate.dart';
|
|
|
|
|
|
|
|
|
|
class NoTokenException implements Exception {
|
|
|
|
|
String get cause => 'Cannot get firebase token';
|
|
|
|
|
@ -57,6 +57,9 @@ class BackgroundPush {
|
|
|
|
|
void Function(String errorMsg, {Uri? link})? onFcmError;
|
|
|
|
|
L10n? l10n;
|
|
|
|
|
|
|
|
|
|
FlutterLocalNotificationsPlugin get notificationsPlugin =>
|
|
|
|
|
_flutterLocalNotificationsPlugin;
|
|
|
|
|
|
|
|
|
|
Future<void> loadLocale() async {
|
|
|
|
|
final context = matrix?.context;
|
|
|
|
|
// inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart
|
|
|
|
|
@ -67,7 +70,7 @@ class BackgroundPush {
|
|
|
|
|
final pendingTests = <String, Completer<void>>{};
|
|
|
|
|
bool firebaseEnabled = false;
|
|
|
|
|
|
|
|
|
|
//<GOOGLE_SERVICES>final firebase = FcmSharedIsolate();
|
|
|
|
|
final firebase = FcmSharedIsolate();
|
|
|
|
|
|
|
|
|
|
DateTime? lastReceivedPush;
|
|
|
|
|
|
|
|
|
|
@ -119,17 +122,17 @@ class BackgroundPush {
|
|
|
|
|
MacOSFlutterLocalNotificationsPlugin>()
|
|
|
|
|
?.requestPermissions(alert: true, badge: true, sound: true);
|
|
|
|
|
}
|
|
|
|
|
//<GOOGLE_SERVICES>firebase.setListeners(
|
|
|
|
|
//<GOOGLE_SERVICES> onMessage: (message) => pushHelper(
|
|
|
|
|
//<GOOGLE_SERVICES> PushNotification.fromJson(
|
|
|
|
|
//<GOOGLE_SERVICES> Map<String, dynamic>.from(message['data'] ?? message),
|
|
|
|
|
//<GOOGLE_SERVICES> ),
|
|
|
|
|
//<GOOGLE_SERVICES> client: client,
|
|
|
|
|
//<GOOGLE_SERVICES> l10n: l10n,
|
|
|
|
|
//<GOOGLE_SERVICES> activeRoomId: matrix?.activeRoomId,
|
|
|
|
|
//<GOOGLE_SERVICES> flutterLocalNotificationsPlugin: _flutterLocalNotificationsPlugin,
|
|
|
|
|
//<GOOGLE_SERVICES> ),
|
|
|
|
|
//<GOOGLE_SERVICES>);
|
|
|
|
|
firebase.setListeners(
|
|
|
|
|
onMessage: (message) => pushHelper(
|
|
|
|
|
PushNotification.fromJson(
|
|
|
|
|
Map<String, dynamic>.from(message['data'] ?? message),
|
|
|
|
|
),
|
|
|
|
|
client: client,
|
|
|
|
|
l10n: l10n,
|
|
|
|
|
activeRoomId: matrix?.activeRoomId,
|
|
|
|
|
flutterLocalNotificationsPlugin: _flutterLocalNotificationsPlugin,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
await UnifiedPush.initialize(
|
|
|
|
|
onNewEndpoint: _newUpEndpoint,
|
|
|
|
|
@ -187,7 +190,7 @@ class BackgroundPush {
|
|
|
|
|
bool useDeviceSpecificAppId = false,
|
|
|
|
|
}) async {
|
|
|
|
|
if (PlatformInfos.isIOS) {
|
|
|
|
|
//<GOOGLE_SERVICES>await firebase.requestPermission();
|
|
|
|
|
await firebase.requestPermission();
|
|
|
|
|
}
|
|
|
|
|
if (PlatformInfos.isAndroid) {
|
|
|
|
|
_flutterLocalNotificationsPlugin
|
|
|
|
|
@ -359,7 +362,7 @@ class BackgroundPush {
|
|
|
|
|
Logs().v('Setup firebase');
|
|
|
|
|
if (_fcmToken?.isEmpty ?? true) {
|
|
|
|
|
try {
|
|
|
|
|
//<GOOGLE_SERVICES>_fcmToken = await firebase.getToken();
|
|
|
|
|
_fcmToken = await firebase.getToken();
|
|
|
|
|
if (_fcmToken == null) throw ('PushToken is null');
|
|
|
|
|
} catch (e, s) {
|
|
|
|
|
Logs().w('[Push] cannot get token', e, e is String ? null : s);
|
|
|
|
|
@ -416,8 +419,8 @@ class BackgroundPush {
|
|
|
|
|
Logs().i('[Push] UnifiedPush using endpoint $endpoint');
|
|
|
|
|
final oldTokens = <String?>{};
|
|
|
|
|
try {
|
|
|
|
|
//<GOOGLE_SERVICES>final fcmToken = await firebase.getToken();
|
|
|
|
|
//<GOOGLE_SERVICES>oldTokens.add(fcmToken);
|
|
|
|
|
final fcmToken = await firebase.getToken();
|
|
|
|
|
oldTokens.add(fcmToken);
|
|
|
|
|
} catch (_) {}
|
|
|
|
|
await setupPusher(
|
|
|
|
|
gatewayUrl: endpoint,
|
|
|
|
|
|