diff options
author | marco <marcoambrosini@pm.me> | 2022-02-22 13:45:09 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-21 14:08:26 +0300 |
commit | 380c193396299d8a835b26342497db0d06d70c85 (patch) | |
tree | bfcd39d862473e9e00d6fc21854cf43c9c9d1c12 /src/store | |
parent | d2f05c1485eeb5d292f10e153b0cf7543f30dae4 (diff) |
Create a dedicated getter to know whether a message has detailed reaction or not
Signed-off-by: marco <marcoambrosini@pm.me>
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/messagesStore.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index a2cd87515..6fc60ae3f 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -195,13 +195,20 @@ 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) => (token, messageId) => { + simplifiedReactions: (state, getters) => (token, messageId) => { const reactions = state.messages[token][messageId].reactions // Return an empty object if there are no reactions for the message @@ -209,10 +216,9 @@ const getters = { return {} } - // Check the first reaction to see if the reactions are detailed or not - const hasDetailedReactions = (typeof reactions[Object.keys(reactions)[0]]) === 'object' + const hasReactionsDetails = getters.hasReactionsDetails(token, messageId) - if (!hasDetailedReactions) { + if (!hasReactionsDetails) { return reactions } else { const simpleReactions = {} |