Commit c0127753 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Remove message from MessageRepository if Message_ShowDeletedMessage is false,...

Remove message from MessageRepository if Message_ShowDeletedMessage is false, otherwise updated it to signalize it
parent ebe0a78e
...@@ -63,6 +63,14 @@ class ChatRoomAdapter(private val serverUrl: String, ...@@ -63,6 +63,14 @@ class ChatRoomAdapter(private val serverUrl: String,
} }
} }
fun removeItem(messageId: String) {
val index = dataSet.indexOfFirst { it.id == messageId }
if (index > -1) {
dataSet.removeAt(index)
notifyItemRemoved(index)
}
}
override fun getItemId(position: Int): Long { override fun getItemId(position: Int): Long {
return dataSet[position].id.hashCode().toLong() return dataSet[position].id.hashCode().toLong()
} }
......
...@@ -122,6 +122,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView { ...@@ -122,6 +122,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
adapter.updateItem(message) adapter.updateItem(message)
} }
override fun dispatchDeleteMessage(msgId: String) {
adapter.removeItem(msgId)
}
override fun showLoading() = view_loading.setVisible(true) override fun showLoading() = view_loading.setVisible(true)
override fun hideLoading() = view_loading.setVisible(false) override fun hideLoading() = view_loading.setVisible(false)
......
...@@ -13,6 +13,7 @@ import chat.rocket.android.helper.UrlHelper ...@@ -13,6 +13,7 @@ import chat.rocket.android.helper.UrlHelper
import chat.rocket.android.server.domain.MessagesRepository import chat.rocket.android.server.domain.MessagesRepository
import chat.rocket.android.server.domain.SITE_URL import chat.rocket.android.server.domain.SITE_URL
import chat.rocket.android.server.domain.USE_REALNAME import chat.rocket.android.server.domain.USE_REALNAME
import chat.rocket.android.server.domain.useRealName
import chat.rocket.common.model.Token import chat.rocket.common.model.Token
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.MessageType.* import chat.rocket.core.model.MessageType.*
...@@ -28,7 +29,7 @@ import timber.log.Timber ...@@ -28,7 +29,7 @@ import timber.log.Timber
data class MessageViewModel(val context: Context, data class MessageViewModel(val context: Context,
private val token: Token?, private val token: Token?,
private val message: Message, private val message: Message,
private val settings: Map<String, Value<Any>>?, private val settings: Map<String, Value<Any>>,
private val parser: MessageParser, private val parser: MessageParser,
private val messagesRepository: MessagesRepository) { private val messagesRepository: MessagesRepository) {
val id: String = message.id val id: String = message.id
...@@ -103,10 +104,9 @@ data class MessageViewModel(val context: Context, ...@@ -103,10 +104,9 @@ data class MessageViewModel(val context: Context,
private fun getTime() = DateTimeHelper.getTime(DateTimeHelper.getLocalDateTime(message.timestamp)) private fun getTime() = DateTimeHelper.getTime(DateTimeHelper.getLocalDateTime(message.timestamp))
private fun getSenderName(): CharSequence { private fun getSenderName(): CharSequence {
val useRealName = settings?.get(USE_REALNAME)?.value as Boolean
val username = message.sender?.username val username = message.sender?.username
val realName = message.sender?.name val realName = message.sender?.name
val senderName = if (useRealName) realName else username val senderName = if (settings.useRealName()) realName else username
return senderName ?: username.toString() return senderName ?: username.toString()
} }
......
...@@ -13,10 +13,10 @@ class MessageViewModelMapper @Inject constructor(private val context: Context, ...@@ -13,10 +13,10 @@ class MessageViewModelMapper @Inject constructor(private val context: Context,
private val messageParser: MessageParser, private val messageParser: MessageParser,
private val messagesRepository: MessagesRepository) { private val messagesRepository: MessagesRepository) {
suspend fun mapToViewModel(message: Message, settings: Map<String, Value<Any>>?) = suspend fun mapToViewModel(message: Message, settings: Map<String, Value<Any>>) =
MessageViewModel(context, tokenRepository.get(), message, settings, messageParser, messagesRepository) MessageViewModel(context, tokenRepository.get(), message, settings, messageParser, messagesRepository)
suspend fun mapToViewModelList(messageList: List<Message>, settings: Map<String, Value<Any>>?): List<MessageViewModel> { suspend fun mapToViewModelList(messageList: List<Message>, settings: Map<String, Value<Any>>): List<MessageViewModel> {
return messageList.map { MessageViewModel(context, tokenRepository.get(), it, settings, messageParser, messagesRepository) } return messageList.map { MessageViewModel(context, tokenRepository.get(), it, settings, messageParser, messagesRepository) }
} }
} }
\ 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