From 2c35afeebf4e508fd911a90d3c4af3a75e4484ab Mon Sep 17 00:00:00 2001 From: eugenijm Date: Mon, 13 Jul 2020 00:06:45 +0300 Subject: Add desktop chat notifications --- src/services/chat_utils/chat_utils.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/services/chat_utils/chat_utils.js (limited to 'src/services/chat_utils/chat_utils.js') diff --git a/src/services/chat_utils/chat_utils.js b/src/services/chat_utils/chat_utils.js new file mode 100644 index 00000000..7264ebcc --- /dev/null +++ b/src/services/chat_utils/chat_utils.js @@ -0,0 +1,18 @@ +import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js' + +export const maybeShowChatNotification = (store, chat) => { + if (!chat.lastMessage) 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) +} -- cgit v1.2.3-70-g09d2 From 54dea24bb8b34021debdb2ab505a2e0b5b770ed9 Mon Sep 17 00:00:00 2001 From: eugenijm Date: Mon, 13 Jul 2020 15:48:19 +0300 Subject: Do not display desktop chat notification when the chat is focused --- src/services/chat_utils/chat_utils.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/services/chat_utils/chat_utils.js') diff --git a/src/services/chat_utils/chat_utils.js b/src/services/chat_utils/chat_utils.js index 7264ebcc..ab898ced 100644 --- a/src/services/chat_utils/chat_utils.js +++ b/src/services/chat_utils/chat_utils.js @@ -2,6 +2,7 @@ import { showDesktopNotification } from '../desktop_notification_utils/desktop_n 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, -- cgit v1.2.3-70-g09d2