UnifiedPush WIP

This commit is contained in:
Benoit Marty 2023-04-11 11:19:44 +02:00 committed by Benoit Marty
parent adfcd61287
commit 95bafe4059
33 changed files with 376 additions and 215 deletions

View file

@ -20,12 +20,9 @@ package io.element.android.libraries.pushstore.api
* Store data related to push about a user.
*/
interface UserPushStore {
/**
* [NOTIFICATION_METHOD_FIREBASE] or [NOTIFICATION_METHOD_UNIFIEDPUSH].
*/
suspend fun getNotificationMethod(): String?
suspend fun getPushProviderName(): String?
suspend fun setNotificationMethod(value: String)
suspend fun setPushProviderName(value: String)
suspend fun getCurrentRegisteredPushKey(): String?

View file

@ -33,16 +33,16 @@ class UserPushStoreDataStore(
userId: String,
) : UserPushStore {
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "push_store_$userId")
private val notificationMethod = stringPreferencesKey("notificationMethod")
private val pushProviderName = stringPreferencesKey("pushProviderName")
private val currentPushKey = stringPreferencesKey("currentPushKey")
override suspend fun getNotificationMethod(): String? {
return context.dataStore.data.first()[notificationMethod]
override suspend fun getPushProviderName(): String? {
return context.dataStore.data.first()[pushProviderName]
}
override suspend fun setNotificationMethod(value: String) {
override suspend fun setPushProviderName(value: String) {
context.dataStore.edit {
it[notificationMethod] = value
it[pushProviderName] = value
}
}