better fix

This commit is contained in:
Henry Jameson 2026-08-26 18:05:15 +03:00
commit f46575add2
2 changed files with 3 additions and 4 deletions

View file

@ -5,8 +5,6 @@ import { useUsersStore } from 'src/stores/users.js'
export const maybeShowChatNotification = (chat) => { export const maybeShowChatNotification = (chat) => {
// No messages // No messages
if (!chat.lastMessage) return if (!chat.lastMessage) return
// Already shown notification for this message
if (chat.lastMessage.id === chat.lastNotifiedMessageId) return
// No unreads to display // No unreads to display
if (chat.unread === 0) return if (chat.unread === 0) return
// Don't notify on outgoing message (shouldn't happen with condition above) // Don't notify on outgoing message (shouldn't happen with condition above)
@ -24,7 +22,6 @@ export const maybeShowChatNotification = (chat) => {
opts.image = chat.lastMessage.attachment.preview_url opts.image = chat.lastMessage.attachment.preview_url
} }
chat.lastNotifiedMessageId = chat.lastMessage.id
showDesktopNotification(opts) showDesktopNotification(opts)
} }

View file

@ -79,13 +79,15 @@ export const useChatsStore = defineStore('chats', {
updateChat(updatedChat) { updateChat(updatedChat) {
const chat = this.data.get(updatedChat.id) const chat = this.data.get(updatedChat.id)
if (chat) { if (chat) {
const isNewMessage = chat.lastMessage !== updatedChat.lastMessage
chat.lastMessage = updatedChat.lastMessage chat.lastMessage = updatedChat.lastMessage
chat.unread = updatedChat.unread chat.unread = updatedChat.unread
chat.updated_at = updatedChat.updated_at chat.updated_at = updatedChat.updated_at
if (!isNewMessage) return
} else { } else {
this.data.set(updatedChat.id, updatedChat) this.data.set(updatedChat.id, updatedChat)
} }
maybeShowChatNotification(chat ?? updatedChat) maybeShowChatNotification(chat)
}, },
deleteChat(id) { deleteChat(id) {
this.data.delete(id) this.data.delete(id)