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