From 92d267602e2c2ea9d291d3261bed8f714653a4f5 Mon Sep 17 00:00:00 2001 From: S1m Date: Wed, 22 Dec 2021 08:12:04 +0000 Subject: [PATCH] fix: Do not setup UP if init from an UP action --- lib/utils/background_push.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 579b9745..32a06596 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -68,6 +68,8 @@ class BackgroundPush { DateTime lastReceivedPush; + bool upAction = false; + BackgroundPush._(this.client, {this.onFcmError}) { onLogin ??= client.onLoginStateChanged.stream.listen(handleLoginStateChanged); @@ -214,12 +216,18 @@ class BackgroundPush { bool _wentToRoomOnStartup = false; Future setupPush() async { + Logs().d("SetupPush"); await setupLocalNotificationsPlugin(); if (client.loginState != LoginState.loggedIn || !PlatformInfos.isMobile || context == null) { return; } + // Do not setup unifiedpush if this has been initialized by + // an unifiedpush action + if (upAction) { + return; + } if (!PlatformInfos.isIOS && (await UnifiedPush.getDistributors()).isNotEmpty) { await setupUp(); @@ -334,6 +342,7 @@ class BackgroundPush { } Future _newUpEndpoint(String newEndpoint) async { + upAction = true; if (newEndpoint?.isEmpty ?? true) { await _upUnregistered(); return; @@ -377,6 +386,7 @@ class BackgroundPush { } Future _upUnregistered() async { + upAction = true; Logs().i('[Push] Removing UnifiedPush endpoint...'); final oldEndpoint = await store.getItem(SettingKeys.unifiedPushEndpoint); await store.setItemBool(SettingKeys.unifiedPushRegistered, false); @@ -390,6 +400,7 @@ class BackgroundPush { } Future _onUpMessage(String message) async { + upAction = true; Map data; try { data = Map.from(json.decode(message)['notification']);