Add resetToken to TokenFetcher (#1009)

* Add resetToken to TokenFetcher

* Remove import
pull/1710/head
SessionHero01 1 month ago committed by GitHub
parent 8aaf985cdd
commit bbdfec3a47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -25,6 +25,12 @@ class HuaweiTokenFetcher @Inject constructor(
this.token.value = token this.token.value = token
} }
override suspend fun resetToken() {
withContext(Dispatchers.Default) {
HmsInstanceId.getInstance(context).deleteToken(APP_ID, TOKEN_SCOPE)
}
}
init { init {
GlobalScope.launch { GlobalScope.launch {
val instanceId = HmsInstanceId.getInstance(context) val instanceId = HmsInstanceId.getInstance(context)
@ -32,6 +38,5 @@ class HuaweiTokenFetcher @Inject constructor(
instanceId.getToken(APP_ID, TOKEN_SCOPE) instanceId.getToken(APP_ID, TOKEN_SCOPE)
} }
} }
} }
} }

@ -40,7 +40,6 @@ import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ProcessLifecycleOwner; import androidx.lifecycle.ProcessLifecycleOwner;
import androidx.work.Configuration; import androidx.work.Configuration;
import com.google.firebase.messaging.FirebaseMessaging;
import com.squareup.phrase.Phrase; import com.squareup.phrase.Phrase;
import org.conscrypt.Conscrypt; import org.conscrypt.Conscrypt;

@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.util
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -15,11 +14,12 @@ import org.thoughtcrime.securesms.dependencies.ConfigFactory
import org.thoughtcrime.securesms.home.HomeActivity import org.thoughtcrime.securesms.home.HomeActivity
import javax.inject.Inject import javax.inject.Inject
import androidx.core.content.edit import androidx.core.content.edit
import kotlinx.coroutines.tasks.await import org.session.libsession.messaging.notifications.TokenFetcher
class ClearDataUtils @Inject constructor( class ClearDataUtils @Inject constructor(
private val application: Application, private val application: Application,
private val configFactory: ConfigFactory, private val configFactory: ConfigFactory,
private val tokenFetcher: TokenFetcher,
) { ) {
// Method to clear the local data - returns true on success otherwise false // Method to clear the local data - returns true on success otherwise false
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
@ -36,9 +36,9 @@ class ClearDataUtils @Inject constructor(
// The token deletion is nice but not critical, so don't let it block the rest of the process // The token deletion is nice but not critical, so don't let it block the rest of the process
runCatching { runCatching {
FirebaseMessaging.getInstance().deleteToken().await() tokenFetcher.resetToken()
}.onFailure { e -> }.onFailure { e ->
Log.w("ClearDataUtils", "Failed to delete Firebase token: ${e.message}", e) Log.w("ClearDataUtils", "Failed to reset push notification token: ${e.message}", e)
} }
} }
} }

@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.notifications
import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.tasks.await
import org.session.libsession.messaging.notifications.TokenFetcher import org.session.libsession.messaging.notifications.TokenFetcher
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -19,4 +20,8 @@ class FirebaseTokenFetcher @Inject constructor(): TokenFetcher {
override fun onNewToken(token: String) { override fun onNewToken(token: String) {
this.token.value = token this.token.value = token
} }
override suspend fun resetToken() {
FirebaseMessaging.getInstance().deleteToken().await()
}
} }

@ -12,4 +12,5 @@ interface TokenFetcher {
val token: StateFlow<String?> val token: StateFlow<String?>
fun onNewToken(token: String) fun onNewToken(token: String)
suspend fun resetToken()
} }

Loading…
Cancel
Save