Merge branch 'optimistic-chat-posting' into 'develop'
Optimistic / nonblocking message posting for chats See merge request pleroma/pleroma-fe!1228
This commit is contained in:
commit
5254fdba75
13 changed files with 212 additions and 44 deletions
|
@ -75,12 +75,18 @@ const api = {
|
|||
} else if (message.event === 'delete') {
|
||||
dispatch('deleteStatusById', message.id)
|
||||
} else if (message.event === 'pleroma:chat_update') {
|
||||
dispatch('addChatMessages', {
|
||||
chatId: message.chatUpdate.id,
|
||||
messages: [message.chatUpdate.lastMessage]
|
||||
})
|
||||
dispatch('updateChat', { chat: message.chatUpdate })
|
||||
maybeShowChatNotification(store, message.chatUpdate)
|
||||
// The setTimeout wrapper is a temporary band-aid to avoid duplicates for the user's own messages when doing optimistic sending.
|
||||
// The cause of the duplicates is the WS event arriving earlier than the HTTP response.
|
||||
// This setTimeout wrapper can be removed once the commit `8e41baff` is in the stable Pleroma release.
|
||||
// (`8e41baff` adds the idempotency key to the chat message entity, which PleromaFE uses when it's available, and it makes this artificial delay unnecessary).
|
||||
setTimeout(() => {
|
||||
dispatch('addChatMessages', {
|
||||
chatId: message.chatUpdate.id,
|
||||
messages: [message.chatUpdate.lastMessage]
|
||||
})
|
||||
dispatch('updateChat', { chat: message.chatUpdate })
|
||||
maybeShowChatNotification(store, message.chatUpdate)
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue