All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.net.folivo.trixnity.client.store.RoomStore.kt Maven / Gradle / Ivy

There is a newer version: 4.7.1
Show newest version
package net.folivo.trixnity.client.store

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import net.folivo.trixnity.client.MatrixClientConfiguration
import net.folivo.trixnity.client.store.cache.FullRepositoryObservableCache
import net.folivo.trixnity.client.store.repository.RepositoryTransactionManager
import net.folivo.trixnity.client.store.repository.RoomRepository
import net.folivo.trixnity.core.model.RoomId

class RoomStore(
    roomRepository: RoomRepository,
    tm: RepositoryTransactionManager,
    storeScope: CoroutineScope,
    config: MatrixClientConfiguration,
) : Store {
    private val roomCache =
        FullRepositoryObservableCache(roomRepository, tm, storeScope, config.cacheExpireDurations.room) { it.roomId }

    override suspend fun clearCache() = deleteAll()

    override suspend fun deleteAll() {
        roomCache.deleteAll()
    }

    fun getAll(): Flow>> = roomCache.readAll()

    fun get(roomId: RoomId): Flow = roomCache.read(roomId)

    suspend fun update(roomId: RoomId, updater: suspend (oldRoom: Room?) -> Room?) =
        roomCache.write(roomId, updater = updater)

    suspend fun delete(roomId: RoomId) =
        roomCache.write(roomId, null)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy