Merge branch 'fix/removing-ad-id' of https://github.com/oxen-io/session-android into fix/removing-ad-id
commit
fe1fe2e109
@ -1,19 +1,19 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import com.google.android.gms.tasks.Tasks
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
import com.google.firebase.iid.FirebaseInstanceId
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
|
import kotlinx.coroutines.tasks.await
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class FirebaseTokenFetcher @Inject constructor(): TokenFetcher {
|
class FirebaseTokenFetcher @Inject constructor(): TokenFetcher {
|
||||||
|
val TAG = "FirebaseTF"
|
||||||
|
|
||||||
override suspend fun fetch() = withContext(Dispatchers.IO) {
|
override suspend fun fetch() = withContext(Dispatchers.IO) {
|
||||||
FirebaseInstanceId.getInstance().instanceId
|
FirebaseMessaging.getInstance().token.await().takeIf { isActive } ?: throw Exception("Firebase token is null")
|
||||||
.also(Tasks::await)
|
|
||||||
.takeIf { isActive } // don't 'complete' task if we were canceled
|
|
||||||
?.run { result?.token ?: throw exception!! }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue