mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 12:18:25 +00:00
Reinstate push v1
This commit is contained in:
parent
288b70bb14
commit
153aa4ceaa
@ -218,10 +218,6 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
||||
broadcaster = new Broadcaster(this);
|
||||
LokiAPIDatabase apiDB = getDatabaseComponent().lokiAPIDatabase();
|
||||
SnodeModule.Companion.configure(apiDB, broadcaster);
|
||||
String userPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||
if (userPublicKey != null) {
|
||||
registerForPnIfNeeded(false);
|
||||
}
|
||||
initializeExpiringMessageManager();
|
||||
initializeTypingStatusRepository();
|
||||
initializeTypingStatusSender();
|
||||
@ -512,10 +508,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
||||
}
|
||||
|
||||
public void clearAllData(boolean isMigratingToV2KeyPair) {
|
||||
String token = TextSecurePreferences.getFCMToken(this);
|
||||
if (token != null && !token.isEmpty()) {
|
||||
PushNotificationAPI.unregister(token);
|
||||
}
|
||||
PushNotificationAPI.unregister();
|
||||
if (firebaseInstanceIdJob != null && firebaseInstanceIdJob.isActive()) {
|
||||
firebaseInstanceIdJob.cancel(null);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class FirebasePushManager(private val context: Context, private val prefs: TextS
|
||||
if (response.success == true) {
|
||||
Log.d(TAG, "Unsubscribe FCM success")
|
||||
TextSecurePreferences.setFCMToken(context, null)
|
||||
PushNotificationAPI.unregister(token)
|
||||
PushNotificationAPI.unregister()
|
||||
} else {
|
||||
Log.e(TAG, "Couldn't unregister for FCM due to error: ${response.message}")
|
||||
}
|
||||
@ -161,7 +161,10 @@ class FirebasePushManager(private val context: Context, private val prefs: TextS
|
||||
|
||||
val oldToken = TextSecurePreferences.getFCMToken(context)
|
||||
val lastUploadDate = TextSecurePreferences.getLastFCMUploadTime(context)
|
||||
if (!force && token == oldToken && System.currentTimeMillis() - lastUploadDate < tokenExpirationInterval) return
|
||||
// if (!force && token == oldToken && System.currentTimeMillis() - lastUploadDate < tokenExpirationInterval) {
|
||||
// Log.d(TAG, "not registering now... not forced or expired")
|
||||
// return
|
||||
// }
|
||||
|
||||
val pnKey = getOrCreateNotificationKey()
|
||||
|
||||
|
@ -24,7 +24,9 @@ class PushNotificationService : FirebaseMessagingService() {
|
||||
super.onNewToken(token)
|
||||
Log.d("Loki", "New FCM token: $token.")
|
||||
TextSecurePreferences.getLocalNumber(this) ?: return
|
||||
pushManager.refresh(true)
|
||||
if (TextSecurePreferences.getLocalNumber(this) != token) {
|
||||
pushManager.refresh(true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMessageReceived(message: RemoteMessage) {
|
||||
|
@ -29,25 +29,43 @@ object PushNotificationAPI {
|
||||
Unsubscribe("unsubscribe_closed_group");
|
||||
}
|
||||
|
||||
fun register(token: String? = TextSecurePreferences.getFCMToken(context)) {
|
||||
fun register(token: String? = TextSecurePreferences.getLegacyFCMToken(context)) {
|
||||
Log.d(TAG, "register: $token")
|
||||
|
||||
unregisterV1IfRequired()
|
||||
register(token, TextSecurePreferences.getLocalNumber(context))
|
||||
subscribeGroups()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun unregister(token: String) {
|
||||
Log.d(TAG, "unregister: $token")
|
||||
fun register(token: String?, publicKey: String?) {
|
||||
Log.d(TAG, "register($token)")
|
||||
|
||||
unregisterV1IfRequired()
|
||||
unsubscribeGroups()
|
||||
token ?: return
|
||||
publicKey ?: return
|
||||
val parameters = mapOf("token" to token, "pubKey" to publicKey)
|
||||
val url = "$legacyServer/register"
|
||||
val body =
|
||||
RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters))
|
||||
val request = Request.Builder().url(url).post(body)
|
||||
retryIfNeeded(maxRetryCount) {
|
||||
OnionRequestAPI.sendOnionRequest(request.build(), legacyServer, legacyServerPublicKey, Version.V2)
|
||||
.map { response ->
|
||||
val code = response.info["code"] as? Int
|
||||
if (code != null && code != 0) {
|
||||
TextSecurePreferences.setLegacyFCMToken(context, token)
|
||||
} else {
|
||||
Log.d(TAG, "Couldn't register for FCM due to error: ${response.info["message"] as? String ?: "null"}.")
|
||||
}
|
||||
}.fail { exception ->
|
||||
Log.d(TAG, "Couldn't register for FCM due to error: ${exception}.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister push notifications for 1-1 conversations as this is now done in FirebasePushManager.
|
||||
*/
|
||||
private fun unregisterV1IfRequired() {
|
||||
@JvmStatic
|
||||
fun unregister() {
|
||||
val token = TextSecurePreferences.getLegacyFCMToken(context) ?: return
|
||||
|
||||
val parameters = mapOf( "token" to token )
|
||||
@ -56,17 +74,17 @@ object PushNotificationAPI {
|
||||
val request = Request.Builder().url(url).post(body).build()
|
||||
retryIfNeeded(maxRetryCount) {
|
||||
OnionRequestAPI.sendOnionRequest(request, legacyServer, legacyServerPublicKey, Version.V2).map { response ->
|
||||
TextSecurePreferences.clearLegacyFCMToken(context)
|
||||
when (response.info["code"]) {
|
||||
null, 0 -> Log.d(TAG, "Couldn't disable FCM with token: $token due to error: ${response.info["message"]}.")
|
||||
else -> {
|
||||
TextSecurePreferences.clearLegacyFCMToken(context)
|
||||
Log.d(TAG, "unregisterV1 success token: $token")
|
||||
}
|
||||
else -> Log.d(TAG, "unregisterV1 success token: $token")
|
||||
}
|
||||
}.fail { exception ->
|
||||
Log.d(TAG, "Couldn't disable FCM with token: $token due to error: ${exception}.")
|
||||
}
|
||||
}
|
||||
|
||||
unsubscribeGroups()
|
||||
}
|
||||
|
||||
// Legacy Closed Groups
|
||||
@ -110,7 +128,7 @@ object PushNotificationAPI {
|
||||
else -> Log.d(TAG, "performGroupOperation success: ${operation.rawValue}")
|
||||
}
|
||||
}.fail { exception ->
|
||||
Log.d(TAG, "Couldn't ${operation.rawValue}: $closedGroupPublicKey due to error: ${exception}.")
|
||||
Log.d(TAG, "performGroupOperation fail: ${operation.rawValue}: $closedGroupPublicKey due to error: ${exception}.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +318,11 @@ interface TextSecurePreferences {
|
||||
return getStringPreference(context, FCM_TOKEN_LEGACY, "")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setLegacyFCMToken(context: Context, token: String?) {
|
||||
setStringPreference(context, FCM_TOKEN_LEGACY, token)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun clearLegacyFCMToken(context: Context) {
|
||||
removePreference(context, FCM_TOKEN_LEGACY)
|
||||
|
Loading…
x
Reference in New Issue
Block a user