parent
a58a3f9d97
commit
4a9f549dd2
3 changed files with 15 additions and 10 deletions
app/javascript/mastodon
|
@ -94,12 +94,11 @@ export const loadPending = () => ({
|
||||||
type: NOTIFICATIONS_LOAD_PENDING,
|
type: NOTIFICATIONS_LOAD_PENDING,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function updateEmojiReactions(emoji_reaction, accountId) {
|
export function updateEmojiReactions(emoji_reaction) {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: STATUS_EMOJI_REACTION_UPDATE,
|
type: STATUS_EMOJI_REACTION_UPDATE,
|
||||||
emoji_reaction,
|
emoji_reaction,
|
||||||
accountId,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
|
||||||
break;
|
break;
|
||||||
case 'emoji_reaction':
|
case 'emoji_reaction':
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
dispatch(updateEmojiReactions(JSON.parse(data.payload), getState().getIn(['meta', 'me'])));
|
dispatch(updateEmojiReactions(JSON.parse(data.payload)));
|
||||||
break;
|
break;
|
||||||
case 'conversation':
|
case 'conversation':
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
import { me } from 'mastodon/initial_state';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BOOKMARK_CATEGORY_EDITOR_ADD_REQUEST,
|
BOOKMARK_CATEGORY_EDITOR_ADD_REQUEST,
|
||||||
BOOKMARK_CATEGORY_EDITOR_ADD_FAIL,
|
BOOKMARK_CATEGORY_EDITOR_ADD_FAIL,
|
||||||
|
@ -47,8 +49,8 @@ const deleteStatus = (state, id, references) => {
|
||||||
return state.delete(id);
|
return state.delete(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateStatusEmojiReaction = (state, emoji_reaction, myId) => {
|
const updateStatusEmojiReaction = (state, emoji_reaction) => {
|
||||||
emoji_reaction.me = emoji_reaction.account_ids ? emoji_reaction.account_ids.indexOf(myId) >= 0 : false;
|
emoji_reaction.me = emoji_reaction.account_ids ? emoji_reaction.account_ids.indexOf(me) >= 0 : false;
|
||||||
|
|
||||||
const status = state.get(emoji_reaction.status_id);
|
const status = state.get(emoji_reaction.status_id);
|
||||||
if (!status) return state;
|
if (!status) return state;
|
||||||
|
@ -56,18 +58,22 @@ const updateStatusEmojiReaction = (state, emoji_reaction, myId) => {
|
||||||
let emoji_reactions = Array.from(status.get('emoji_reactions') || []);
|
let emoji_reactions = Array.from(status.get('emoji_reactions') || []);
|
||||||
|
|
||||||
if (emoji_reaction.count > 0) {
|
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) {
|
if (old_emoji) {
|
||||||
const index = emoji_reactions.indexOf(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 {
|
} else {
|
||||||
emoji_reactions.push(ImmutableMap(emoji_reaction));
|
emoji_reactions.push(ImmutableMap(emoji_reaction));
|
||||||
}
|
}
|
||||||
} else {
|
} 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) => {
|
const statusTranslateSuccess = (state, id, translation) => {
|
||||||
|
@ -160,7 +166,7 @@ export default function statuses(state = initialState, action) {
|
||||||
case STATUS_TRANSLATE_UNDO:
|
case STATUS_TRANSLATE_UNDO:
|
||||||
return statusTranslateUndo(state, action.id);
|
return statusTranslateUndo(state, action.id);
|
||||||
case STATUS_EMOJI_REACTION_UPDATE:
|
case STATUS_EMOJI_REACTION_UPDATE:
|
||||||
return updateStatusEmojiReaction(state, action.emoji_reaction, action.accountId);
|
return updateStatusEmojiReaction(state, action.emoji_reaction);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue