aboutsummaryrefslogtreecommitdiff
path: root/src/modules/chats.js
diff options
context:
space:
mode:
authorShpuld Shpludson <shp@cock.li>2020-11-02 05:36:42 +0000
committerShpuld Shpludson <shp@cock.li>2020-11-02 05:36:42 +0000
commit5254fdba75fc8d645c2235902a39b79c45f9aa6f (patch)
treeac329a5fc0448d804d5aa8d77e137b00e64a4491 /src/modules/chats.js
parent590f8e17544969b1fc2456b3724e85b16cf81bdd (diff)
parent78e5a639228ba846e38ae722590aec1310275c79 (diff)
Merge branch 'optimistic-chat-posting' into 'develop'
Optimistic / nonblocking message posting for chats See merge request pleroma/pleroma-fe!1228
Diffstat (limited to 'src/modules/chats.js')
-rw-r--r--src/modules/chats.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/modules/chats.js b/src/modules/chats.js
index 21e30933..0a373d88 100644
--- a/src/modules/chats.js
+++ b/src/modules/chats.js
@@ -16,7 +16,8 @@ const defaultState = {
openedChats: {},
openedChatMessageServices: {},
fetcher: undefined,
- currentChatId: null
+ currentChatId: null,
+ lastReadMessageId: null
}
const getChatById = (state, id) => {
@@ -92,9 +93,14 @@ const chats = {
commit('setCurrentChatFetcher', { fetcher: undefined })
},
readChat ({ rootState, commit, dispatch }, { id, lastReadId }) {
+ const isNewMessage = rootState.chats.lastReadMessageId !== lastReadId
+
dispatch('resetChatNewMessageCount')
- commit('readChat', { id })
- rootState.api.backendInteractor.readChat({ id, lastReadId })
+ commit('readChat', { id, lastReadId })
+
+ if (isNewMessage) {
+ rootState.api.backendInteractor.readChat({ id, lastReadId })
+ }
},
deleteChatMessage ({ rootState, commit }, value) {
rootState.api.backendInteractor.deleteChatMessage(value)
@@ -106,6 +112,9 @@ const chats = {
},
clearOpenedChats ({ rootState, commit, dispatch, rootGetters }) {
commit('clearOpenedChats', { commit })
+ },
+ handleMessageError ({ commit }, value) {
+ commit('handleMessageError', { commit, ...value })
}
},
mutations: {
@@ -208,11 +217,16 @@ const chats = {
}
}
},
- readChat (state, { id }) {
+ readChat (state, { id, lastReadId }) {
+ state.lastReadMessageId = lastReadId
const chat = getChatById(state, id)
if (chat) {
chat.unread = 0
}
+ },
+ handleMessageError (state, { chatId, fakeId, isRetry }) {
+ const chatMessageService = state.openedChatMessageServices[chatId]
+ chatService.handleMessageError(chatMessageService, fakeId, isRetry)
}
}
}