cleanup PushNotificationAPI

This commit is contained in:
andrew 2023-06-09 15:56:24 +09:30
parent 3f6229f841
commit 01d80ae54b
5 changed files with 6 additions and 24 deletions

View File

@ -143,7 +143,6 @@ class FirebasePushManager(private val context: Context, private val prefs: TextS
retryIfNeeded(maxRetryCount) { retryIfNeeded(maxRetryCount) {
getResponseBody<UnsubscribeResponse>(request.build()).map { response -> getResponseBody<UnsubscribeResponse>(request.build()).map { response ->
if (response.success == true) { if (response.success == true) {
TextSecurePreferences.setIsUsingFCM(context, false)
TextSecurePreferences.setFCMToken(context, null) TextSecurePreferences.setFCMToken(context, null)
Log.d("Loki", "Unsubscribe FCM success") Log.d("Loki", "Unsubscribe FCM success")
} else { } else {

View File

@ -478,7 +478,7 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli
// Set expiration timer // Set expiration timer
storage.setExpirationTimer(groupID, expireTimer) storage.setExpirationTimer(groupID, expireTimer)
// Notify the PN server // Notify the PN server
PushNotificationAPI.subscribeGroup(groupPublicKey, userPublicKey) PushNotificationAPI.subscribeGroup(groupPublicKey)
// Notify the user // Notify the user
if (userPublicKey == sender && !groupExists) { if (userPublicKey == sender && !groupExists) {
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID)) val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))

View File

@ -59,38 +59,22 @@ object PushNotificationAPI {
fun subscribeGroup( fun subscribeGroup(
closedGroupPublicKey: String, closedGroupPublicKey: String,
publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!! publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!!
) { ) = performGroupOperation(ClosedGroupOperation.Subscribe, closedGroupPublicKey, publicKey)
performGroupOperation(ClosedGroupOperation.Subscribe, closedGroupPublicKey, publicKey)
}
private fun subscribeGroups( private fun subscribeGroups(
closedGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys(), closedGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys(),
publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!! publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!!
) { ) = closedGroupPublicKeys.forEach { performGroupOperation(ClosedGroupOperation.Subscribe, it, publicKey) }
performGroupOperations(ClosedGroupOperation.Subscribe, closedGroupPublicKeys, publicKey)
}
fun unsubscribeGroup( fun unsubscribeGroup(
closedGroupPublicKey: String, closedGroupPublicKey: String,
publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!! publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!!
) { ) = performGroupOperation(ClosedGroupOperation.Unsubscribe, closedGroupPublicKey, publicKey)
performGroupOperation(ClosedGroupOperation.Unsubscribe, closedGroupPublicKey, publicKey)
}
private fun unsubscribeGroups( private fun unsubscribeGroups(
closedGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys(), closedGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys(),
publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!! publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!!
) { ) = closedGroupPublicKeys.forEach { performGroupOperation(ClosedGroupOperation.Unsubscribe, it, publicKey) }
performGroupOperations(ClosedGroupOperation.Unsubscribe, closedGroupPublicKeys, publicKey)
}
private fun performGroupOperations(
operation: ClosedGroupOperation,
closedGroupPublicKeys: Collection<String>,
publicKey: String
) {
closedGroupPublicKeys.forEach { performGroupOperation(operation, it, publicKey) }
}
private fun performGroupOperation( private fun performGroupOperation(
operation: ClosedGroupOperation, operation: ClosedGroupOperation,

View File

@ -986,7 +986,6 @@ interface TextSecurePreferences {
fun clearAll(context: Context) { fun clearAll(context: Context) {
getDefaultSharedPreferences(context).edit().clear().commit() getDefaultSharedPreferences(context).edit().clear().commit()
} }
} }
} }