diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java index 428d8f721..24c1a5b31 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java @@ -1,7 +1,9 @@ /* * Nextcloud Talk application * + * @author Andy Scherzinger * @author Mario Danic + * Copyright (C) 2022 Andy Scherzinger * Copyright (C) 2017-2018 Mario Danic * * This program is free software: you can redistribute it and/or modify @@ -57,6 +59,7 @@ import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.DoNotDisturbUtils; import com.nextcloud.talk.utils.NotificationUtils; import com.nextcloud.talk.utils.PushUtils; +import com.nextcloud.talk.utils.UserIdUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder; @@ -106,7 +109,7 @@ public class NotificationWorker extends Worker { AppPreferences appPreferences; @Inject - ArbitraryStorageManager arbitraryStorageManger; + ArbitraryStorageManager arbitraryStorageManager; @Inject Retrofit retrofit; @@ -132,12 +135,12 @@ public class NotificationWorker extends Worker { private void showNotificationForCallWithNoPing(Intent intent) { User user = signatureVerification.getUser(); - importantConversation = arbitraryStorageManger.getStorageSetting( - user.getId(), - "important_conversation", - intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())) + importantConversation = arbitraryStorageManager.getStorageSetting( + UserIdUtils.INSTANCE.getIdForUser(user), + "important_conversation", + intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())) .map(arbitraryStorage -> { - if (arbitraryStorage != null) { + if (arbitraryStorage != null && arbitraryStorage.getValue() != null) { return Boolean.parseBoolean(arbitraryStorage.getValue()); } else { return importantConversation; @@ -146,6 +149,8 @@ public class NotificationWorker extends Worker { .switchIfEmpty(Maybe.just(importantConversation)) .blockingGet(); + Log.e(TAG, "showNotificationForCallWithNoPing: importantConversation: " + importantConversation); + int apiVersion = ApiUtils.getConversationApiVersion(user, new int[] {ApiUtils.APIv4, 1}); ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, user.getBaseUrl(), @@ -153,7 +158,7 @@ public class NotificationWorker extends Worker { .blockingSubscribe(new Observer() { @Override public void onSubscribe(Disposable d) { - //unused atm + // unused atm } @Override @@ -183,12 +188,12 @@ public class NotificationWorker extends Worker { @Override public void onError(Throwable e) { - //unused atm + // unused atm } @Override public void onComplete() { - //unused atm + // unused atm } }); } @@ -200,7 +205,7 @@ public class NotificationWorker extends Worker { .blockingSubscribe(new Observer() { @Override public void onSubscribe(Disposable d) { - //unused atm + // unused atm } @Override @@ -263,12 +268,12 @@ public class NotificationWorker extends Worker { @Override public void onError(Throwable e) { - //unused atm + // unused atm } @Override public void onComplete() { - //unused atm + // unused atm } }); } @@ -647,6 +652,8 @@ public class NotificationWorker extends Worker { intent.putExtras(bundle); + Log.e(TAG, "Notification: " + decryptedPushMessage.getType()); + switch (decryptedPushMessage.getType()) { case "call": if (bundle.containsKey(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java index cf37b49ca..38ec20d5c 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java @@ -1,8 +1,10 @@ /* * Nextcloud Talk application * + * @author Andy Scherzinger * @author Mario Danic * @author Tim Krüger + * Copyright (C) 2022 Andy Scherzinger * Copyright (C) 2021 Tim Krüger * Copyright (C) 2017-2018 Mario Danic * @@ -29,9 +31,11 @@ import android.util.Log; import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager; +import com.nextcloud.talk.data.storage.model.ArbitraryStorage; import com.nextcloud.talk.data.user.model.User; import com.nextcloud.talk.models.json.generic.GenericOverall; import com.nextcloud.talk.utils.ApiUtils; +import com.nextcloud.talk.utils.UserIdUtils; import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew; import com.yarolegovich.mp.io.StorageModule; @@ -42,7 +46,6 @@ import java.util.Set; import javax.inject.Inject; import autodagger.AutoInjector; -import io.reactivex.Maybe; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -51,16 +54,15 @@ import io.reactivex.schedulers.Schedulers; @AutoInjector(NextcloudTalkApplication.class) public class DatabaseStorageModule implements StorageModule { private static final String TAG = "DatabaseStorageModule"; - @Inject ArbitraryStorageManager arbitraryStorageManager; @Inject NcApi ncApi; - private User conversationUser; - private String conversationToken; - private long accountIdentifier; + private final User conversationUser; + private final String conversationToken; + private final long accountIdentifier; private boolean lobbyValue; @@ -70,7 +72,7 @@ public class DatabaseStorageModule implements StorageModule { NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); this.conversationUser = conversationUser; - this.accountIdentifier = conversationUser.getId(); + this.accountIdentifier = UserIdUtils.INSTANCE.getIdForUser(conversationUser); this.conversationToken = conversationToken; } @@ -94,7 +96,7 @@ public class DatabaseStorageModule implements StorageModule { @Override public void onNext(@NotNull GenericOverall genericOverall) { - // unused atm + Log.d(TAG, "Toggled notification calls"); } @Override @@ -142,8 +144,7 @@ public class DatabaseStorageModule implements StorageModule { intValue = 0; } - int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, - new int[] {ApiUtils.APIv4, 1}); + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1}); ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()), @@ -182,10 +183,7 @@ public class DatabaseStorageModule implements StorageModule { @Override public void saveInt(String key, int value) { - arbitraryStorageManager.storeStorageSetting(accountIdentifier, - key, - Integer.toString(value), - conversationToken); + arbitraryStorageManager.storeStorageSetting(accountIdentifier, key, Integer.toString(value), conversationToken); } @Override @@ -200,15 +198,8 @@ public class DatabaseStorageModule implements StorageModule { } else { return arbitraryStorageManager .getStorageSetting(accountIdentifier, key, conversationToken) - .map(arbitraryStorage -> { - if (arbitraryStorage != null) { - return Boolean.parseBoolean(arbitraryStorage.getValue()); - } else { - return defaultVal; - } - }) - .switchIfEmpty(Maybe.just(defaultVal)) - .blockingGet(); + .map(arbitraryStorage -> Boolean.parseBoolean(arbitraryStorage.getValue())) + .blockingGet(defaultVal); } } @@ -219,15 +210,8 @@ public class DatabaseStorageModule implements StorageModule { } else { return arbitraryStorageManager .getStorageSetting(accountIdentifier, key, conversationToken) - .map(arbitraryStorage -> { - if (arbitraryStorage != null) { - return arbitraryStorage.getValue(); - } else { - return defaultVal; - } - }) - .switchIfEmpty(Maybe.just(defaultVal)) - .blockingGet(); + .map(ArbitraryStorage::getValue) + .blockingGet(defaultVal); } } @@ -236,14 +220,13 @@ public class DatabaseStorageModule implements StorageModule { return arbitraryStorageManager .getStorageSetting(accountIdentifier, key, conversationToken) .map(arbitraryStorage -> { - if (arbitraryStorage != null && arbitraryStorage.getValue() != null) { + if (arbitraryStorage.getValue() != null) { return Integer.parseInt(arbitraryStorage.getValue()); } else { return defaultVal; } }) - .switchIfEmpty(Maybe.just(defaultVal)) - .blockingGet(); + .blockingGet(defaultVal); } @Override