pleroma-fe/src/services/chat_utils/chat_utils.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-07-13 00:06:45 +03:00
import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
export const maybeShowChatNotification = (store, chat) => {
if (!chat.lastMessage) return
2026-01-06 16:22:52 +02:00
if (store.rootState.chats.currentChatId === chat.id && !document.hidden)
return
if (store.rootState.users.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-01-06 16:22:52 +02:00
if (
chat.lastMessage.attachment &&
chat.lastMessage.attachment.type === 'image'
) {
2020-07-13 00:06:45 +03:00
opts.image = chat.lastMessage.attachment.preview_url
}
showDesktopNotification(store.rootState, opts)
}
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
}