@@ -3451,21 +3451,27 @@ class ChatActivity :
34513451 )
34523452 }
34533453
3454- fun markAsUnread (chatMessage : ChatMessage ? ) {
3455- if (chatMessage!! .previousMessageId > NO_PREVIOUS_MESSAGE_ID ) {
3456- // previousMessageId is taken to mark chat as unread even when "chat-unread" capability is not available
3457- // It should be checked if "chat-unread" capability is available and then use
3458- // https://nextcloud-talk.readthedocs.io/en/latest/chat/#mark-chat-as-unread
3459- chatViewModel.setChatReadMessage(
3460- credentials!! ,
3461- ApiUtils .getUrlForChatReadMarker(
3462- ApiUtils .getChatApiVersion(spreedCapabilities, intArrayOf(ApiUtils .API_V1 )),
3463- conversationUser?.baseUrl!! ,
3464- roomToken
3465- ),
3466- chatMessage.previousMessageId
3467- )
3454+ fun markAsUnread (chatMessage : ChatMessage ) {
3455+ val items = chatViewModel.uiState.value.items
3456+ val selectedIndex = items.indexOfFirst {
3457+ (it as ? ChatViewModel .ChatItem .MessageItem )?.uiMessage?.id == chatMessage.jsonMessageId
3458+ }
3459+ val lastReadMessage = if (selectedIndex in 0 until items.size - 1 ) {
3460+ (selectedIndex + 1 until items.size)
3461+ .firstNotNullOfOrNull { (items[it] as ? ChatViewModel .ChatItem .MessageItem )?.uiMessage?.id }
3462+ ? : 0
3463+ } else {
3464+ 0
34683465 }
3466+ chatViewModel.setChatReadMessage(
3467+ credentials!! ,
3468+ ApiUtils .getUrlForChatReadMarker(
3469+ ApiUtils .getChatApiVersion(spreedCapabilities, intArrayOf(ApiUtils .API_V1 )),
3470+ conversationUser.baseUrl!! ,
3471+ roomToken
3472+ ),
3473+ lastReadMessage
3474+ )
34693475 }
34703476
34713477 fun copyMessage (message : ChatMessage ? ) {
@@ -3712,10 +3718,7 @@ class ChatActivity :
37123718 // delete
37133719 ChatMessage .MessageType .REGULAR_TEXT_MESSAGE == message.getCalculateMessageType() ||
37143720 // forward
3715- message.previousMessageId > NO_PREVIOUS_MESSAGE_ID &&
3716- // mark as unread
3717- ChatMessage .MessageType .SYSTEM_MESSAGE != message.getCalculateMessageType() &&
3718- BuildConfig .DEBUG
3721+ ChatMessage .MessageType .SYSTEM_MESSAGE != message.getCalculateMessageType()
37193722
37203723 private fun isShowMessageDeletionButton (message : ChatMessage ): Boolean {
37213724 val isUserAllowedByPrivileges = userAllowedByPrivilages(message)
@@ -3975,7 +3978,6 @@ class ChatActivity :
39753978 private const val FULLY_OPAQUE_INT : Int = 255
39763979 private const val SEMI_TRANSPARENT_INT : Int = 99
39773980 private const val VOICE_MESSAGE_SEEKBAR_BASE = 1000
3978- private const val NO_PREVIOUS_MESSAGE_ID : Int = - 1
39793981 private const val TOOLBAR_AVATAR_RATIO = 1.5
39803982 private const val STATUS_SIZE_IN_DP = 9f
39813983 private const val HTTP_BAD_REQUEST = 400
0 commit comments