logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

chat_utils.js (1173B)


  1. import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
  2. export const maybeShowChatNotification = (store, chat) => {
  3. if (!chat.lastMessage) return
  4. if (store.rootState.chats.currentChatId === chat.id && !document.hidden) return
  5. if (store.rootState.users.currentUser.id === chat.lastMessage.account_id) return
  6. const opts = {
  7. tag: chat.lastMessage.id,
  8. title: chat.account.name,
  9. icon: chat.account.profile_image_url,
  10. body: chat.lastMessage.content
  11. }
  12. if (chat.lastMessage.attachment && chat.lastMessage.attachment.type === 'image') {
  13. opts.image = chat.lastMessage.attachment.preview_url
  14. }
  15. showDesktopNotification(store.rootState, opts)
  16. }
  17. export const buildFakeMessage = ({ content, chatId, attachments, userId, idempotencyKey }) => {
  18. const fakeMessage = {
  19. content,
  20. chat_id: chatId,
  21. created_at: new Date(),
  22. id: `${new Date().getTime()}`,
  23. attachments,
  24. account_id: userId,
  25. idempotency_key: idempotencyKey,
  26. emojis: [],
  27. pending: true,
  28. isNormalized: true
  29. }
  30. if (attachments[0]) {
  31. fakeMessage.attachment = attachments[0]
  32. }
  33. return fakeMessage
  34. }