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 ...@@ -25,6 +25,7 @@ import chat.rocket.android.util.retryDB
import chat.rocket.common.model.BaseRoom import chat.rocket.common.model.BaseRoom
import chat.rocket.common.model.RoomType import chat.rocket.common.model.RoomType
import chat.rocket.common.model.SimpleUser import chat.rocket.common.model.SimpleUser
import chat.rocket.common.model.Token
import chat.rocket.common.model.User import chat.rocket.common.model.User
import chat.rocket.core.internal.model.Subscription import chat.rocket.core.internal.model.Subscription
import chat.rocket.core.internal.realtime.socket.model.StreamMessage import chat.rocket.core.internal.realtime.socket.model.StreamMessage
...@@ -51,8 +52,7 @@ import kotlin.collections.component2 ...@@ -51,8 +52,7 @@ import kotlin.collections.component2
import kotlin.collections.set import kotlin.collections.set
import kotlin.system.measureTimeMillis 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( private val database: RCDatabase = androidx.room.Room.databaseBuilder(
context, context,
RCDatabase::class.java, serverUrl.databaseName() RCDatabase::class.java, serverUrl.databaseName()
...@@ -61,23 +61,23 @@ class DatabaseManager(val context: Application, val serverUrl: String) { ...@@ -61,23 +61,23 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
.build() .build()
private val dbContext = newSingleThreadContext("$serverUrl-db-context") private val dbContext = newSingleThreadContext("$serverUrl-db-context")
private val dbManagerContext = newSingleThreadContext("$serverUrl-db-manager-context") private val dbManagerContext = newSingleThreadContext("$serverUrl-db-manager-context")
private val writeChannel = Channel<Operation>(Channel.UNLIMITED) private val writeChannel = Channel<Operation>(Channel.UNLIMITED)
private var dbJob: Job? = null private var dbJob: Job? = null
private val insertSubs = HashMap<String, Subscription>() private val insertSubs = HashMap<String, Subscription>()
private val insertRooms = HashMap<String, Room>() private val insertRooms = HashMap<String, Room>()
private val updateSubs = LinkedHashMap<String, Subscription>() private val updateSubs = LinkedHashMap<String, Subscription>()
private val updateRooms = LinkedHashMap<String, Room>() private val updateRooms = LinkedHashMap<String, Room>()
fun chatRoomDao(): ChatRoomDao = database.chatRoomDao()
fun userDao(): UserDao = database.userDao()
fun messageDao(): MessageDao = database.messageDao()
init { init {
start() start()
} }
fun chatRoomDao(): ChatRoomDao = database.chatRoomDao()
fun userDao(): UserDao = database.userDao()
fun messageDao(): MessageDao = database.messageDao()
fun start() { fun start() {
dbJob?.cancel() dbJob?.cancel()
dbJob = GlobalScope.launch(dbContext) { dbJob = GlobalScope.launch(dbContext) {
...@@ -196,7 +196,13 @@ class DatabaseManager(val context: Application, val serverUrl: String) { ...@@ -196,7 +196,13 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
myself.name == null && myself.username == null myself.name == null && myself.username == null
) { ) {
user?.username?.let { 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 package chat.rocket.android.db
import android.app.Application import android.app.Application
import chat.rocket.android.server.domain.TokenRepository
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@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>() private val cache = HashMap<String, DatabaseManager>()
fun create(serverUrl: String): DatabaseManager { fun create(serverUrl: String): DatabaseManager {
...@@ -15,9 +19,10 @@ class DatabaseManagerFactory @Inject constructor(private val context: Applicatio ...@@ -15,9 +19,10 @@ class DatabaseManagerFactory @Inject constructor(private val context: Applicatio
return it return it
} }
Timber.d("Returning FRESH database for $serverUrl") Timber.d("Returning fresh database for $serverUrl")
val db = DatabaseManager(context, serverUrl) with(DatabaseManager(context, serverUrl, tokenRepository.get(serverUrl)!!)) {
cache[serverUrl] = db cache[serverUrl] = this
return db 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