SessionPreferencesStore: add entries for sharePresence, renderReadReceipts, sendTypingNotifications, renderTypingNotifications.
`sharePresence` should take existing value of `sendPublicReadReceipts`, which has been added first.
This commit is contained in:
parent
52c47b1c14
commit
b987397b79
3 changed files with 76 additions and 2 deletions
|
|
@ -19,8 +19,20 @@ package io.element.android.features.preferences.api.store
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface SessionPreferencesStore {
|
interface SessionPreferencesStore {
|
||||||
|
suspend fun setSharePresence(enabled: Boolean)
|
||||||
|
fun isSharePresenceEnabled(): Flow<Boolean>
|
||||||
|
|
||||||
suspend fun setSendPublicReadReceipts(enabled: Boolean)
|
suspend fun setSendPublicReadReceipts(enabled: Boolean)
|
||||||
fun isSendPublicReadReceiptsEnabled(): Flow<Boolean>
|
fun isSendPublicReadReceiptsEnabled(): Flow<Boolean>
|
||||||
|
|
||||||
|
suspend fun setRenderReadReceipts(enabled: Boolean)
|
||||||
|
fun isRenderReadReceiptsEnabled(): Flow<Boolean>
|
||||||
|
|
||||||
|
suspend fun setSendTypingNotifications(enabled: Boolean)
|
||||||
|
fun isSendTypingNotificationsEnabled(): Flow<Boolean>
|
||||||
|
|
||||||
|
suspend fun setRenderTypingNotifications(enabled: Boolean)
|
||||||
|
fun isRenderTypingNotificationsEnabled(): Flow<Boolean>
|
||||||
|
|
||||||
suspend fun clear()
|
suspend fun clear()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@ import io.element.android.libraries.di.annotations.SessionCoroutineScope
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class DefaultSessionPreferencesStore(
|
class DefaultSessionPreferencesStore(
|
||||||
|
|
@ -43,14 +45,43 @@ class DefaultSessionPreferencesStore(
|
||||||
return context.preferencesDataStoreFile("session_${hashedUserId}_preferences")
|
return context.preferencesDataStoreFile("session_${hashedUserId}_preferences")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val sharePresenceKey = booleanPreferencesKey("sharePresence")
|
||||||
private val sendPublicReadReceiptsKey = booleanPreferencesKey("sendPublicReadReceipts")
|
private val sendPublicReadReceiptsKey = booleanPreferencesKey("sendPublicReadReceipts")
|
||||||
|
private val renderReadReceiptsKey = booleanPreferencesKey("renderReadReceipts")
|
||||||
|
private val sendTypingNotificationsKey = booleanPreferencesKey("sendTypingNotifications")
|
||||||
|
private val renderTypingNotificationsKey = booleanPreferencesKey("renderTypingNotifications")
|
||||||
|
|
||||||
private val dataStoreFile = storeFile(context, sessionId)
|
private val dataStoreFile = storeFile(context, sessionId)
|
||||||
private val store = PreferenceDataStoreFactory.create(scope = sessionCoroutineScope) { dataStoreFile }
|
private val store = PreferenceDataStoreFactory.create(scope = sessionCoroutineScope) { dataStoreFile }
|
||||||
|
|
||||||
|
override suspend fun setSharePresence(enabled: Boolean) {
|
||||||
|
update(sharePresenceKey, enabled)
|
||||||
|
// Also update all the other settings
|
||||||
|
setSendPublicReadReceipts(enabled)
|
||||||
|
setRenderReadReceipts(enabled)
|
||||||
|
setSendTypingNotifications(enabled)
|
||||||
|
setRenderTypingNotifications(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSharePresenceEnabled(): Flow<Boolean> {
|
||||||
|
// Migration, if sendPublicReadReceiptsKey was false, consider that sharing presence is false.
|
||||||
|
val defaultValue = runBlocking { isSendPublicReadReceiptsEnabled().first() }
|
||||||
|
return get(sharePresenceKey, defaultValue)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun setSendPublicReadReceipts(enabled: Boolean) = update(sendPublicReadReceiptsKey, enabled)
|
override suspend fun setSendPublicReadReceipts(enabled: Boolean) = update(sendPublicReadReceiptsKey, enabled)
|
||||||
override fun isSendPublicReadReceiptsEnabled(): Flow<Boolean> = get(sendPublicReadReceiptsKey, true)
|
override fun isSendPublicReadReceiptsEnabled(): Flow<Boolean> = get(sendPublicReadReceiptsKey, true)
|
||||||
|
|
||||||
|
override suspend fun setRenderReadReceipts(enabled: Boolean) = update(renderReadReceiptsKey, enabled)
|
||||||
|
override fun isRenderReadReceiptsEnabled(): Flow<Boolean> = get(renderReadReceiptsKey, true)
|
||||||
|
|
||||||
|
override suspend fun setSendTypingNotifications(enabled: Boolean) = update(sendTypingNotificationsKey, enabled)
|
||||||
|
override fun isSendTypingNotificationsEnabled(): Flow<Boolean> = get(sendTypingNotificationsKey, true)
|
||||||
|
|
||||||
|
override suspend fun setRenderTypingNotifications(enabled: Boolean) = update(renderTypingNotificationsKey, enabled)
|
||||||
|
override fun isRenderTypingNotificationsEnabled(): Flow<Boolean> = get(renderTypingNotificationsKey, true)
|
||||||
|
|
||||||
override suspend fun clear() {
|
override suspend fun clear() {
|
||||||
dataStoreFile.safeDelete()
|
dataStoreFile.safeDelete()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,50 @@ import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
class InMemorySessionPreferencesStore(
|
class InMemorySessionPreferencesStore(
|
||||||
|
isSharePresenceEnabled: Boolean = true,
|
||||||
isSendPublicReadReceiptsEnabled: Boolean = true,
|
isSendPublicReadReceiptsEnabled: Boolean = true,
|
||||||
|
isRenderReadReceiptsEnabled: Boolean = true,
|
||||||
|
isSendTypingNotificationsEnabled: Boolean = true,
|
||||||
|
isRenderTypingNotificationsEnabled: Boolean = true,
|
||||||
) : SessionPreferencesStore {
|
) : SessionPreferencesStore {
|
||||||
|
private val isSharePresenceEnabled = MutableStateFlow(isSharePresenceEnabled)
|
||||||
private val isSendPublicReadReceiptsEnabled = MutableStateFlow(isSendPublicReadReceiptsEnabled)
|
private val isSendPublicReadReceiptsEnabled = MutableStateFlow(isSendPublicReadReceiptsEnabled)
|
||||||
|
private val isRenderReadReceiptsEnabled = MutableStateFlow(isRenderReadReceiptsEnabled)
|
||||||
|
private val isSendTypingNotificationsEnabled = MutableStateFlow(isSendTypingNotificationsEnabled)
|
||||||
|
private val isRenderTypingNotificationsEnabled = MutableStateFlow(isRenderTypingNotificationsEnabled)
|
||||||
var clearCallCount = 0
|
var clearCallCount = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
override suspend fun setSharePresence(enabled: Boolean) {
|
||||||
|
isSharePresenceEnabled.tryEmit(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSharePresenceEnabled(): Flow<Boolean> = isSharePresenceEnabled
|
||||||
|
|
||||||
override suspend fun setSendPublicReadReceipts(enabled: Boolean) {
|
override suspend fun setSendPublicReadReceipts(enabled: Boolean) {
|
||||||
isSendPublicReadReceiptsEnabled.tryEmit(enabled)
|
isSendPublicReadReceiptsEnabled.tryEmit(enabled)
|
||||||
}
|
}
|
||||||
override fun isSendPublicReadReceiptsEnabled(): Flow<Boolean> {
|
|
||||||
return isSendPublicReadReceiptsEnabled
|
override fun isSendPublicReadReceiptsEnabled(): Flow<Boolean> = isSendPublicReadReceiptsEnabled
|
||||||
|
|
||||||
|
override suspend fun setRenderReadReceipts(enabled: Boolean) {
|
||||||
|
isRenderReadReceiptsEnabled.tryEmit(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isRenderReadReceiptsEnabled(): Flow<Boolean> = isRenderReadReceiptsEnabled
|
||||||
|
|
||||||
|
override suspend fun setSendTypingNotifications(enabled: Boolean) {
|
||||||
|
isSendTypingNotificationsEnabled.tryEmit(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSendTypingNotificationsEnabled(): Flow<Boolean> = isSendTypingNotificationsEnabled
|
||||||
|
|
||||||
|
override suspend fun setRenderTypingNotifications(enabled: Boolean) {
|
||||||
|
isRenderTypingNotificationsEnabled.tryEmit(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isRenderTypingNotificationsEnabled(): Flow<Boolean> = isRenderTypingNotificationsEnabled
|
||||||
|
|
||||||
override suspend fun clear() {
|
override suspend fun clear() {
|
||||||
clearCallCount++
|
clearCallCount++
|
||||||
isSendPublicReadReceiptsEnabled.tryEmit(true)
|
isSendPublicReadReceiptsEnabled.tryEmit(true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue