Refactor to accept Huawei token from getToken() and/or onNewToken()
parent
c8dcfbf32c
commit
5a5b2f593f
@ -1,34 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class PushTokenManager @Inject constructor(
|
|
||||||
@ApplicationContext private val context: Context,
|
|
||||||
private val tokenFetcher: TokenFetcher
|
|
||||||
) {
|
|
||||||
private val expiryManager = ExpiryManager(context)
|
|
||||||
|
|
||||||
val isPushEnabled get() = TextSecurePreferences.isPushEnabled(context)
|
|
||||||
|
|
||||||
var fcmToken
|
|
||||||
get() = TextSecurePreferences.getPushToken(context)
|
|
||||||
set(value) {
|
|
||||||
TextSecurePreferences.setPushToken(context, value)
|
|
||||||
if (value != null) markTime() else clearTime()
|
|
||||||
}
|
|
||||||
|
|
||||||
val requiresUnregister get() = fcmToken != null
|
|
||||||
|
|
||||||
private fun clearTime() = expiryManager.clearTime()
|
|
||||||
private fun markTime() = expiryManager.markTime()
|
|
||||||
private fun isExpired() = expiryManager.isExpired()
|
|
||||||
|
|
||||||
fun isInvalid(): Boolean = fcmToken == null || isExpired()
|
|
||||||
fun fetchToken(): Job = tokenFetcher.fetch()
|
|
||||||
}
|
|
@ -1,7 +1,5 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
|
|
||||||
interface TokenFetcher {
|
interface TokenFetcher {
|
||||||
fun fetch(): Job
|
suspend fun fetch(): String?
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue