From dc7602a1d3449aece0f8df4fa9a105847d7f34b8 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 21 Jun 2023 12:37:10 +0930 Subject: [PATCH] Check fcm is enabled before modifying group sub --- .../notifications/PushManagerV1.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt index 6e4c61fee..09827ef8f 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt @@ -33,13 +33,14 @@ object PushManagerV1 { publicKey: String? = TextSecurePreferences.getLocalNumber(context), legacyGroupPublicKeys: Collection = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys() ): Promise<*, Exception> = - retryIfNeeded(maxRetryCount) { - if (isUsingFCM) doRegister(token, publicKey, legacyGroupPublicKeys) - else emptyPromise() + if (!isUsingFCM) { + emptyPromise() + } else retryIfNeeded(maxRetryCount) { + doRegister(token, publicKey, legacyGroupPublicKeys) } fail { exception -> Log.d(TAG, "Couldn't register for FCM due to error: ${exception}.") } success { - Log.d(TAG, "register success!!") + Log.d(TAG, "register success") } private fun doRegister(token: String?, publicKey: String?, legacyGroupPublicKeys: Collection): Promise<*, Exception> { @@ -62,7 +63,7 @@ object PushManagerV1 { return OnionRequestAPI.sendOnionRequest(request, legacyServer, legacyServerPublicKey, Version.V2).map { response -> when (response.info["code"]) { null, 0 -> throw Exception("error: ${response.info["message"]}.") - else -> Log.d(TAG, "register() success!!") + else -> Log.d(TAG, "doRegister success") } } } @@ -99,13 +100,19 @@ object PushManagerV1 { fun subscribeGroup( closedGroupPublicKey: String, + isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context), publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!! - ) = performGroupOperation("subscribe_closed_group", closedGroupPublicKey, publicKey) + ) = if (isUsingFCM) { + performGroupOperation("subscribe_closed_group", closedGroupPublicKey, publicKey) + } else emptyPromise() fun unsubscribeGroup( closedGroupPublicKey: String, + isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context), publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!! - ) = performGroupOperation("unsubscribe_closed_group", closedGroupPublicKey, publicKey) + ) = if (isUsingFCM) { + performGroupOperation("unsubscribe_closed_group", closedGroupPublicKey, publicKey) + } else emptyPromise() private fun performGroupOperation( operation: String,