Push distributor: ensure the current UnifiedPush distributor is stored
This commit is contained in:
parent
56ca04affa
commit
d2fbff09b8
8 changed files with 68 additions and 8 deletions
|
|
@ -61,6 +61,12 @@ class UnifiedPushProvider @Inject constructor(
|
|||
override suspend fun registerWith(matrixClient: MatrixClient, distributor: Distributor) {
|
||||
val clientSecret = pushClientSecret.getSecretForUser(matrixClient.sessionId)
|
||||
registerUnifiedPushUseCase.execute(matrixClient, distributor, clientSecret)
|
||||
unifiedPushStore.setDistributorValue(matrixClient.sessionId, distributor.value)
|
||||
}
|
||||
|
||||
override suspend fun getCurrentDistributor(matrixClient: MatrixClient): Distributor? {
|
||||
val distributorValue = unifiedPushStore.getDistributorValue(matrixClient.sessionId)
|
||||
return getDistributors().find { it.value == distributorValue }
|
||||
}
|
||||
|
||||
override suspend fun unregister(matrixClient: MatrixClient) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import android.content.SharedPreferences
|
|||
import androidx.core.content.edit
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.di.DefaultPreferences
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import javax.inject.Inject
|
||||
|
||||
class UnifiedPushStore @Inject constructor(
|
||||
|
|
@ -71,8 +72,19 @@ class UnifiedPushStore @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun getDistributorValue(userId: UserId): String? {
|
||||
return defaultPrefs.getString(PREFS_DISTRIBUTOR + userId, null)
|
||||
}
|
||||
|
||||
fun setDistributorValue(userId: UserId, value: String) {
|
||||
defaultPrefs.edit {
|
||||
putString(PREFS_DISTRIBUTOR + userId, value)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PREFS_ENDPOINT_OR_TOKEN = "UP_ENDPOINT_OR_TOKEN"
|
||||
private const val PREFS_PUSH_GATEWAY = "PUSH_GATEWAY"
|
||||
private const val PREFS_DISTRIBUTOR = "DISTRIBUTOR"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue