From d3ea4e2e30de981ca2131242c1192a638324f9de Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 26 Jul 2023 14:36:06 +0930 Subject: [PATCH] Fix --- .../notifications/HuaweiPushManager.kt | 28 +++++++++----- .../notifications/HuaweiPushModule.kt | 11 ------ .../HuaweiPushNotificationService.kt | 11 ------ .../securesms/home/HomeActivity.kt | 5 ++- .../securesms/notifications/ExpiryManager.kt | 3 ++ .../notifications/FcmTokenManager.kt | 11 ++++-- .../securesms/onboarding/PNModeActivity.kt | 7 +++- .../NotificationSettingsActivity.kt | 2 + .../NotificationsPreferenceFragment.java | 10 ++++- .../notifications/GenericPushManager.kt | 37 ++++++++++++------- .../securesms/notifications/PushManagerV2.kt | 7 +++- app/src/play/AndroidManifest.xml | 2 +- .../notifications/FirebasePushManager.kt | 12 +++--- ....kt => FirebasePushNotificationService.kt} | 13 +------ .../MessageSenderClosedGroupHandler.kt | 2 +- .../ReceivedMessageHandler.kt | 2 +- .../notifications/PushManagerV1.kt | 17 +++++---- .../session/libsession/utilities/Device.kt | 4 +- 18 files changed, 99 insertions(+), 85 deletions(-) rename app/src/{play => main}/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt (76%) rename app/src/{play => main}/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt (96%) rename app/src/play/kotlin/org/thoughtcrime/securesms/notifications/{PushNotificationService.kt => FirebasePushNotificationService.kt} (64%) diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt index f17b35f292..6e495357f3 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt @@ -1,10 +1,22 @@ package org.thoughtcrime.securesms.notifications import android.content.Context +import com.huawei.hmf.tasks.Tasks import com.huawei.hms.aaid.HmsInstanceId +import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch +import javax.inject.Inject +import javax.inject.Singleton -class HuaweiPushManager(val context: Context): PushManager { +@Singleton +class HuaweiPushManager @Inject constructor( + @ApplicationContext private val context: Context, + private val genericPushManager: GenericPushManager +): PushManager { private var huaweiPushInstanceIdJob: Job? = null @Synchronized @@ -17,13 +29,11 @@ class HuaweiPushManager(val context: Context): PushManager { val hmsInstanceId = HmsInstanceId.getInstance(context) - val task = hmsInstanceId.aaid - -// HuaweiPushNotificationService().start() -// -// huaweiPushInstanceIdJob = HmsInstanceId.getInstance(this) { hmsInstanceId -> -// RegisterHuaweiPushService(hmsInstanceId, this, force).start() -// Unit.INSTANCE -// } + MainScope().launch(Dispatchers.IO) { + val task = hmsInstanceId.aaid + Tasks.await(task) + if (!isActive) return@launch // don't 'complete' task if we were canceled + task.result?.id?.let { genericPushManager.refresh(it, force) } + } } } diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt index e10ed77abf..c1be786afc 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushModule.kt @@ -8,17 +8,6 @@ import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import javax.inject.Singleton - -@Module -@InstallIn(SingletonComponent::class) -object HuaweiPushModule { - @Provides - @Singleton - fun provideFirebasePushManager( - @ApplicationContext context: Context, - ) = HuaweiPushManager(context) -} - @Module @InstallIn(SingletonComponent::class) abstract class HuaweiBindingModule { diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt index e6941a563d..507787123c 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt @@ -1,17 +1,9 @@ package org.thoughtcrime.securesms.notifications import android.os.Bundle -import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationManagerCompat import com.huawei.hms.push.HmsMessageService import com.huawei.hms.push.RemoteMessage import dagger.hilt.android.AndroidEntryPoint -import org.session.libsession.messaging.jobs.BatchMessageReceiveJob -import org.session.libsession.messaging.jobs.JobQueue -import org.session.libsession.messaging.jobs.MessageReceiveParameters -import org.session.libsession.messaging.utilities.MessageWrapper -import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.Log import javax.inject.Inject @@ -20,16 +12,13 @@ class HuaweiPushNotificationService: HmsMessageService() { @Inject lateinit var pushManager: PushManager @Inject lateinit var pushHandler: PushHandler - override fun onNewToken(token: String?, bundle: Bundle?) { Log.d("Loki", "New HCM token: $token.") pushManager.refresh(true) } - override fun onMessageReceived(message: RemoteMessage?) { pushHandler.onPush(message?.dataOfMap) } - override fun onDeletedMessages() { pushManager.refresh(true) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 6570c0ca18..c64d6ef071 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -67,6 +67,7 @@ import org.thoughtcrime.securesms.home.search.GlobalSearchViewModel import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideRequests +import org.thoughtcrime.securesms.notifications.PushManager import org.thoughtcrime.securesms.onboarding.SeedActivity import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate import org.thoughtcrime.securesms.permissions.Permissions @@ -106,6 +107,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), @Inject lateinit var groupDatabase: GroupDatabase @Inject lateinit var textSecurePreferences: TextSecurePreferences @Inject lateinit var configFactory: ConfigFactory + @Inject lateinit var pushManager: PushManager private val globalSearchViewModel by viewModels() private val homeViewModel by viewModels() @@ -230,8 +232,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), (applicationContext as ApplicationContext).startPollingIfNeeded() // update things based on TextSecurePrefs (profile info etc) // Set up remaining components if needed - val application = ApplicationContext.getInstance(this@HomeActivity) - application.registerForPnIfNeeded(false) + pushManager.refresh(false) if (textSecurePreferences.getLocalNumber() != null) { OpenGroupManager.startPolling() JobQueue.shared.resumePendingJobs() diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt index 36c986f0ea..45318d43ad 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/ExpiryManager.kt @@ -1,7 +1,10 @@ package org.thoughtcrime.securesms.notifications import android.content.Context +import dagger.hilt.android.qualifiers.ApplicationContext import org.session.libsession.utilities.TextSecurePreferences +import javax.inject.Inject +import javax.inject.Singleton class ExpiryManager( private val context: Context, diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/FcmTokenManager.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/FcmTokenManager.kt index e1182a480b..295c8296fc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/FcmTokenManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/FcmTokenManager.kt @@ -1,12 +1,17 @@ package org.thoughtcrime.securesms.notifications import android.content.Context +import dagger.hilt.android.qualifiers.ApplicationContext import org.session.libsession.utilities.TextSecurePreferences +import javax.inject.Inject +import javax.inject.Singleton -class FcmTokenManager( - private val context: Context, - private val expiryManager: ExpiryManager +@Singleton +class FcmTokenManager @Inject constructor( + @ApplicationContext private val context: Context, ) { + private val expiryManager = ExpiryManager(context) + val isUsingFCM get() = TextSecurePreferences.isUsingFCM(context) var fcmToken diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt index 8210937830..c8f036f15f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/PNModeActivity.kt @@ -19,6 +19,7 @@ import org.session.libsession.utilities.ThemeUtil import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.home.HomeActivity +import org.thoughtcrime.securesms.notifications.PushManager import org.thoughtcrime.securesms.showSessionDialog import org.thoughtcrime.securesms.util.GlowViewUtilities import org.thoughtcrime.securesms.util.PNModeView @@ -27,8 +28,12 @@ import org.thoughtcrime.securesms.util.getAccentColor import org.thoughtcrime.securesms.util.getColorWithID import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import org.thoughtcrime.securesms.util.show +import javax.inject.Inject class PNModeActivity : BaseActionBarActivity() { + + @Inject lateinit var pushManager: PushManager + private lateinit var binding: ActivityPnModeBinding private var selectedOptionView: PNModeView? = null @@ -161,7 +166,7 @@ class PNModeActivity : BaseActionBarActivity() { TextSecurePreferences.setIsUsingFCM(this, (selectedOptionView == binding.fcmOptionView)) val application = ApplicationContext.getInstance(this) application.startPollingIfNeeded() - application.registerForPnIfNeeded(true) + pushManager.refresh(true) val intent = Intent(this, HomeActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.putExtra(HomeActivity.FROM_ONBOARDING, true) diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt index af039a4fdb..b18859ea07 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt @@ -1,10 +1,12 @@ package org.thoughtcrime.securesms.preferences import android.os.Bundle +import dagger.hilt.android.AndroidEntryPoint import network.loki.messenger.R import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment +@AndroidEntryPoint class NotificationSettingsActivity : PassphraseRequiredActionBarActivity() { override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java index 8afc0ff41b..228392ad76 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java @@ -23,14 +23,22 @@ import org.session.libsession.utilities.TextSecurePreferences; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.components.SwitchPreferenceCompat; import org.thoughtcrime.securesms.notifications.NotificationChannels; +import org.thoughtcrime.securesms.notifications.PushManager; +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; import network.loki.messenger.R; +@AndroidEntryPoint public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment { @SuppressWarnings("unused") private static final String TAG = NotificationsPreferenceFragment.class.getSimpleName(); + @Inject + PushManager pushManager; + @Override public void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); @@ -41,7 +49,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme this.findPreference(fcmKey) .setOnPreferenceChangeListener((preference, newValue) -> { TextSecurePreferences.setIsUsingFCM(getContext(), (boolean) newValue); - ApplicationContext.getInstance(getContext()).registerForPnIfNeeded(true); + pushManager.refresh(true); return true; }); diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt similarity index 76% rename from app/src/play/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt rename to app/src/main/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt index 692826225d..ce4210fcfd 100644 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt +++ b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/GenericPushManager.kt @@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.notifications import android.content.Context import com.goterl.lazysodium.utils.KeyPair +import dagger.hilt.android.qualifiers.ApplicationContext import nl.komponents.kovenant.Promise import nl.komponents.kovenant.combine.and import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1 @@ -18,7 +19,7 @@ private const val TAG = "GenericPushManager" @Singleton class GenericPushManager @Inject constructor( - private val context: Context, + @ApplicationContext private val context: Context, private val device: Device, private val tokenManager: FcmTokenManager, private val pushManagerV2: PushManagerV2, @@ -60,17 +61,25 @@ class GenericPushManager @Inject constructor( publicKey: String, userEd25519Key: KeyPair, namespaces: List = listOf(Namespace.DEFAULT) - ): Promise<*, Exception> = PushManagerV1.register( - token = token, - device = device, - publicKey = publicKey - ) and pushManagerV2.register( - token, publicKey, userEd25519Key, namespaces - ) fail { - Log.e(TAG, "registerBoth failed", it) - } success { - Log.d(TAG, "registerBoth success... saving token!!") - tokenManager.fcmToken = token + ): Promise<*, Exception> { + val v1 = PushManagerV1.register( + device = device, + token = token, + publicKey = publicKey + ) fail { + Log.e(TAG, "register v1 failed", it) + } + + val v2 = pushManagerV2.register( + Device.ANDROID, token, publicKey, userEd25519Key, namespaces + ) fail { + Log.e(TAG, "register v2 failed", it) + } + + return v1 and v2 success { + Log.d(TAG, "registerBoth success... saving token!!") + tokenManager.fcmToken = token + } } private fun unregister( @@ -78,10 +87,10 @@ class GenericPushManager @Inject constructor( userPublicKey: String, userEdKey: KeyPair ): Promise<*, Exception> = PushManagerV1.unregister() and pushManagerV2.unregister( - token, userPublicKey, userEdKey + Device.ANDROID, token, userPublicKey, userEdKey ) fail { Log.e(TAG, "unregisterBoth failed", it) } success { tokenManager.fcmToken = null } -} \ No newline at end of file +} diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt similarity index 96% rename from app/src/play/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt rename to app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt index 9f9a132aba..93e6fc6819 100644 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt +++ b/app/src/main/kotlin/org/thoughtcrime/securesms/notifications/PushManagerV2.kt @@ -16,6 +16,7 @@ import org.session.libsession.messaging.sending_receiving.notifications.* import org.session.libsession.snode.OnionRequestAPI import org.session.libsession.snode.SnodeAPI import org.session.libsession.snode.Version +import org.session.libsession.utilities.Device import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Namespace @@ -31,6 +32,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) { private val sodium = LazySodiumAndroid(SodiumAndroid()) fun register( + device: Device, token: String, publicKey: String, userEd25519Key: KeyPair, @@ -48,7 +50,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) { session_ed25519 = userEd25519Key.publicKey.asHexString, namespaces = listOf(Namespace.DEFAULT), data = true, // only permit data subscription for now (?) - service = "firebase", + service = device.service, sig_ts = timestamp, signature = Base64.encodeBytes(signature), service_info = mapOf("token" to token), @@ -61,6 +63,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) { } fun unregister( + device: Device, token: String, userPublicKey: String, userEdKey: KeyPair @@ -74,7 +77,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) { val requestParameters = UnsubscriptionRequest( pubkey = userPublicKey, session_ed25519 = userEdKey.publicKey.asHexString, - service = "firebase", + service = device.service, sig_ts = timestamp, signature = Base64.encodeBytes(signature), service_info = mapOf("token" to token), diff --git a/app/src/play/AndroidManifest.xml b/app/src/play/AndroidManifest.xml index f5b54fd47e..8b975b0634 100644 --- a/app/src/play/AndroidManifest.xml +++ b/app/src/play/AndroidManifest.xml @@ -4,7 +4,7 @@ diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt index 3df54fc119..074ef379f8 100644 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt +++ b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushManager.kt @@ -1,9 +1,6 @@ package org.thoughtcrime.securesms.notifications -import android.content.Context -import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.Job -import org.session.libsession.utilities.Device import org.session.libsignal.utilities.Log import javax.inject.Inject import javax.inject.Singleton @@ -12,11 +9,9 @@ private const val TAG = "FirebasePushManager" @Singleton class FirebasePushManager @Inject constructor( - @ApplicationContext private val context: Context + private val genericPushManager: GenericPushManager ): PushManager { - @Inject lateinit var genericPushManager: GenericPushManager - private var firebaseInstanceIdJob: Job? = null @Synchronized @@ -24,7 +19,10 @@ class FirebasePushManager @Inject constructor( Log.d(TAG, "refresh() called with: force = $force") firebaseInstanceIdJob?.apply { - if (force) cancel() else if (isActive) return + when { + force -> cancel() + isActive -> return + } } firebaseInstanceIdJob = getFcmInstanceId { task -> diff --git a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/PushNotificationService.kt b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushNotificationService.kt similarity index 64% rename from app/src/play/kotlin/org/thoughtcrime/securesms/notifications/PushNotificationService.kt rename to app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushNotificationService.kt index bc641f82cd..b8640296fa 100644 --- a/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/PushNotificationService.kt +++ b/app/src/play/kotlin/org/thoughtcrime/securesms/notifications/FirebasePushNotificationService.kt @@ -1,23 +1,15 @@ package org.thoughtcrime.securesms.notifications -import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationManagerCompat import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import dagger.hilt.android.AndroidEntryPoint -import org.session.libsession.messaging.jobs.BatchMessageReceiveJob -import org.session.libsession.messaging.jobs.JobQueue -import org.session.libsession.messaging.jobs.MessageReceiveParameters -import org.session.libsession.messaging.utilities.MessageWrapper import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.Log import javax.inject.Inject -private const val TAG = "PushNotificationService" - +private const val TAG = "FirebasePushNotificationService" @AndroidEntryPoint -class PushNotificationService : FirebaseMessagingService() { +class FirebasePushNotificationService : FirebaseMessagingService() { @Inject lateinit var pushManager: PushManager @Inject lateinit var pushHandler: PushHandler @@ -37,7 +29,6 @@ class PushNotificationService : FirebaseMessagingService() { override fun onDeletedMessages() { Log.d(TAG, "Called onDeletedMessages.") - super.onDeletedMessages() pushManager.refresh(true) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt index 9a068f68c3..022d32f170 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt @@ -94,7 +94,7 @@ fun MessageSender.create( // Add the group to the config now that it was successfully created storage.createInitialConfigGroup(groupPublicKey, name, GroupUtil.createConfigMemberMap(members, admins), sentTime, encryptionKeyPair) // Notify the PN server - PushManagerV1.register(publicKey = userPublicKey, device = device) + PushManagerV1.register(device = device, publicKey = userPublicKey) // Start polling ClosedGroupPollerV2.shared.startPolling(groupPublicKey) // Fulfill the promise diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt index 91197649c7..7c5092e5ea 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt @@ -556,7 +556,7 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli // Set expiration timer storage.setExpirationTimer(groupID, expireTimer) // Notify the PN server - PushManagerV1.register(publicKey = userPublicKey, device = MessagingModuleConfiguration.shared.device) + PushManagerV1.register(device = MessagingModuleConfiguration.shared.device, publicKey = userPublicKey) // Notify the user if (userPublicKey == sender && !groupExists) { val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID)) 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 32e5f6b2dc..b8894162d5 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 @@ -27,18 +27,19 @@ object PushManagerV1 { private val server = Server.LEGACY fun register( + device: Device, isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context), token: String? = TextSecurePreferences.getFCMToken(context), publicKey: String? = TextSecurePreferences.getLocalNumber(context), - device: Device, legacyGroupPublicKeys: Collection = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys() ): Promise<*, Exception> = - if (!isUsingFCM) { - emptyPromise() - } else retryIfNeeded(maxRetryCount) { - doRegister(token, publicKey, device, legacyGroupPublicKeys) - } fail { exception -> - Log.d(TAG, "Couldn't register for FCM due to error: $exception.") + when { + isUsingFCM -> retryIfNeeded(maxRetryCount) { + doRegister(token, publicKey, device, legacyGroupPublicKeys) + } fail { exception -> + Log.d(TAG, "Couldn't register for FCM due to error: $exception.") + } + else -> emptyPromise() } private fun doRegister(token: String?, publicKey: String?, device: Device, legacyGroupPublicKeys: Collection): Promise<*, Exception> { @@ -50,7 +51,7 @@ object PushManagerV1 { val parameters = mapOf( "token" to token, "pubKey" to publicKey, - "device" to device, + "device" to device.value, "legacyGroupPublicKeys" to legacyGroupPublicKeys ) diff --git a/libsession/src/main/java/org/session/libsession/utilities/Device.kt b/libsession/src/main/java/org/session/libsession/utilities/Device.kt index 3f8d0d6d5a..c00e0a69dd 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/Device.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/Device.kt @@ -1,6 +1,6 @@ package org.session.libsession.utilities -enum class Device(val value: String) { - ANDROID("android"), +enum class Device(val value: String, val service: String = value) { + ANDROID("android", "firebase"), HUAWEI("huawei"); }