diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt index 1928e3f4d7..20d8e52631 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiTokenFetcher.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.session.libsession.messaging.notifications.TokenFetcher +import org.session.libsignal.utilities.Log import javax.inject.Inject import javax.inject.Singleton @@ -33,9 +34,13 @@ class HuaweiTokenFetcher @Inject constructor( init { GlobalScope.launch { - val instanceId = HmsInstanceId.getInstance(context) - withContext(Dispatchers.Default) { - instanceId.getToken(APP_ID, TOKEN_SCOPE) + try { + val instanceId = HmsInstanceId.getInstance(context) + withContext(Dispatchers.Default) { + instanceId.getToken(APP_ID, TOKEN_SCOPE) + } + } catch (e: Exception) { + Log.e("HuaweiTokenFetcher", "Failed to fetch token", e) } } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt index bed4f6f528..d99379f877 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt @@ -107,21 +107,20 @@ class Poller( Log.d(TAG, "Polling...") isPolling = true + var pollDelay = RETRY_INTERVAL_MS + try { + // check if the polling pool is empty + if (pollPool.isEmpty()){ + // if it is empty, fill it with the snodes from our swarm + pollPool.addAll(SnodeAPI.getSwarm(userPublicKey).await()) + } - // check if the polling pool is empty - if(pollPool.isEmpty()){ - // if it is empty, fill it with the snodes from our swarm - pollPool.addAll(SnodeAPI.getSwarm(userPublicKey).await()) - } - - // randomly get a snode from the pool - val currentNode = pollPool.random() + // randomly get a snode from the pool + val currentNode = pollPool.random() - // remove that snode from the pool - pollPool.remove(currentNode) + // remove that snode from the pool + pollPool.remove(currentNode) - var pollDelay = RETRY_INTERVAL_MS - try { poll(currentNode) retryScalingFactor = 1f } catch (e: Exception){