Create new stream event type: emoji_reaction
This commit is contained in:
parent
14fddebbd0
commit
1c028a20ac
15 changed files with 171 additions and 15 deletions
|
@ -17,10 +17,11 @@ import {
|
|||
STATUS_TRANSLATE_UNDO,
|
||||
STATUS_FETCH_REQUEST,
|
||||
STATUS_FETCH_FAIL,
|
||||
STATUS_EMOJI_REACTION_UPDATE,
|
||||
} from '../actions/statuses';
|
||||
import { TIMELINE_DELETE } from '../actions/timelines';
|
||||
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
|
||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||
|
||||
const importStatus = (state, status) => state.set(status.id, fromJS(status));
|
||||
|
||||
|
@ -35,6 +36,30 @@ 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 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.name === emoji_reaction.name && er.url === emoji_reaction.url);
|
||||
if (old_emoji) {
|
||||
old_emoji.account_ids = emoji_reaction.account_ids;
|
||||
old_emoji.count = emoji_reaction.count;
|
||||
old_emoji.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);
|
||||
}
|
||||
|
||||
return state.setIn([emoji_reaction.status_id, 'emoji_reactions'], ImmutableList(emoji_reactions));
|
||||
};
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
export default function statuses(state = initialState, action) {
|
||||
|
@ -89,6 +114,8 @@ export default function statuses(state = initialState, action) {
|
|||
return state.setIn([action.id, 'translation'], fromJS(action.translation));
|
||||
case STATUS_TRANSLATE_UNDO:
|
||||
return state.deleteIn([action.id, 'translation']);
|
||||
case STATUS_EMOJI_REACTION_UPDATE:
|
||||
return updateStatusEmojiReaction(state, action.emoji_reaction, action.accountId);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue