|
@@ -1,20 +1,13 @@
|
|
|
package org.sirekanyan.outline.repository
|
|
package org.sirekanyan.outline.repository
|
|
|
|
|
|
|
|
-import kotlinx.coroutines.flow.Flow
|
|
|
|
|
-import kotlinx.coroutines.flow.map
|
|
|
|
|
import org.sirekanyan.outline.api.OutlineApi
|
|
import org.sirekanyan.outline.api.OutlineApi
|
|
|
-import org.sirekanyan.outline.api.model.Key
|
|
|
|
|
import org.sirekanyan.outline.api.model.Server
|
|
import org.sirekanyan.outline.api.model.Server
|
|
|
-import org.sirekanyan.outline.api.model.fromEntities
|
|
|
|
|
import org.sirekanyan.outline.api.model.getHost
|
|
import org.sirekanyan.outline.api.model.getHost
|
|
|
-import org.sirekanyan.outline.api.model.toEntities
|
|
|
|
|
-import org.sirekanyan.outline.db.KeyDao
|
|
|
|
|
-import org.sirekanyan.outline.db.model.KeyEntity
|
|
|
|
|
import org.sirekanyan.outline.db.model.ServerEntity
|
|
import org.sirekanyan.outline.db.model.ServerEntity
|
|
|
import org.sirekanyan.outline.ext.logDebug
|
|
import org.sirekanyan.outline.ext.logDebug
|
|
|
import java.util.concurrent.ConcurrentHashMap
|
|
import java.util.concurrent.ConcurrentHashMap
|
|
|
|
|
|
|
|
-class ServerRepository(private val api: OutlineApi, private val keyDao: KeyDao) {
|
|
|
|
|
|
|
+class ServerRepository(private val api: OutlineApi) {
|
|
|
|
|
|
|
|
private val cache: MutableMap<String, Server> = ConcurrentHashMap()
|
|
private val cache: MutableMap<String, Server> = ConcurrentHashMap()
|
|
|
|
|
|
|
@@ -37,14 +30,6 @@ class ServerRepository(private val api: OutlineApi, private val keyDao: KeyDao)
|
|
|
return getCachedServer(server)
|
|
return getCachedServer(server)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun observeKeys(server: ServerEntity): Flow<List<Key>> =
|
|
|
|
|
- keyDao.observe(server).map(List<KeyEntity>::fromEntities)
|
|
|
|
|
-
|
|
|
|
|
- suspend fun updateKeys(server: ServerEntity) {
|
|
|
|
|
- val keys = api.getKeys(server)
|
|
|
|
|
- keyDao.update(server, keys.toEntities(server))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
fun clearCache() {
|
|
fun clearCache() {
|
|
|
cache.clear()
|
|
cache.clear()
|
|
|
}
|
|
}
|