Refactor: change signature to always have clientSecret first, since it's acting as a key.

This commit is contained in:
Benoit Marty 2024-05-23 00:14:00 +02:00
parent 0a2d87f6b1
commit 4e7f5c46b8
6 changed files with 27 additions and 27 deletions

View file

@ -28,9 +28,9 @@ import javax.inject.Inject
interface UnifiedPushStore {
fun getEndpoint(clientSecret: String): String?
fun storeUpEndpoint(endpoint: String?, clientSecret: String)
fun storeUpEndpoint(clientSecret: String, endpoint: String?)
fun getPushGateway(clientSecret: String): String?
fun storePushGateway(gateway: String?, clientSecret: String)
fun storePushGateway(clientSecret: String, gateway: String?)
fun getDistributorValue(userId: UserId): String?
fun setDistributorValue(userId: UserId, value: String)
}
@ -53,10 +53,10 @@ class DefaultUnifiedPushStore @Inject constructor(
/**
* Store UnifiedPush Endpoint to the SharedPrefs.
*
* @param endpoint the endpoint to store
* @param clientSecret the client secret, to identify the session
* @param endpoint the endpoint to store
*/
override fun storeUpEndpoint(endpoint: String?, clientSecret: String) {
override fun storeUpEndpoint(clientSecret: String, endpoint: String?) {
defaultPrefs.edit {
putString(PREFS_ENDPOINT_OR_TOKEN + clientSecret, endpoint)
}
@ -75,10 +75,10 @@ class DefaultUnifiedPushStore @Inject constructor(
/**
* Store Push Gateway to the SharedPrefs.
*
* @param gateway the push gateway to store
* @param clientSecret the client secret, to identify the session
* @param gateway the push gateway to store
*/
override fun storePushGateway(gateway: String?, clientSecret: String) {
override fun storePushGateway(clientSecret: String, gateway: String?) {
defaultPrefs.edit {
putString(PREFS_PUSH_GATEWAY + clientSecret, gateway)
}

View file

@ -43,8 +43,8 @@ class DefaultUnregisterUnifiedPushUseCase @Inject constructor(
}
return pusherSubscriber.unregisterPusher(matrixClient, endpoint, gateway)
.onSuccess {
unifiedPushStore.storeUpEndpoint(null, clientSecret)
unifiedPushStore.storePushGateway(null, clientSecret)
unifiedPushStore.storeUpEndpoint(clientSecret, null)
unifiedPushStore.storePushGateway(clientSecret, null)
UnifiedPush.unregisterApp(context)
}
}

View file

@ -73,13 +73,13 @@ class VectorUnifiedPushMessagingReceiver : MessagingReceiver() {
Timber.tag(loggerTag.value).i("onNewEndpoint: $endpoint")
coroutineScope.launch {
val gateway = unifiedPushGatewayResolver.getGateway(endpoint)
unifiedPushStore.storePushGateway(gateway, instance)
unifiedPushStore.storePushGateway(instance, gateway)
val result = newGatewayHandler.handle(endpoint, gateway, instance)
.onFailure {
Timber.tag(loggerTag.value).e(it, "Failed to handle new gateway")
}
.onSuccess {
unifiedPushStore.storeUpEndpoint(endpoint, instance)
unifiedPushStore.storeUpEndpoint(instance, endpoint)
}
endpointRegistrationHandler.registrationDone(
RegistrationResult(