Skip to content

Commit 9d6c9df

Browse files
Fix unread badge not disappearing upon opening the chat (#5994)
* Stop using kluent * Fix `markChannelAsRead` not working when `lastReadMessageId` is correct but `unreadCount` > 0 The `markChannelAsRead` function is now allowed to proceed if there are unread messages, even if the `lastReadMessageId` already matches the ID of the latest message. This handles cases where the server state for the unread count might be out of sync with the client. * CHANGELOG --------- Co-authored-by: Petar Velikov <[email protected]>
1 parent d913aed commit 9d6c9df

File tree

3 files changed

+182
-49
lines changed

3 files changed

+182
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
## stream-chat-android-state
3636
### 🐞 Fixed
37+
- Fix `markChannelAsRead` not working when `lastReadMessageId` is correct but `unreadCount` > 0. [#5994](https://github.com/GetStream/stream-chat-android/pull/5994)
3738

3839
### ⬆️ Improved
3940
- Prioritize `Message.createdLocallyAt` over `Message.createdAt` when sorting messages, to ensure the message order is consistent before the messages are synced with the server. [#5993](https://github.com/GetStream/stream-chat-android/pull/5993)

stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/state/channel/internal/ChannelMutableState.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,12 @@ internal class ChannelMutableState(
573573
when (val currentUserRead = read.value) {
574574
null -> true
575575
else ->
576+
// Allow marking as read if:
577+
// 1. The last read message ID differs from the last message, OR
578+
// 2. There are unread messages (even if lastReadMessageId matches, server state may differ)
576579
currentUserRead
577-
.takeIf { it.lastReadMessageId != lastMessage.id }
578-
?. let {
580+
.takeIf { it.lastReadMessageId != lastMessage.id || it.unreadMessages > 0 }
581+
?.let {
579582
upsertReads(
580583
listOf(
581584
it.copy(

0 commit comments

Comments
 (0)