|
|
@ -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() |
|
|
|
} |
|
|
|
} |
|
|
|