mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
Merge pull request #16349 from nextcloud/fix/16299/chat-relay-reactions
This commit is contained in:
commit
fa481edb49
2 changed files with 26 additions and 6 deletions
|
|
@ -629,7 +629,7 @@ export function useGetMessagesProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
chatStore.processChatBlocks(token, [message], { mergeBy: chatStore.getLastKnownId(token) })
|
chatStore.processChatBlocks(token, [message], { mergeBy: chatStore.getLastKnownId(token) })
|
||||||
store.dispatch('processMessage', { token, message })
|
store.dispatch('processMessage', { token, message, fromRealtime: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
provide(GET_MESSAGES_CONTEXT_KEY, {
|
provide(GET_MESSAGES_CONTEXT_KEY, {
|
||||||
|
|
|
||||||
|
|
@ -455,8 +455,9 @@ const actions = {
|
||||||
* @param {object} payload payload;
|
* @param {object} payload payload;
|
||||||
* @param {string} payload.token conversation token;
|
* @param {string} payload.token conversation token;
|
||||||
* @param {object} payload.message message object;
|
* @param {object} payload.message message object;
|
||||||
|
* @param {boolean} [payload.fromRealtime] whether the message comes from realtime (polling or signaling)
|
||||||
*/
|
*/
|
||||||
processMessage(context, { token, message }) {
|
processMessage(context, { token, message, fromRealtime = false }) {
|
||||||
const sharedItemsStore = useSharedItemsStore()
|
const sharedItemsStore = useSharedItemsStore()
|
||||||
const actorStore = useActorStore()
|
const actorStore = useActorStore()
|
||||||
const chatExtrasStore = useChatExtrasStore()
|
const chatExtrasStore = useChatExtrasStore()
|
||||||
|
|
@ -481,6 +482,22 @@ const actions = {
|
||||||
// If parent message is presented in store and is different, we update it
|
// If parent message is presented in store and is different, we update it
|
||||||
const parentInStore = context.getters.message(token, message.parent.id)
|
const parentInStore = context.getters.message(token, message.parent.id)
|
||||||
if (Object.keys(parentInStore).length !== 0 && JSON.stringify(parentInStore) !== JSON.stringify(message.parent)) {
|
if (Object.keys(parentInStore).length !== 0 && JSON.stringify(parentInStore) !== JSON.stringify(message.parent)) {
|
||||||
|
if (fromRealtime && !message.parent.reactionsSelf) {
|
||||||
|
// Message object might come from signaling, where we don't relay this field
|
||||||
|
message.parent.reactionsSelf = parentInStore.reactionsSelf ?? []
|
||||||
|
|
||||||
|
if (message.systemMessage === MESSAGE.SYSTEM_TYPE.REACTION
|
||||||
|
&& actorStore.checkIfSelfIsActor(message)
|
||||||
|
&& !message.parent.reactionsSelf.includes(message.message)
|
||||||
|
) {
|
||||||
|
message.parent.reactionsSelf = [...message.parent.reactionsSelf, message.message]
|
||||||
|
} else if (message.systemMessage === MESSAGE.SYSTEM_TYPE.REACTION_REVOKED
|
||||||
|
&& actorStore.checkIfSelfIsActor(message)
|
||||||
|
&& message.parent.reactionsSelf.includes(message.message)
|
||||||
|
) {
|
||||||
|
message.parent.reactionsSelf = message.parent.reactionsSelf.filter((reaction) => reaction !== message.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
context.commit('addMessage', { token, message: message.parent })
|
context.commit('addMessage', { token, message: message.parent })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -632,7 +649,7 @@ const actions = {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await deleteMessage({ token, id })
|
const response = await deleteMessage({ token, id })
|
||||||
context.dispatch('processMessage', { token, message: response.data.ocs.data })
|
context.dispatch('processMessage', { token, message: response.data.ocs.data, fromRealtime: true })
|
||||||
return response.status
|
return response.status
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Restore the previous message state
|
// Restore the previous message state
|
||||||
|
|
@ -664,7 +681,7 @@ const actions = {
|
||||||
messageId,
|
messageId,
|
||||||
updatedMessage,
|
updatedMessage,
|
||||||
})
|
})
|
||||||
context.dispatch('processMessage', { token, message: response.data.ocs.data })
|
context.dispatch('processMessage', { token, message: response.data.ocs.data, fromRealtime: true })
|
||||||
EventBus.emit('editing-message-processing', { messageId, value: false })
|
EventBus.emit('editing-message-processing', { messageId, value: false })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
@ -1086,6 +1103,9 @@ const actions = {
|
||||||
let countNewMessages = 0
|
let countNewMessages = 0
|
||||||
let hasNewMention = conversation.unreadMention
|
let hasNewMention = conversation.unreadMention
|
||||||
let lastMessage = null
|
let lastMessage = null
|
||||||
|
// Determine if the messages are coming from realtime (polling) or not
|
||||||
|
// Might be falsy for own messages, if send request returns before polling is closed
|
||||||
|
const fromRealtime = !conversation?.lastMessage?.id || lastKnownMessageId >= conversation.lastMessage.id
|
||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
chatStore.processChatBlocks(token, response.data.ocs.data, {
|
chatStore.processChatBlocks(token, response.data.ocs.data, {
|
||||||
mergeBy: +lastKnownMessageId,
|
mergeBy: +lastKnownMessageId,
|
||||||
|
|
@ -1099,7 +1119,7 @@ const actions = {
|
||||||
const guestNameStore = useGuestNameStore()
|
const guestNameStore = useGuestNameStore()
|
||||||
guestNameStore.addGuestName(message, { noUpdate: false })
|
guestNameStore.addGuestName(message, { noUpdate: false })
|
||||||
}
|
}
|
||||||
context.dispatch('processMessage', { token, message })
|
context.dispatch('processMessage', { token, message, fromRealtime })
|
||||||
if (!lastMessage || message.id > lastMessage.id) {
|
if (!lastMessage || message.id > lastMessage.id) {
|
||||||
if (!message.systemMessage) {
|
if (!message.systemMessage) {
|
||||||
if (actorId !== message.actorId || actorType !== message.actorType) {
|
if (actorId !== message.actorId || actorType !== message.actorType) {
|
||||||
|
|
@ -1249,7 +1269,7 @@ const actions = {
|
||||||
chatStore.processChatBlocks(token, [response.data.ocs.data], {
|
chatStore.processChatBlocks(token, [response.data.ocs.data], {
|
||||||
mergeBy: conversationLastMessageId,
|
mergeBy: conversationLastMessageId,
|
||||||
})
|
})
|
||||||
context.dispatch('processMessage', { token, message: response.data.ocs.data })
|
context.dispatch('processMessage', { token, message: response.data.ocs.data, fromRealtime: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue