Skip to content

Commit

Permalink
Fix: #660 絵文字リアクションのストリーミングを受信した時点で投稿のカウントが更新されない (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Mar 31, 2024
1 parent a58a3f9 commit 4a9f549
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 1 addition & 2 deletions app/javascript/mastodon/actions/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/actions/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions app/javascript/mastodon/reducers/statuses.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -47,27 +49,31 @@ 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;

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) => {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4a9f549

Please sign in to comment.