Add persistent account provider history to app preferences

This commit is contained in:
Jenna Vassar
2026-08-03 09:07:48 -07:00
parent 50ff04ac88
commit 21471e07fb
4 changed files with 126 additions and 0 deletions
@@ -16,6 +16,7 @@ import io.element.android.libraries.preferences.api.store.NotificationSound
import io.element.android.libraries.preferences.api.store.NotificationSoundChannelConfig
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.flow.updateAndGet
class InMemoryAppPreferencesStore(
@@ -27,6 +28,7 @@ class InMemoryAppPreferencesStore(
liveLocationMinimumDistanceUpdate: Int = 10,
logLevel: LogLevel = LogLevel.INFO,
traceLogPacks: Set<TraceLogPack> = emptySet(),
homeserverHistory: List<String> = emptyList(),
messageSound: NotificationSound = NotificationSound.SystemDefault,
messageSoundChannelVersion: Int = 0,
messageSoundDisplayName: String? = null,
@@ -40,6 +42,7 @@ class InMemoryAppPreferencesStore(
private val liveLocationMinimumDistanceUpdate = MutableStateFlow(liveLocationMinimumDistanceUpdate)
private val logLevel = MutableStateFlow(logLevel)
private val tracingLogPacks = MutableStateFlow(traceLogPacks)
private val homeserverHistory = MutableStateFlow(homeserverHistory)
private val hideInviteAvatars = MutableStateFlow(hideInviteAvatars)
private val timelineMediaPreviewValue = MutableStateFlow(timelineMediaPreviewValue)
private val messageSound = MutableStateFlow(messageSound)
@@ -117,6 +120,18 @@ class InMemoryAppPreferencesStore(
return tracingLogPacks
}
override fun getHomeserverHistoryFlow(): Flow<List<String>> {
return homeserverHistory
}
override suspend fun addHomeserverToHistory(url: String) {
val normalized = url.trim().lowercase()
if (normalized.isEmpty()) return
homeserverHistory.update { current ->
(listOf(normalized) + current.filter { it != normalized }).take(10)
}
}
override fun getMessageSoundFlow(): Flow<NotificationSound> {
return messageSound
}