Tries to avoid crash when lacking google services in the play version.
This commit is contained in:
+10
-5
@@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.service.notifications
|
package com.vitorpamplona.amethyst.service.notifications
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import com.google.firebase.messaging.FirebaseMessaging
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
import com.vitorpamplona.amethyst.AccountInfo
|
import com.vitorpamplona.amethyst.AccountInfo
|
||||||
import com.vitorpamplona.amethyst.service.retryIfException
|
import com.vitorpamplona.amethyst.service.retryIfException
|
||||||
@@ -35,12 +36,16 @@ object PushNotificationUtils {
|
|||||||
accounts: List<AccountInfo>,
|
accounts: List<AccountInfo>,
|
||||||
okHttpClient: (String) -> OkHttpClient,
|
okHttpClient: (String) -> OkHttpClient,
|
||||||
) = with(Dispatchers.IO) {
|
) = with(Dispatchers.IO) {
|
||||||
val token = FirebaseMessaging.getInstance().token.await()
|
try {
|
||||||
if (hasInit?.equals(accounts) == true && lastToken == token) {
|
val token = FirebaseMessaging.getInstance().token.await()
|
||||||
return@with
|
if (hasInit?.equals(accounts) == true && lastToken == token) {
|
||||||
}
|
return@with
|
||||||
|
}
|
||||||
|
|
||||||
registerToken(token, accounts, okHttpClient)
|
registerToken(token, accounts, okHttpClient)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("PushNotificationUtils", "Failed to get Firebase token", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun checkAndInit(
|
suspend fun checkAndInit(
|
||||||
|
|||||||
Reference in New Issue
Block a user