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
1 changed files with 11 additions and 0 deletions

View File

@ -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<void> 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<void> _newUpEndpoint(String newEndpoint) async {
upAction = true;
if (newEndpoint?.isEmpty ?? true) {
await _upUnregistered();
return;
@ -377,6 +386,7 @@ class BackgroundPush {
}
Future<void> _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<void> _onUpMessage(String message) async {
upAction = true;
Map<String, dynamic> data;
try {
data = Map<String, dynamic>.from(json.decode(message)['notification']);