Skip to content

Commit 2d34ff3

Browse files
committed
WIP mark chat as read
wip: Maybe trigger it when the user scrolled to the bottom on his own. E.g. when a scrolling listener tells "scrolling is finished" we check if it's scrolled to the bottom and then send the mark as read also todo: mark as read "when the user is sending the app to the background or navigates "back to conversation list" and the last message a user read (saw on screen) is a higher id then the previous known readmarker" Signed-off-by: Marcel Hibbe <[email protected]>
1 parent ea85242 commit 2d34ff3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,17 @@ class ChatActivity :
14641464
if (isScrolledToBottom()) {
14651465
binding.unreadMessagesPopup.visibility = View.GONE
14661466
binding.scrollDownButton.visibility = View.GONE
1467+
1468+
1469+
1470+
// TODO: mark chat as read here
1471+
// val previousChatMessage = adapter.items?.getOrNull(1)?.item
1472+
// if (previousChatMessage != null && previousChatMessage is ChatMessage) {
1473+
// chatMessage.isGrouped = groupMessages(chatMessage, previousChatMessage)
1474+
// }
1475+
//
1476+
//
1477+
// markAsRead(adapter.items......)
14671478
} else {
14681479
if (binding.unreadMessagesPopup.isShown) {
14691480
binding.scrollDownButton.visibility = View.GONE
@@ -3943,9 +3954,24 @@ class ChatActivity :
39433954
}
39443955
}
39453956

3957+
private fun markAsRead(messageId: Int) {
3958+
chatViewModel.setChatReadMarker(
3959+
credentials!!,
3960+
ApiUtils.getUrlForChatReadMarker(
3961+
ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(ApiUtils.API_V1)),
3962+
conversationUser?.baseUrl!!,
3963+
roomToken
3964+
),
3965+
messageId
3966+
)
3967+
}
3968+
39463969
fun markAsUnread(message: IMessage?) {
39473970
val chatMessage = message as ChatMessage?
39483971
if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) {
3972+
// previousMessageId is taken to mark chat as unread even when "chat-unread" capability is not available
3973+
// It should be checked if "chat-unread" capability is available and then use
3974+
// https://nextcloud-talk.readthedocs.io/en/latest/chat/#mark-chat-as-unread
39493975
chatViewModel.setChatReadMarker(
39503976
credentials!!,
39513977
ApiUtils.getUrlForChatReadMarker(

app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ class ChatViewModel @Inject constructor(
564564
})
565565
}
566566

567-
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int) {
568-
chatNetworkDataSource.setChatReadMarker(credentials, url, previousMessageId)
567+
fun setChatReadMarker(credentials: String, url: String, lastReadMessage: Int) {
568+
chatNetworkDataSource.setChatReadMarker(credentials, url, lastReadMessage)
569569
.subscribeOn(Schedulers.io())
570570
.observeOn(AndroidSchedulers.mainThread())
571571
.subscribe(object : Observer<GenericOverall> {

0 commit comments

Comments
 (0)