mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-30 23:50:46 +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)) {
|
fun register(token: String? = TextSecurePreferences.getFCMToken(context)) {
|
||||||
Log.d(TAG, "register: $token")
|
Log.d(TAG, "register: $token")
|
||||||
|
|
||||||
token?.let(::unregisterV1)
|
unregisterV1IfRequired()
|
||||||
subscribeGroups()
|
subscribeGroups()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,11 +40,16 @@ object PushNotificationAPI {
|
|||||||
fun unregister(token: String) {
|
fun unregister(token: String) {
|
||||||
Log.d(TAG, "unregister: $token")
|
Log.d(TAG, "unregister: $token")
|
||||||
|
|
||||||
unregisterV1(token)
|
unregisterV1IfRequired()
|
||||||
unsubscribeGroups()
|
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 parameters = mapOf( "token" to token )
|
||||||
val url = "$legacyServer/unregister"
|
val url = "$legacyServer/unregister"
|
||||||
val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters))
|
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 ->
|
OnionRequestAPI.sendOnionRequest(request, legacyServer, legacyServerPublicKey, Version.V2).map { response ->
|
||||||
when (response.info["code"]) {
|
when (response.info["code"]) {
|
||||||
null, 0 -> Log.d(TAG, "Couldn't disable FCM with token: $token due to error: ${response.info["message"]}.")
|
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 ->
|
}.fail { exception ->
|
||||||
Log.d(TAG, "Couldn't disable FCM with token: $token due to error: ${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_METADATA_WARNING = "has_seen_gif_metadata_warning"
|
||||||
const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
|
const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
|
||||||
const val IS_USING_FCM = "pref_is_using_fcm"
|
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_FCM_TOKEN_UPLOAD_TIME = "pref_last_fcm_token_upload_time_2"
|
||||||
const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
|
const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
|
||||||
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
|
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
|
||||||
@ -312,6 +313,16 @@ interface TextSecurePreferences {
|
|||||||
setBooleanPreference(context, IS_USING_FCM, value)
|
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
|
@JvmStatic
|
||||||
fun getFCMToken(context: Context): String? {
|
fun getFCMToken(context: Context): String? {
|
||||||
return getStringPreference(context, FCM_TOKEN, "")
|
return getStringPreference(context, FCM_TOKEN, "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user