From 5bb63fd58d44b32dc64f5735ba27570c4df435f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 7 Sep 2022 10:51:09 +0200 Subject: [PATCH] Reduce nested block depth for updateReadStatusOfAllMessages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index f03ee2ecb..82c4adf02 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -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.Wrapper, + 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 } } }