Skip to content

Commit

Permalink
Last fixes
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <dorra.jaoued7@gmail.com>
  • Loading branch information
DorraJaouad committed Jan 17, 2024
1 parent f95bce0 commit 888b0d3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 63 deletions.
5 changes: 0 additions & 5 deletions src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ export default {
this.containerId = this.container
},
beforeDestroy() {
EventBus.$off('editing-message')
EventBus.$off('message-edited')
},
methods: {
handleDragOver(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@
</template>
{{ t('spreed', 'Back') }}
</NcActionButton>
<NcActionText>
<NcActionText class="edit-history__author">
{{ t('spreed', 'Edited by: {actor}',
{actor : messageObject.lastEditActorDisplayName}) }}
</NcActionText>
<NcActionSeparator />
<NcActionText>
<template #icon>
<Pencil />
</template>
{{ editedDateTime }}
</NcActionText>
</template>
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
</style>
13 changes: 13 additions & 0 deletions src/components/MessagesList/MessagesGroup/MessagesGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
49 changes: 1 addition & 48 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
/**
Expand Down
4 changes: 2 additions & 2 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
CONVERSATION,
} from '../constants.js'
import { fetchNoteToSelfConversation } from '../services/conversationsService.js'
import { EventBus } from '../services/EventBus.js'
import {
deleteMessage,
updateLastReadMessage,
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 888b0d3

Please sign in to comment.