diff options
author | marco <marcoambrosini@pm.me> | 2022-02-21 17:41:35 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-21 14:08:26 +0300 |
commit | aca33f5de29a267600960056ad8878c769a054b3 (patch) | |
tree | da1daf9a328f592b715f8bec1f4cf238e8a6e273 /src/store | |
parent | 7f1d2e1e060d18847613f458fe097d0a70162f11 (diff) |
Create simplified reactions getter for messages
Signed-off-by: marco <marcoambrosini@pm.me>
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/messagesStore.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 518a674c8..282e18391 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -194,6 +194,34 @@ const getters = { // the cancel handler only exists when a message is being sent return Object.keys(state.cancelPostNewMessage).length !== 0 }, + + /** + * + * @param {*} state The state object + * @return {object} an object with the reactions (emojis) as keys and a number + * as value. + */ + simplifiedReactions: (state) => (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 {} + } + + // Check the first reaction to see if the reactions are detailed or not + const hasDetailedReactions = (typeof reactions[Object.keys(reactions)[0]]) === 'object' + + if (!hasDetailedReactions) { + return reactions + } else { + const simpleReactions = {} + for (const reaction of Object.keys(reactions)) { + simpleReactions[reaction] = reactions[reaction].length + } + return simpleReactions + } + }, } const mutations = { |