Reduce nested block depth for updateReadStatusOfAllMessages

Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
Tim Krüger 2022-09-07 10:51:09 +02:00
parent 57ddf9af60
commit 5bb63fd58d
No known key found for this signature in database
GPG key ID: FECE3A7222C52A4E

View file

@ -2352,15 +2352,22 @@ class ChatController(args: Bundle) :
private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) {
for (message in adapter!!.items) {
xChatLastCommonRead?.let {
if (message.item is ChatMessage) {
val chatMessage = message.item as ChatMessage
updateReadStatusOfMessage(message, it)
}
}
}
if (chatMessage.jsonMessageId <= it) {
chatMessage.readStatus = ReadStatus.READ
} else {
chatMessage.readStatus = ReadStatus.SENT
}
}
private fun updateReadStatusOfMessage(
message: MessagesListAdapter<IMessage>.Wrapper<Any>,
xChatLastCommonRead: Int
) {
if (message.item is ChatMessage) {
val chatMessage = message.item as ChatMessage
if (chatMessage.jsonMessageId <= xChatLastCommonRead) {
chatMessage.readStatus = ReadStatus.READ
} else {
chatMessage.readStatus = ReadStatus.SENT
}
}
}