mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-08 11:29:25 +00:00
Store legacy fcm token to reduce unregister api calls
This commit is contained in:
parent
b2a1b5fe46
commit
288b70bb14
@ -32,7 +32,7 @@ object PushNotificationAPI {
|
||||
fun register(token: String? = TextSecurePreferences.getFCMToken(context)) {
|
||||
Log.d(TAG, "register: $token")
|
||||
|
||||
token?.let(::unregisterV1)
|
||||
unregisterV1IfRequired()
|
||||
subscribeGroups()
|
||||
}
|
||||
|
||||
@ -40,11 +40,16 @@ object PushNotificationAPI {
|
||||
fun unregister(token: String) {
|
||||
Log.d(TAG, "unregister: $token")
|
||||
|
||||
unregisterV1(token)
|
||||
unregisterV1IfRequired()
|
||||
unsubscribeGroups()
|
||||
}
|
||||
|
||||
private fun unregisterV1(token: String) {
|
||||
/**
|
||||
* Unregister push notifications for 1-1 conversations as this is now done in FirebasePushManager.
|
||||
*/
|
||||
private fun unregisterV1IfRequired() {
|
||||
val token = TextSecurePreferences.getLegacyFCMToken(context) ?: return
|
||||
|
||||
val parameters = mapOf( "token" to token )
|
||||
val url = "$legacyServer/unregister"
|
||||
val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters))
|
||||
@ -53,7 +58,10 @@ object PushNotificationAPI {
|
||||
OnionRequestAPI.sendOnionRequest(request, legacyServer, legacyServerPublicKey, Version.V2).map { response ->
|
||||
when (response.info["code"]) {
|
||||
null, 0 -> Log.d(TAG, "Couldn't disable FCM with token: $token due to error: ${response.info["message"]}.")
|
||||
else -> Log.d(TAG, "unregisterV1 success token: $token")
|
||||
else -> {
|
||||
TextSecurePreferences.clearLegacyFCMToken(context)
|
||||
Log.d(TAG, "unregisterV1 success token: $token")
|
||||
}
|
||||
}
|
||||
}.fail { exception ->
|
||||
Log.d(TAG, "Couldn't disable FCM with token: $token due to error: ${exception}.")
|
||||
|
@ -250,7 +250,8 @@ interface TextSecurePreferences {
|
||||
const val GIF_METADATA_WARNING = "has_seen_gif_metadata_warning"
|
||||
const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
|
||||
const val IS_USING_FCM = "pref_is_using_fcm"
|
||||
const val FCM_TOKEN = "pref_fcm_token"
|
||||
const val FCM_TOKEN_LEGACY = "pref_fcm_token"
|
||||
const val FCM_TOKEN = "pref_fcm_token_2"
|
||||
const val LAST_FCM_TOKEN_UPLOAD_TIME = "pref_last_fcm_token_upload_time_2"
|
||||
const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
|
||||
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
|
||||
@ -312,6 +313,16 @@ interface TextSecurePreferences {
|
||||
setBooleanPreference(context, IS_USING_FCM, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getLegacyFCMToken(context: Context): String? {
|
||||
return getStringPreference(context, FCM_TOKEN_LEGACY, "")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun clearLegacyFCMToken(context: Context) {
|
||||
removePreference(context, FCM_TOKEN_LEGACY)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getFCMToken(context: Context): String? {
|
||||
return getStringPreference(context, FCM_TOKEN, "")
|
||||
|
Loading…
x
Reference in New Issue
Block a user