fix: Do not setup UP if init from an UP action

This commit is contained in:
S1m 2021-12-22 08:12:04 +00:00 committed by Krille Fear
parent 81164316b5
commit fd19dafbbb

View File

@ -68,6 +68,8 @@ class BackgroundPush {
DateTime lastReceivedPush; DateTime lastReceivedPush;
bool upAction = false;
BackgroundPush._(this.client, {this.onFcmError}) { BackgroundPush._(this.client, {this.onFcmError}) {
onLogin ??= onLogin ??=
client.onLoginStateChanged.stream.listen(handleLoginStateChanged); client.onLoginStateChanged.stream.listen(handleLoginStateChanged);
@ -214,12 +216,18 @@ class BackgroundPush {
bool _wentToRoomOnStartup = false; bool _wentToRoomOnStartup = false;
Future<void> setupPush() async { Future<void> setupPush() async {
Logs().d("SetupPush");
await setupLocalNotificationsPlugin(); await setupLocalNotificationsPlugin();
if (client.loginState != LoginState.loggedIn || if (client.loginState != LoginState.loggedIn ||
!PlatformInfos.isMobile || !PlatformInfos.isMobile ||
context == null) { context == null) {
return; return;
} }
// Do not setup unifiedpush if this has been initialized by
// an unifiedpush action
if (upAction) {
return;
}
if (!PlatformInfos.isIOS && if (!PlatformInfos.isIOS &&
(await UnifiedPush.getDistributors()).isNotEmpty) { (await UnifiedPush.getDistributors()).isNotEmpty) {
await setupUp(); await setupUp();
@ -334,6 +342,7 @@ class BackgroundPush {
} }
Future<void> _newUpEndpoint(String newEndpoint) async { Future<void> _newUpEndpoint(String newEndpoint) async {
upAction = true;
if (newEndpoint?.isEmpty ?? true) { if (newEndpoint?.isEmpty ?? true) {
await _upUnregistered(); await _upUnregistered();
return; return;
@ -377,6 +386,7 @@ class BackgroundPush {
} }
Future<void> _upUnregistered() async { Future<void> _upUnregistered() async {
upAction = true;
Logs().i('[Push] Removing UnifiedPush endpoint...'); Logs().i('[Push] Removing UnifiedPush endpoint...');
final oldEndpoint = await store.getItem(SettingKeys.unifiedPushEndpoint); final oldEndpoint = await store.getItem(SettingKeys.unifiedPushEndpoint);
await store.setItemBool(SettingKeys.unifiedPushRegistered, false); await store.setItemBool(SettingKeys.unifiedPushRegistered, false);
@ -390,6 +400,7 @@ class BackgroundPush {
} }
Future<void> _onUpMessage(String message) async { Future<void> _onUpMessage(String message) async {
upAction = true;
Map<String, dynamic> data; Map<String, dynamic> data;
try { try {
data = Map<String, dynamic>.from(json.decode(message)['notification']); data = Map<String, dynamic>.from(json.decode(message)['notification']);