Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authormarco <marcoambrosini@pm.me>2022-03-14 13:16:48 +0300
committerJoas Schilling <coding@schilljs.com>2022-03-21 14:08:27 +0300
commit8a2f128e74f9a600b82a4e824921e40ecb2b42e1 (patch)
treed3ebc8ba8a40dfff45b3016319dc444ef2ccdaff /src/store
parentfe47a6b1f7fe16a44a312f788016d98c704f193b (diff)
Use the API response to update reactions details
Signed-off-by: marco <marcoambrosini@pm.me>
Diffstat (limited to 'src/store')
-rw-r--r--src/store/messagesStore.js30
-rw-r--r--src/store/reactionsStore.js14
2 files changed, 32 insertions, 12 deletions
diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js
index ae64cf719..3dd4833d3 100644
--- a/src/store/messagesStore.js
+++ b/src/store/messagesStore.js
@@ -978,12 +978,15 @@ const actions = {
messageId,
reaction: selectedEmoji,
})
- await addReactionToMessage(token, messageId, selectedEmoji)
- try {
- context.dispatch('getReactions', { token, messageId })
- } catch (error) {
- console.debug(error)
- }
+ // The response return an array with the reaction details for this message
+ const response = await addReactionToMessage(token, messageId, selectedEmoji)
+ // We replace the reaction details in the reactions store and wipe the old
+ // values
+ context.dispatch('updateReactions', {
+ token,
+ messageId,
+ reactionsDetails: response.data.ocs.data,
+ })
} catch (error) {
// Restore the previous state if the request fails
context.commit('removeReactionFromMessage', {
@@ -1008,12 +1011,15 @@ const actions = {
messageId,
reaction: selectedEmoji,
})
- await removeReactionFromMessage(token, messageId, selectedEmoji)
- try {
- context.dispatch('getReactions', { token, messageId })
- } catch (error) {
- console.debug(error)
- }
+ // The response return an array with the reaction details for this message
+ const response = await removeReactionFromMessage(token, messageId, selectedEmoji)
+ // We replace the reaction details in the reactions store and wipe the old
+ // values
+ context.dispatch('updateReactions', {
+ token,
+ messageId,
+ reactionsDetails: response.data.ocs.data,
+ })
} catch (error) {
// Restore the previous state if the request fails
context.commit('addReactionToMessage', {
diff --git a/src/store/reactionsStore.js b/src/store/reactionsStore.js
index ab1f92e47..821e6c60a 100644
--- a/src/store/reactionsStore.js
+++ b/src/store/reactionsStore.js
@@ -64,6 +64,20 @@ const mutations = {
const actions = {
/**
+ * Updates reactions for a given message.
+ *
+ * @param {*} context The context object
+ * @param {*} param1 conversation token, message id
+ */
+ async updateReactions(context, { token, messageId, reactionsDetails }) {
+ context.commit('addReactions', {
+ token,
+ messageId,
+ reactions: reactionsDetails,
+ })
+ },
+
+ /**
* Gets the full reactions array for a given message.
*
* @param {*} context the context object