android: fix unread badge reset when chat is read
This commit is contained in:
@@ -525,3 +525,8 @@
|
||||
### Step 84 - Chats list preview icon policy cleanup
|
||||
- Updated chat last-message preview text to remove emoji prefixes.
|
||||
- Switched media-type preview prefixes to plain text labels (`Photo`, `Video`, `Voice`, etc.) to match Material-icons-only UI policy.
|
||||
|
||||
### Step 85 - Unread counter fix for active/read chats
|
||||
- Added `ChatDao.markChatRead(chatId)` to clear `unread_count` and `unread_mentions_count` in Room.
|
||||
- Applied optimistic local unread reset on `markMessageRead(...)` in message repository.
|
||||
- Fixed realtime unread logic: incoming messages in currently active chat no longer increment unread badge.
|
||||
|
||||
@@ -139,6 +139,16 @@ interface ChatDao {
|
||||
)
|
||||
suspend fun incrementUnread(chatId: Long, incrementBy: Int = 1)
|
||||
|
||||
@Query(
|
||||
"""
|
||||
UPDATE chats
|
||||
SET unread_count = 0,
|
||||
unread_mentions_count = 0
|
||||
WHERE id = :chatId
|
||||
"""
|
||||
)
|
||||
suspend fun markChatRead(chatId: Long)
|
||||
|
||||
@Transaction
|
||||
suspend fun clearAndReplaceChats(
|
||||
archived: Boolean,
|
||||
|
||||
@@ -401,6 +401,8 @@ class NetworkMessageRepository @Inject constructor(
|
||||
}
|
||||
|
||||
override suspend fun markMessageRead(chatId: Long, messageId: Long): AppResult<Unit> = withContext(ioDispatcher) {
|
||||
// User already viewed this chat/message in UI, so unread badge should drop immediately.
|
||||
chatDao.markChatRead(chatId)
|
||||
try {
|
||||
messageApiService.updateMessageStatus(
|
||||
request = MessageStatusUpdateRequestDto(
|
||||
|
||||
@@ -45,6 +45,7 @@ class HandleRealtimeEventsUseCase @Inject constructor(
|
||||
}
|
||||
|
||||
is RealtimeEvent.ReceiveMessage -> {
|
||||
val activeChatId = activeChatTracker.activeChatId.value
|
||||
messageDao.upsertMessages(
|
||||
listOf(
|
||||
MessageEntity(
|
||||
@@ -75,8 +76,11 @@ class HandleRealtimeEventsUseCase @Inject constructor(
|
||||
lastMessageCreatedAt = event.createdAt,
|
||||
updatedSortAt = event.createdAt,
|
||||
)
|
||||
chatDao.incrementUnread(chatId = event.chatId)
|
||||
val activeChatId = activeChatTracker.activeChatId.value
|
||||
if (activeChatId == event.chatId) {
|
||||
chatDao.markChatRead(chatId = event.chatId)
|
||||
} else {
|
||||
chatDao.incrementUnread(chatId = event.chatId)
|
||||
}
|
||||
val muted = chatDao.isChatMuted(event.chatId) == true
|
||||
val shouldNotify = shouldShowMessageNotificationUseCase(
|
||||
chatId = event.chatId,
|
||||
|
||||
Reference in New Issue
Block a user