fix: avoid unread noise from realtime self echoes
Some checks failed
Android CI / android (push) Has been cancelled
Android Release / release (push) Has been cancelled
CI / test (push) Has been cancelled

fix: ignore self-sent websocket echoes for unread counters and notifications
This commit is contained in:
2026-04-05 15:02:02 +03:00
parent ab391ec475
commit d2d3f2f08e

View File

@@ -52,6 +52,8 @@ class HandleRealtimeEventsUseCase @Inject constructor(
is RealtimeEvent.ReceiveMessage -> {
val activeChatId = activeChatTracker.activeChatId.value
val activeUserId = tokenRepository.getActiveUserId()
val isOwnMessage = activeUserId != null && event.senderId == activeUserId
val lastMessagePreview = event.text?.takeIf { it.isNotBlank() }
?: fallbackMessagePreview(event.type)
messageDao.upsertMessages(
@@ -87,11 +89,10 @@ class HandleRealtimeEventsUseCase @Inject constructor(
if (activeChatId == event.chatId) {
chatDao.markChatRead(chatId = event.chatId)
messageRepository.syncRecentMessages(chatId = event.chatId)
} else {
} else if (!isOwnMessage) {
chatDao.incrementUnread(chatId = event.chatId)
}
chatRepository.refreshChat(chatId = event.chatId)
val activeUserId = tokenRepository.getActiveUserId()
val myUsername = activeUserId?.let { userId ->
tokenRepository.getAccounts()
.firstOrNull { it.userId == userId }
@@ -113,7 +114,7 @@ class HandleRealtimeEventsUseCase @Inject constructor(
isMention = isMention,
serverMuted = muted,
)
if (activeChatId != event.chatId && shouldNotify) {
if (!isOwnMessage && activeChatId != event.chatId && shouldNotify) {
val title = chatDao.getChatDisplayTitle(event.chatId) ?: "New message"
val previewEnabled = notificationSettingsRepository.getSettings().previewEnabled
val body = (if (previewEnabled) {