diff options
| author | eugenijm <eugenijm@protonmail.com> | 2020-07-13 00:06:45 +0300 |
|---|---|---|
| committer | eugenijm <eugenijm@protonmail.com> | 2020-07-13 06:27:51 +0300 |
| commit | 2c35afeebf4e508fd911a90d3c4af3a75e4484ab (patch) | |
| tree | e63cfc5c4010a76b6c883be5fe0050a7bb7b985b /src/modules/chats.js | |
| parent | 3e09a708f600b47dde831eeddb412828b38a0cf4 (diff) | |
Add desktop chat notifications
Diffstat (limited to 'src/modules/chats.js')
| -rw-r--r-- | src/modules/chats.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/modules/chats.js b/src/modules/chats.js index 228d6256..c7609018 100644 --- a/src/modules/chats.js +++ b/src/modules/chats.js @@ -2,6 +2,7 @@ import Vue from 'vue' import { find, omitBy, orderBy, sumBy } from 'lodash' import chatService from '../services/chat_service/chat_service.js' import { parseChat, parseChatMessage } from '../services/entity_normalizer/entity_normalizer.service.js' +import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js' const emptyChatList = () => ({ data: [], @@ -59,8 +60,12 @@ const chats = { return chats }) }, - addNewChats ({ rootState, commit, dispatch, rootGetters }, { chats }) { - commit('addNewChats', { dispatch, chats, rootGetters }) + addNewChats (store, { chats }) { + const { commit, dispatch, rootGetters } = store + const newChatMessageSideEffects = (chat) => { + maybeShowChatNotification(store, chat) + } + commit('addNewChats', { dispatch, chats, rootGetters, newChatMessageSideEffects }) }, updateChat ({ commit }, { chat }) { commit('updateChat', { chat }) @@ -130,13 +135,17 @@ const chats = { setCurrentChatId (state, { chatId }) { state.currentChatId = chatId }, - addNewChats (state, { _dispatch, chats, _rootGetters }) { + addNewChats (state, { chats, newChatMessageSideEffects }) { chats.forEach((updatedChat) => { const chat = getChatById(state, updatedChat.id) if (chat) { + const isNewMessage = (chat.lastMessage && chat.lastMessage.id) !== (updatedChat.lastMessage && updatedChat.lastMessage.id) chat.lastMessage = updatedChat.lastMessage chat.unread = updatedChat.unread + if (isNewMessage && chat.unread) { + newChatMessageSideEffects(updatedChat) + } } else { state.chatList.data.push(updatedChat) Vue.set(state.chatList.idStore, updatedChat.id, updatedChat) |
