From 888b0d3c8f9477a2fc07068261eb544865c6bd3a Mon Sep 17 00:00:00 2001 From: DorraJaouad Date: Wed, 17 Jan 2024 14:46:37 +0100 Subject: [PATCH] Last fixes Signed-off-by: DorraJaouad --- src/components/ChatView.vue | 5 -- .../MessageButtonsBar/MessageButtonsBar.vue | 15 +++--- .../MessagesGroup/MessagesGroup.vue | 13 +++++ src/components/MessagesList/MessagesList.vue | 49 +------------------ src/components/NewMessage/NewMessage.vue | 4 +- src/store/messagesStore.js | 3 +- 6 files changed, 26 insertions(+), 63 deletions(-) diff --git a/src/components/ChatView.vue b/src/components/ChatView.vue index 61c1610ea7e5..d8d201241a51 100644 --- a/src/components/ChatView.vue +++ b/src/components/ChatView.vue @@ -174,11 +174,6 @@ export default { this.containerId = this.container }, - beforeDestroy() { - EventBus.$off('editing-message') - EventBus.$off('message-edited') - }, - methods: { handleDragOver(event) { diff --git a/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue b/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue index d8fc2a29a709..460ab8b9951e 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue @@ -245,12 +245,14 @@ {{ t('spreed', 'Back') }} - + {{ t('spreed', 'Edited by: {actor}', {actor : messageObject.lastEditActorDisplayName}) }} - + {{ editedDateTime }} @@ -538,12 +540,12 @@ export default { }, isEditable() { - if (!this.isModifiable || this.isObjectShare) { + if (!this.isModifiable || this.isObjectShare + || (!this.$store.getters.isModerator && !this.isMyMsg)) { return false } return (moment(this.timestamp * 1000).add(1, 'd')) > moment() - && (this.$store.getters.isModerator || this.isMyMsg) }, isDeleteable() { @@ -881,8 +883,7 @@ export default { background: no-repeat center var(--icon-triangle-e-dark); } } - -:deep(.action-text) { - padding-left: 5px; +.edit-history__author { + padding-left: 10px; } diff --git a/src/components/MessagesList/MessagesGroup/MessagesGroup.vue b/src/components/MessagesList/MessagesGroup/MessagesGroup.vue index 3a176ea6eef1..e1f683560f0c 100644 --- a/src/components/MessagesList/MessagesGroup/MessagesGroup.vue +++ b/src/components/MessagesList/MessagesGroup/MessagesGroup.vue @@ -92,6 +92,19 @@ export default { default: 0, }, + lastEditTimestamp: { + type: Number, + default: 0, + }, + lastEditActorId: { + type: String, + default: '', + }, + lastEditActorType: { + type: String, + default: '', + }, + lastEditActorDisplayName: { type: String, default: '' diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index 19fae2479dce..bf5693e1ad20 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -635,54 +635,7 @@ export default { }, handleMessageEdited(id) { - // regroup messagesGroupedByAuthor when a message is edited - // find the group that contains the id and split it into 3 groups - // 1. the messages before the edited message - // 2. the edited message - // 3. the messages after the edited message - const groups = this.messagesGroupedByAuthor - const groupIndex = groups.findIndex(group => group.messages.some(message => message.id === id)) - if (groupIndex === -1) { - return - } - // split the group into 3 groups - const group = groups[groupIndex] - const messageIndex = group.messages.findIndex(message => message.id === id) - const beforeMessages = group.messages.slice(0, messageIndex) - const afterMessages = group.messages.slice(messageIndex + 1) - const editedMessage = group.messages[messageIndex] - // remove the old group and add the 3 new groups at the same index - groups.splice(groupIndex, 1, - ...(beforeMessages.length - ? [{ - id: beforeMessages[0].id, - messages: beforeMessages, - dateSeparator: group.dateSeparator, - previousMessageId: group.previousMessageId, - nextMessageId: editedMessage.id, - isSystemMessagesGroup: group.isSystemMessagesGroup, - }] - : []), - { - id: editedMessage.id, - messages: [editedMessage], - dateSeparator: group.dateSeparator, - previousMessageId: beforeMessages.length ? beforeMessages.at(-1).id : group.previousMessageId, - nextMessageId: afterMessages.length ? afterMessages[0].id : group.nextMessageId, - isSystemMessagesGroup: group.isSystemMessagesGroup, - }, - ...(afterMessages.length - ? [{ - id: afterMessages[0].id, - messages: afterMessages, - dateSeparator: group.dateSeparator, - previousMessageId: editedMessage.id, - nextMessageId: group.nextMessageId, - isSystemMessagesGroup: group.isSystemMessagesGroup, - }] - : []), - ) - + this.messagesGroupedByAuthor = this.prepareMessagesGroups(this.messagesList) }, /** diff --git a/src/components/NewMessage/NewMessage.vue b/src/components/NewMessage/NewMessage.vue index 7f69399352f2..32465f500ed4 100644 --- a/src/components/NewMessage/NewMessage.vue +++ b/src/components/NewMessage/NewMessage.vue @@ -675,12 +675,12 @@ export default { async handleEdit() { try { - await editMessage({ + const response = await editMessage({ token: this.token, messageId: this.messageToEdit.id, updatedMessage: this.text.trim() }) - EventBus.$emit('message-edited', this.messageToEdit.id) + this.$store.dispatch('processMessage', { token: this.token, message: response.data.ocs.data }) this.chatExtrasStore.removeMessageIdToEdit(this.token) } catch { this.$emit('failure') diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 8640c6e737fe..4222234c9626 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -32,6 +32,7 @@ import { CONVERSATION, } from '../constants.js' import { fetchNoteToSelfConversation } from '../services/conversationsService.js' +import { EventBus } from '../services/EventBus.js' import { deleteMessage, updateLastReadMessage, @@ -536,7 +537,7 @@ const actions = { if (Object.keys(parentInStore).length !== 0) { context.commit('addMessage', { token, message: message.parent }) if (message.systemMessage === 'message_edited') { - // End of process for edited messages + EventBus.$emit('message-edited') return } }