summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaksim Sukharev <antreesy.web@gmail.com>2024-02-01 18:53:10 +0100
committerMaksim Sukharev <antreesy.web@gmail.com>2024-02-05 11:48:48 +0100
commit64ab1beaa5f8d201f148f14ef1f92b1835c3d11c (patch)
treeddcbedf891f9f2a13b37795c3181b4b4bb820c89
parentbefea257ba96ab7757f0d56040fb2932896225e8 (diff)
chore(messages): create editMessage action in the store
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
-rw-r--r--src/components/NewMessage/NewMessage.vue6
-rw-r--r--src/store/messagesStore.js32
2 files changed, 34 insertions, 4 deletions
diff --git a/src/components/NewMessage/NewMessage.vue b/src/components/NewMessage/NewMessage.vue
index a4e80bda1..09d16fa90 100644
--- a/src/components/NewMessage/NewMessage.vue
+++ b/src/components/NewMessage/NewMessage.vue
@@ -222,7 +222,6 @@ import { CONVERSATION, PARTICIPANT, PRIVACY } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'
import { shareFile } from '../../services/filesSharingServices.js'
import { searchPossibleMentions } from '../../services/mentionsService.js'
-import { editMessage } from '../../services/messagesService.js'
import { useChatExtrasStore } from '../../stores/chatExtras.js'
import { useSettingsStore } from '../../stores/settings.js'
import { fetchClipboardContent } from '../../utils/clipboard.js'
@@ -692,12 +691,11 @@ export default {
async handleEdit() {
try {
- const response = await editMessage({
+ await this.$store.dispatch('editMessage', {
token: this.token,
messageId: this.messageToEdit.id,
- updatedMessage: this.text.trim()
+ updatedMessage: this.text.trim(),
})
- this.$store.dispatch('processMessage', { token: this.token, message: response.data.ocs.data })
this.chatExtrasStore.removeMessageIdToEdit(this.token)
this.resetTypingIndicator()
} catch {
diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js
index 27e0cc0a5..91962c6b6 100644
--- a/src/store/messagesStore.js
+++ b/src/store/messagesStore.js
@@ -35,6 +35,7 @@ import { fetchNoteToSelfConversation } from '../services/conversationsService.js
import { EventBus } from '../services/EventBus.js'
import {
deleteMessage,
+ editMessage,
updateLastReadMessage,
fetchMessages,
lookForNewMessages,
@@ -629,6 +630,37 @@ const actions = {
},
/**
+ * Edit a message text
+ *
+ * @param {object} context default store context;
+ * @param {object} payload payload;
+ * @param {string} payload.token The conversation token
+ * @param {string} payload.messageId The message id
+ * @param {string} payload.updatedMessage The modified text of the message / file share caption
+ */
+ async editMessage(context, { token, messageId, updatedMessage }) {
+ const message = Object.assign({}, context.getters.message(token, messageId))
+ context.commit('addMessage', {
+ token,
+ message: { ...message, message: updatedMessage },
+ })
+
+ try {
+ const response = await editMessage({
+ token,
+ messageId,
+ updatedMessage,
+ })
+ context.dispatch('processMessage', { token, message: response.data.ocs.data })
+ } catch (error) {
+ console.error(error)
+ // Restore the previous message state
+ context.commit('addMessage', { token, message })
+ throw error
+ }
+ },
+
+ /**
* Creates a temporary message ready to be posted, based
* on the message to be replied and the current actor
*