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-02 18:24:26 +0300
committerJoas Schilling <coding@schilljs.com>2022-03-21 14:08:27 +0300
commitdff5d31602ef81257a56dcb08872a7ccbe4d6385 (patch)
tree9d2ea45c43d518ed9f41782694e726d4b7726ad9 /src/store
parentd3d8f124dca2ad6149abb867af8a6a71e181326a (diff)
temp
Signed-off-by: marco <marcoambrosini@pm.me>
Diffstat (limited to 'src/store')
-rw-r--r--src/store/messagesStore.js60
-rw-r--r--src/store/reactionsStore.js17
2 files changed, 39 insertions, 38 deletions
diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js
index 6d28cb748..aacb86bd7 100644
--- a/src/store/messagesStore.js
+++ b/src/store/messagesStore.js
@@ -194,38 +194,9 @@ const getters = {
return Object.keys(state.cancelPostNewMessage).length !== 0
},
- hasReactionsDetails: (state) => (token, messageId) => {
- const reactions = state.messages[token][messageId].reactions
- // Check the first reaction to see if the reactions are detailed or not
- return (typeof reactions[Object.keys(reactions)[0]]) === 'object'
- },
-
- /**
- *
- * @param {*} state The state object
- * @param getters The getters
- * @return {object} an object with the reactions (emojis) as keys and a number
- * as value.
- */
- simplifiedReactions: (state, getters) => (token, messageId) => {
- const reactions = state.messages[token][messageId].reactions
-
- // Return an empty object if there are no reactions for the message
- if (Object.keys(reactions).length === 0) {
- return {}
- }
-
- const hasReactionsDetails = getters.hasReactionsDetails(token, messageId)
-
- if (!hasReactionsDetails) {
- return reactions
- } else {
- const simpleReactions = {}
- for (const reaction of Object.keys(reactions)) {
- simpleReactions[reaction] = reactions[reaction].length
- }
- return simpleReactions
- }
+ // Returns true if the message has reactions
+ hasReactions: (state) => (token, messageId) => {
+ return Object.keys(state.messages[token][messageId].reactions).length !== 0
},
}
@@ -372,12 +343,20 @@ const mutations = {
// Increases reaction count for a particular reaction on a message
addReactionToMessage(state, { token, messageId, reaction }) {
- state.messages[token][messageId].reactions[reaction]++
+ if (!state.messages[token][messageId].reactions[reaction]) {
+ Vue.set(state.messages[token][messageId].reactions, reaction, 0)
+ }
+ const reactionCount = state.messages[token][messageId].reactions[reaction] + 1
+ Vue.set(state.messages[token][messageId].reactions, reaction, reactionCount)
},
// Decreases reaction count for a particular reaction on a message
removeReactionFromMessage(state, { token, messageId, reaction }) {
- state.messages[token][messageId].reactions[reaction]--
+ const reactionCount = state.messages[token][messageId].reactions[reaction] - 1
+ Vue.set(state.messages[token][messageId].reactions, reaction, reactionCount)
+ if (state.messages[token][messageId].reactions[reaction] <= 0) {
+ Vue.delete(state.messages[token][messageId].reactions, reaction)
+ }
},
}
@@ -488,6 +467,7 @@ const actions = {
token,
isReplyable: false,
sendingFailure: '',
+ reactions: {},
referenceId: Hex.stringify(SHA256(tempId)),
})
@@ -992,6 +972,11 @@ const actions = {
reaction: selectedEmoji,
})
await addReactionToMessage(token, messageId, selectedEmoji)
+ try {
+ context.dispatch('getReactions', { token, messageId })
+ } catch (error) {
+ console.debug(error)
+ }
} catch (error) {
// Restore the previous state if the request fails
context.commit('removeReactionFromMessage', {
@@ -1004,7 +989,7 @@ const actions = {
},
/**
- * Removes a single reactin to a message for the current user.
+ * Removes a single reaction from a message for the current user.
*
* @param {*} context the context object
* @param {*} param1 conversation token, message id and selected emoji (string)
@@ -1017,6 +1002,11 @@ const actions = {
reaction: selectedEmoji,
})
await removeReactionFromMessage(token, messageId, selectedEmoji)
+ try {
+ context.dispatch('getReactions', { token, messageId })
+ } catch (error) {
+ console.debug(error)
+ }
} 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 c3c7ce0e5..ab1f92e47 100644
--- a/src/store/reactionsStore.js
+++ b/src/store/reactionsStore.js
@@ -40,14 +40,25 @@ const getters = {
return undefined
}
},
+
+ // Checks if a user has already reacted to a message with a particular reaction
+ userHasReacted: (state) => (actorId, token, messageId, reaction) => {
+ if (!state?.reactions?.[token]?.[messageId]?.[reaction]) {
+ return false
+ }
+ return state?.reactions?.[token]?.[messageId]?.[reaction].filter(item => {
+ return item.actorId === actorId
+ }).length !== 0
+ },
}
const mutations = {
addReactions(state, { token, messageId, reactions }) {
if (!state.reactions[token]) {
- Vue.set(state.reactions, [token], [messageId])
+ Vue.set(state.reactions, token, {})
+
}
- state.reactions[token][messageId] = reactions
+ Vue.set(state.reactions[token], messageId, reactions)
},
}
@@ -59,7 +70,7 @@ const actions = {
* @param {*} param1 conversation token, message id
*/
async getReactions(context, { token, messageId }) {
-
+ console.debug('getting reactions details')
try {
const response = await getReactionsDetails(token, messageId)
context.commit('addReactions', {