2020-07-13 00:06:45 +03:00
|
|
|
import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
|
|
|
|
|
|
2026-08-10 15:00:59 +03:00
|
|
|
import { useUsersStore } from 'src/stores/users.js'
|
|
|
|
|
|
2026-07-08 20:29:59 +03:00
|
|
|
export const maybeShowChatNotification = (chat) => {
|
2020-07-13 00:06:45 +03:00
|
|
|
if (!chat.lastMessage) return
|
2026-08-10 15:00:59 +03:00
|
|
|
if (useUsersStore().currentUser.id === chat.lastMessage.account_id) return
|
2020-07-13 00:06:45 +03:00
|
|
|
|
|
|
|
|
const opts = {
|
|
|
|
|
tag: chat.lastMessage.id,
|
|
|
|
|
title: chat.account.name,
|
|
|
|
|
icon: chat.account.profile_image_url,
|
2026-01-06 16:22:52 +02:00
|
|
|
body: chat.lastMessage.content,
|
2020-07-13 00:06:45 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-04 18:04:57 +03:00
|
|
|
if (chat.lastMessage.attachment?.type === 'image') {
|
2020-07-13 00:06:45 +03:00
|
|
|
opts.image = chat.lastMessage.attachment.preview_url
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-08 20:29:59 +03:00
|
|
|
showDesktopNotification(window.vuex.state, opts)
|
2020-07-13 00:06:45 +03:00
|
|
|
}
|
2020-10-29 13:33:06 +03:00
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
export const buildFakeMessage = ({
|
|
|
|
|
content,
|
|
|
|
|
chatId,
|
|
|
|
|
attachments,
|
|
|
|
|
userId,
|
|
|
|
|
idempotencyKey,
|
|
|
|
|
}) => {
|
2020-10-29 13:33:06 +03:00
|
|
|
const fakeMessage = {
|
|
|
|
|
content,
|
|
|
|
|
chat_id: chatId,
|
|
|
|
|
created_at: new Date(),
|
|
|
|
|
id: `${new Date().getTime()}`,
|
2022-07-31 12:35:48 +03:00
|
|
|
attachments,
|
2020-10-29 13:33:06 +03:00
|
|
|
account_id: userId,
|
|
|
|
|
idempotency_key: idempotencyKey,
|
|
|
|
|
emojis: [],
|
|
|
|
|
pending: true,
|
2026-01-06 16:22:52 +02:00
|
|
|
isNormalized: true,
|
2020-10-29 13:33:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attachments[0]) {
|
|
|
|
|
fakeMessage.attachment = attachments[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fakeMessage
|
|
|
|
|
}
|