mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Fix individual group subs
This commit is contained in:
parent
42cfce0c3e
commit
e3f60eb5f2
@ -73,7 +73,7 @@ class FirebasePushManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refresh(token: String, force: Boolean): Promise<*, Exception> {
|
private fun refresh(token: String, force: Boolean): Promise<*, Exception> {
|
||||||
Log.d(TAG, "refresh() called with: token = $token, force = $force")
|
Log.d(TAG, "refresh() called")
|
||||||
|
|
||||||
val userPublicKey = getLocalNumber(context) ?: return emptyPromise()
|
val userPublicKey = getLocalNumber(context) ?: return emptyPromise()
|
||||||
val userEdKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return emptyPromise()
|
val userEdKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return emptyPromise()
|
||||||
@ -109,7 +109,10 @@ class FirebasePushManager(
|
|||||||
publicKey: String,
|
publicKey: String,
|
||||||
userEd25519Key: KeyPair,
|
userEd25519Key: KeyPair,
|
||||||
namespaces: List<Int> = listOf(Namespace.DEFAULT)
|
namespaces: List<Int> = listOf(Namespace.DEFAULT)
|
||||||
): Promise<*, Exception> = PushManagerV1.register(token, publicKey) and pushManagerV2.register(
|
): Promise<*, Exception> = PushManagerV1.register(
|
||||||
|
token = token,
|
||||||
|
publicKey = publicKey
|
||||||
|
) and pushManagerV2.register(
|
||||||
token, publicKey, userEd25519Key, namespaces
|
token, publicKey, userEd25519Key, namespaces
|
||||||
) fail {
|
) fail {
|
||||||
Log.e(TAG, "Couldn't register for FCM due to error: $it.", it)
|
Log.e(TAG, "Couldn't register for FCM due to error: $it.", it)
|
||||||
|
@ -24,7 +24,6 @@ class PushNotificationService : FirebaseMessagingService() {
|
|||||||
|
|
||||||
override fun onNewToken(token: String) {
|
override fun onNewToken(token: String) {
|
||||||
super.onNewToken(token)
|
super.onNewToken(token)
|
||||||
Log.d(TAG, "New FCM token: $token.")
|
|
||||||
TextSecurePreferences.getLocalNumber(this) ?: return
|
TextSecurePreferences.getLocalNumber(this) ?: return
|
||||||
if (TextSecurePreferences.getFCMToken(this) != token) {
|
if (TextSecurePreferences.getFCMToken(this) != token) {
|
||||||
pushManager.refresh(true)
|
pushManager.refresh(true)
|
||||||
@ -69,6 +68,6 @@ class PushNotificationService : FirebaseMessagingService() {
|
|||||||
override fun onDeletedMessages() {
|
override fun onDeletedMessages() {
|
||||||
Log.d(TAG, "Called onDeletedMessages.")
|
Log.d(TAG, "Called onDeletedMessages.")
|
||||||
super.onDeletedMessages()
|
super.onDeletedMessages()
|
||||||
PushManagerV1.register()
|
pushManager.refresh(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -772,7 +772,7 @@ fun MessageReceiver.disableLocalGroupAndUnsubscribe(groupPublicKey: String, grou
|
|||||||
storage.setActive(groupID, false)
|
storage.setActive(groupID, false)
|
||||||
storage.removeMember(groupID, Address.fromSerialized(userPublicKey))
|
storage.removeMember(groupID, Address.fromSerialized(userPublicKey))
|
||||||
// Notify the PN server
|
// Notify the PN server
|
||||||
PushManagerV1.register(publicKey = userPublicKey)
|
PushManagerV1.unsubscribeGroup(groupPublicKey, publicKey = userPublicKey)
|
||||||
// Stop polling
|
// Stop polling
|
||||||
ClosedGroupPollerV2.shared.stopPolling(groupPublicKey)
|
ClosedGroupPollerV2.shared.stopPolling(groupPublicKey)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import org.session.libsignal.utilities.JsonUtil
|
|||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import org.session.libsignal.utilities.emptyPromise
|
import org.session.libsignal.utilities.emptyPromise
|
||||||
import org.session.libsignal.utilities.retryIfNeeded
|
import org.session.libsignal.utilities.retryIfNeeded
|
||||||
|
import org.session.libsignal.utilities.sideEffect
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
object PushManagerV1 {
|
object PushManagerV1 {
|
||||||
@ -27,12 +28,14 @@ object PushManagerV1 {
|
|||||||
private const val maxRetryCount = 4
|
private const val maxRetryCount = 4
|
||||||
|
|
||||||
fun register(
|
fun register(
|
||||||
|
isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context),
|
||||||
token: String? = TextSecurePreferences.getFCMToken(context),
|
token: String? = TextSecurePreferences.getFCMToken(context),
|
||||||
publicKey: String? = TextSecurePreferences.getLocalNumber(context),
|
publicKey: String? = TextSecurePreferences.getLocalNumber(context),
|
||||||
legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
|
legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
|
||||||
): Promise<*, Exception> =
|
): Promise<*, Exception> =
|
||||||
retryIfNeeded(maxRetryCount) {
|
retryIfNeeded(maxRetryCount) {
|
||||||
doRegister(token, publicKey, legacyGroupPublicKeys)
|
if (isUsingFCM) doRegister(token, publicKey, legacyGroupPublicKeys)
|
||||||
|
else emptyPromise()
|
||||||
} fail { exception ->
|
} fail { exception ->
|
||||||
Log.d(TAG, "Couldn't register for FCM due to error: ${exception}.")
|
Log.d(TAG, "Couldn't register for FCM due to error: ${exception}.")
|
||||||
} success {
|
} success {
|
||||||
@ -40,13 +43,11 @@ object PushManagerV1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun doRegister(token: String?, publicKey: String?, legacyGroupPublicKeys: Collection<String>): Promise<*, Exception> {
|
private fun doRegister(token: String?, publicKey: String?, legacyGroupPublicKeys: Collection<String>): Promise<*, Exception> {
|
||||||
Log.d(TAG, "doRegister() called $token, $publicKey, $legacyGroupPublicKeys")
|
Log.d(TAG, "doRegister() called")
|
||||||
|
|
||||||
token ?: return emptyPromise()
|
token ?: return emptyPromise()
|
||||||
publicKey ?: return emptyPromise()
|
publicKey ?: return emptyPromise()
|
||||||
legacyGroupPublicKeys.takeIf { it.isNotEmpty() } ?: return emptyPromise()
|
legacyGroupPublicKeys.takeIf { it.isNotEmpty() } ?: return unregister()
|
||||||
|
|
||||||
Log.d(TAG, "actually registering...")
|
|
||||||
|
|
||||||
val parameters = mapOf(
|
val parameters = mapOf(
|
||||||
"token" to token,
|
"token" to token,
|
||||||
@ -63,10 +64,6 @@ object PushManagerV1 {
|
|||||||
null, 0 -> throw Exception("error: ${response.info["message"]}.")
|
null, 0 -> throw Exception("error: ${response.info["message"]}.")
|
||||||
else -> Log.d(TAG, "register() success!!")
|
else -> Log.d(TAG, "register() success!!")
|
||||||
}
|
}
|
||||||
} success {
|
|
||||||
Log.d(TAG, "onion request success")
|
|
||||||
} fail {
|
|
||||||
Log.d(TAG, "onion fail: $it")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,14 +87,10 @@ object PushManagerV1 {
|
|||||||
legacyServerPublicKey,
|
legacyServerPublicKey,
|
||||||
Version.V2
|
Version.V2
|
||||||
) success {
|
) success {
|
||||||
Log.d(TAG, "unregister() success!!")
|
|
||||||
|
|
||||||
when (it.info["code"]) {
|
when (it.info["code"]) {
|
||||||
null, 0 -> throw Exception("error: ${it.info["message"]}.")
|
null, 0 -> throw Exception("error: ${it.info["message"]}.")
|
||||||
else -> Log.d(TAG, "unregisterV1 success token: $token")
|
else -> Log.d(TAG, "unregisterV1 success")
|
||||||
}
|
}
|
||||||
} fail {
|
|
||||||
Log.d(TAG, "Couldn't disable FCM with token: $token due to error: $it.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,13 +123,10 @@ object PushManagerV1 {
|
|||||||
legacyServer,
|
legacyServer,
|
||||||
legacyServerPublicKey,
|
legacyServerPublicKey,
|
||||||
Version.V2
|
Version.V2
|
||||||
) success {
|
) sideEffect {
|
||||||
when (it.info["code"]) {
|
when (it.info["code"]) {
|
||||||
null, 0 -> throw Exception("${it.info["message"]}")
|
0, null -> throw Exception("${it.info["message"]}")
|
||||||
else -> Log.d(TAG, "performGroupOperation success: $operation")
|
|
||||||
}
|
}
|
||||||
} fail { exception ->
|
|
||||||
Log.d(TAG, "performGroupOperation fail: $operation: $closedGroupPublicKey due to error: ${exception}.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.session.libsignal.utilities
|
|||||||
|
|
||||||
import nl.komponents.kovenant.Promise
|
import nl.komponents.kovenant.Promise
|
||||||
import nl.komponents.kovenant.deferred
|
import nl.komponents.kovenant.deferred
|
||||||
|
import nl.komponents.kovenant.functional.map
|
||||||
import nl.komponents.kovenant.task
|
import nl.komponents.kovenant.task
|
||||||
import java.util.concurrent.TimeoutException
|
import java.util.concurrent.TimeoutException
|
||||||
|
|
||||||
@ -59,3 +60,10 @@ fun <V> Promise<V, Exception>.timeout(millis: Long): Promise<V, Exception> {
|
|||||||
}
|
}
|
||||||
return deferred.promise
|
return deferred.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infix fun <V, E: Exception> Promise<V, E>.sideEffect(
|
||||||
|
callback: (value: V) -> Unit
|
||||||
|
) = map {
|
||||||
|
callback(it)
|
||||||
|
it
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user