Commit 6ffa4788 authored by Lucio Maciel's avatar Lucio Maciel

Sometimes we don't have the userId, so just ignore it

parent c3d08b98
......@@ -3,7 +3,6 @@ package chat.rocket.android.chatrooms.domain
import chat.rocket.android.db.DatabaseManager
import chat.rocket.android.db.model.ChatRoomEntity
import chat.rocket.android.db.model.UserEntity
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.util.retryIO
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.chatRooms
......
......@@ -154,14 +154,14 @@ class DatabaseManager(val context: Application,
val chatRoom = current.chatRoom
lastMessage?.sender?.let { user ->
if (findUser(user.id!!) == null) {
if (findUser(user.id) == null) {
Timber.d("Missing last message user, inserting: ${user.id}")
insert(UserEntity(user.id!!, user.username, user.name))
}
}
user?.let { user ->
if (findUser(user.id!!) == null) {
if (findUser(user.id) == null) {
Timber.d("Missing owner user, inserting: ${user.id}")
insert(UserEntity(user.id!!, user.username, user.name))
}
......@@ -260,15 +260,16 @@ class DatabaseManager(val context: Application,
Timber.d("Missing user, inserting: $userId")
insert(UserEntity(userId))
}
room.lastMessage?.sender?.let { user ->
if (findUser(user.id!!) == null) {
if (findUser(user.id) == null) {
Timber.d("Missing last message user, inserting: ${user.id}")
insert(UserEntity(user.id!!, user.username, user.name))
}
}
room.user?.let { user ->
if (findUser(user.id!!) == null) {
if (findUser(user.id) == null) {
Timber.d("Missing owner user, inserting: ${user.id}")
insert(UserEntity(user.id!!, user.username, user.name))
}
......@@ -312,13 +313,13 @@ class DatabaseManager(val context: Application,
}
}
fun findUser(userId: String): String? = userDao().findUser(userId)
fun findUser(userId: String?): String? = if (userId != null) userDao().findUser(userId) else null
}
fun User.toEntity(): BaseUserEntity? {
return if (name == null && username == null && utcOffset == null && status != null) {
UserStatus(id = id, status = status.toString())
} else if (username != null){
} else if (username != null) {
UserEntity(id, username, name, status?.toString() ?: "offline", utcOffset)
} else {
null
......
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