diff --git a/app/javascript/mastodon/actions/notifications.js b/app/javascript/mastodon/actions/notifications.js index 715b20700f8067..c8b1178d771dc2 100644 --- a/app/javascript/mastodon/actions/notifications.js +++ b/app/javascript/mastodon/actions/notifications.js @@ -94,12 +94,11 @@ export const loadPending = () => ({ type: NOTIFICATIONS_LOAD_PENDING, }); -export function updateEmojiReactions(emoji_reaction, accountId) { +export function updateEmojiReactions(emoji_reaction) { return (dispatch) => dispatch({ type: STATUS_EMOJI_REACTION_UPDATE, emoji_reaction, - accountId, }); } diff --git a/app/javascript/mastodon/actions/streaming.js b/app/javascript/mastodon/actions/streaming.js index d430ae7acf9453..6517e5ad20acce 100644 --- a/app/javascript/mastodon/actions/streaming.js +++ b/app/javascript/mastodon/actions/streaming.js @@ -105,7 +105,7 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti break; case 'emoji_reaction': // @ts-expect-error - dispatch(updateEmojiReactions(JSON.parse(data.payload), getState().getIn(['meta', 'me']))); + dispatch(updateEmojiReactions(JSON.parse(data.payload))); break; case 'conversation': // @ts-expect-error diff --git a/app/javascript/mastodon/reducers/statuses.js b/app/javascript/mastodon/reducers/statuses.js index e589f246bfbdc5..1eeea771928853 100644 --- a/app/javascript/mastodon/reducers/statuses.js +++ b/app/javascript/mastodon/reducers/statuses.js @@ -1,5 +1,7 @@ import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; +import { me } from 'mastodon/initial_state'; + import { BOOKMARK_CATEGORY_EDITOR_ADD_REQUEST, BOOKMARK_CATEGORY_EDITOR_ADD_FAIL, @@ -47,8 +49,8 @@ const deleteStatus = (state, id, references) => { return state.delete(id); }; -const updateStatusEmojiReaction = (state, emoji_reaction, myId) => { - emoji_reaction.me = emoji_reaction.account_ids ? emoji_reaction.account_ids.indexOf(myId) >= 0 : false; +const updateStatusEmojiReaction = (state, emoji_reaction) => { + emoji_reaction.me = emoji_reaction.account_ids ? emoji_reaction.account_ids.indexOf(me) >= 0 : false; const status = state.get(emoji_reaction.status_id); if (!status) return state; @@ -56,18 +58,22 @@ const updateStatusEmojiReaction = (state, emoji_reaction, myId) => { let emoji_reactions = Array.from(status.get('emoji_reactions') || []); if (emoji_reaction.count > 0) { - const old_emoji = emoji_reactions.find((er) => er.get('name') === emoji_reaction.name && (!er.get('domain') || er.get('domain') === emoji_reaction.domain)); + const old_emoji = emoji_reactions.find((er) => er.get('name') === emoji_reaction.name); if (old_emoji) { const index = emoji_reactions.indexOf(old_emoji); - emoji_reactions[index] = old_emoji.merge({ account_ids: emoji_reaction.account_ids, count: emoji_reaction.count, me: emoji_reaction.me }); + emoji_reactions[index] = old_emoji.merge({ account_ids: ImmutableList(emoji_reaction.account_ids), count: emoji_reaction.count, me: emoji_reaction.me }); } else { emoji_reactions.push(ImmutableMap(emoji_reaction)); } } else { - emoji_reactions = emoji_reactions.filter((er) => er.get('name') !== emoji_reaction.name || er.get('domain') !== emoji_reaction.domain); + emoji_reactions = emoji_reactions.filter((er) => er.get('name') !== emoji_reaction.name); } - return state.setIn([emoji_reaction.status_id, 'emoji_reactions'], ImmutableList(emoji_reactions)); + const emoji_reactions_count = emoji_reactions.reduce((prev, current) => prev + current.get('account_ids').count(), 0); + + return state + .setIn([emoji_reaction.status_id, 'emoji_reactions'], ImmutableList(emoji_reactions)) + .setIn([emoji_reaction.status_id, 'emoji_reactions_count'], emoji_reactions_count); }; const statusTranslateSuccess = (state, id, translation) => { @@ -160,7 +166,7 @@ export default function statuses(state = initialState, action) { case STATUS_TRANSLATE_UNDO: return statusTranslateUndo(state, action.id); case STATUS_EMOJI_REACTION_UPDATE: - return updateStatusEmojiReaction(state, action.emoji_reaction, action.accountId); + return updateStatusEmojiReaction(state, action.emoji_reaction); default: return state; }