diff options
| author | Shpuld Shpludson <shp@cock.li> | 2020-07-20 14:34:50 +0000 |
|---|---|---|
| committer | Shpuld Shpludson <shp@cock.li> | 2020-07-20 14:34:50 +0000 |
| commit | a06ab08f96ba25a5163dd3c8e7e0fec75023c302 (patch) | |
| tree | 0f977bf96ce11e078adb0e470c5a33eb5e18d630 /src/modules/chats.js | |
| parent | e0add7a44e6d626ddfcb5869cf5cade719ca2061 (diff) | |
| parent | 54dea24bb8b34021debdb2ab505a2e0b5b770ed9 (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/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) |
