fix: avoid unread noise from realtime self echoes
fix: ignore self-sent websocket echoes for unread counters and notifications
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user