Merge branch 'fix-init-unifiedpush' into 'main'

Do not setup UP if init from an UP action

See merge request famedly/fluffychat!628
This commit is contained in:
Krille Fear 2021-12-22 08:12:04 +00:00
commit 1c3e0e4d1e

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']);