Skip to content

Commit 074dc73

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 <dev@mhibbe.de>
1 parent ff73495 commit 074dc73

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,17 @@ class ChatActivity :
14541454
if (isScrolledToBottom()) {
14551455
binding.unreadMessagesPopup.visibility = View.GONE
14561456
binding.scrollDownButton.visibility = View.GONE
1457+
1458+
1459+
1460+
// TODO: mark chat as read here
1461+
// val previousChatMessage = adapter.items?.getOrNull(1)?.item
1462+
// if (previousChatMessage != null && previousChatMessage is ChatMessage) {
1463+
// chatMessage.isGrouped = groupMessages(chatMessage, previousChatMessage)
1464+
// }
1465+
//
1466+
//
1467+
// markAsRead(adapter.items......)
14571468
} else {
14581469
if (binding.unreadMessagesPopup.isShown) {
14591470
binding.scrollDownButton.visibility = View.GONE
@@ -3928,9 +3939,24 @@ class ChatActivity :
39283939
}
39293940
}
39303941

3942+
private fun markAsRead(messageId: Int) {
3943+
chatViewModel.setChatReadMarker(
3944+
credentials!!,
3945+
ApiUtils.getUrlForChatReadMarker(
3946+
ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(ApiUtils.API_V1)),
3947+
conversationUser?.baseUrl!!,
3948+
roomToken
3949+
),
3950+
messageId
3951+
)
3952+
}
3953+
39313954
fun markAsUnread(message: IMessage?) {
39323955
val chatMessage = message as ChatMessage?
39333956
if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) {
3957+
// previousMessageId is taken to mark chat as unread even when "chat-unread" capability is not available
3958+
// It should be checked if "chat-unread" capability is available and then use
3959+
// https://nextcloud-talk.readthedocs.io/en/latest/chat/#mark-chat-as-unread
39343960
chatViewModel.setChatReadMarker(
39353961
credentials!!,
39363962
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
@@ -555,8 +555,8 @@ class ChatViewModel @Inject constructor(
555555
})
556556
}
557557

558-
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int) {
559-
chatNetworkDataSource.setChatReadMarker(credentials, url, previousMessageId)
558+
fun setChatReadMarker(credentials: String, url: String, lastReadMessage: Int) {
559+
chatNetworkDataSource.setChatReadMarker(credentials, url, lastReadMessage)
560560
.subscribeOn(Schedulers.io())
561561
.observeOn(AndroidSchedulers.mainThread())
562562
.subscribe(object : Observer<GenericOverall> {

0 commit comments

Comments
 (0)