aboutsummaryrefslogtreecommitdiff
path: root/src/services/chat_utils
diff options
context:
space:
mode:
authorShpuld Shpludson <shp@cock.li>2020-07-20 14:34:50 +0000
committerShpuld Shpludson <shp@cock.li>2020-07-20 14:34:50 +0000
commita06ab08f96ba25a5163dd3c8e7e0fec75023c302 (patch)
tree0f977bf96ce11e078adb0e470c5a33eb5e18d630 /src/services/chat_utils
parente0add7a44e6d626ddfcb5869cf5cade719ca2061 (diff)
parent54dea24bb8b34021debdb2ab505a2e0b5b770ed9 (diff)
Merge branch 'desktop-notifications-for-chat' into 'develop'
Desktop chat notifications Closes #893 See merge request pleroma/pleroma-fe!1185
Diffstat (limited to 'src/services/chat_utils')
-rw-r--r--src/services/chat_utils/chat_utils.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/services/chat_utils/chat_utils.js b/src/services/chat_utils/chat_utils.js
new file mode 100644
index 00000000..ab898ced
--- /dev/null
+++ b/src/services/chat_utils/chat_utils.js
@@ -0,0 +1,19 @@
+import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
+
+export const maybeShowChatNotification = (store, chat) => {
+ if (!chat.lastMessage) return
+ if (store.rootState.chats.currentChatId === chat.id && !document.hidden) return
+
+ const opts = {
+ tag: chat.lastMessage.id,
+ title: chat.account.name,
+ icon: chat.account.profile_image_url,
+ body: chat.lastMessage.content
+ }
+
+ if (chat.lastMessage.attachment && chat.lastMessage.attachment.type === 'image') {
+ opts.image = chat.lastMessage.attachment.preview_url
+ }
+
+ showDesktopNotification(store.rootState, opts)
+}