Commit 465a8596 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add missing parameters.

parent 0102cdc3
......@@ -25,6 +25,7 @@ import chat.rocket.android.util.retryDB
import chat.rocket.common.model.BaseRoom
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.SimpleUser
import chat.rocket.common.model.Token
import chat.rocket.common.model.User
import chat.rocket.core.internal.model.Subscription
import chat.rocket.core.internal.realtime.socket.model.StreamMessage
......@@ -51,8 +52,7 @@ import kotlin.collections.component2
import kotlin.collections.set
import kotlin.system.measureTimeMillis
class DatabaseManager(val context: Application, val serverUrl: String) {
class DatabaseManager(val context: Application, val serverUrl: String, val token: Token) {
private val database: RCDatabase = androidx.room.Room.databaseBuilder(
context,
RCDatabase::class.java, serverUrl.databaseName()
......@@ -61,23 +61,23 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
.build()
private val dbContext = newSingleThreadContext("$serverUrl-db-context")
private val dbManagerContext = newSingleThreadContext("$serverUrl-db-manager-context")
private val writeChannel = Channel<Operation>(Channel.UNLIMITED)
private var dbJob: Job? = null
private val insertSubs = HashMap<String, Subscription>()
private val insertRooms = HashMap<String, Room>()
private val updateSubs = LinkedHashMap<String, Subscription>()
private val updateRooms = LinkedHashMap<String, Room>()
fun chatRoomDao(): ChatRoomDao = database.chatRoomDao()
fun userDao(): UserDao = database.userDao()
fun messageDao(): MessageDao = database.messageDao()
init {
start()
}
fun chatRoomDao(): ChatRoomDao = database.chatRoomDao()
fun userDao(): UserDao = database.userDao()
fun messageDao(): MessageDao = database.messageDao()
fun start() {
dbJob?.cancel()
dbJob = GlobalScope.launch(dbContext) {
......@@ -196,7 +196,13 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
myself.name == null && myself.username == null
) {
user?.username?.let {
Fresco.getImagePipeline().evictFromCache(serverUrl.avatarUrl(it).toUri())
Fresco.getImagePipeline().evictFromCache(
serverUrl.avatarUrl(
it,
token.userId,
token.authToken
).toUri()
)
}
}
......
package chat.rocket.android.db
import android.app.Application
import chat.rocket.android.server.domain.TokenRepository
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class DatabaseManagerFactory @Inject constructor(private val context: Application) {
class DatabaseManagerFactory @Inject constructor(
private val context: Application,
private val tokenRepository: TokenRepository
) {
private val cache = HashMap<String, DatabaseManager>()
fun create(serverUrl: String): DatabaseManager {
......@@ -15,9 +19,10 @@ class DatabaseManagerFactory @Inject constructor(private val context: Applicatio
return it
}
Timber.d("Returning FRESH database for $serverUrl")
val db = DatabaseManager(context, serverUrl)
cache[serverUrl] = db
return db
Timber.d("Returning fresh database for $serverUrl")
with(DatabaseManager(context, serverUrl, tokenRepository.get(serverUrl)!!)) {
cache[serverUrl] = this
return this
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment