]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/reducers/statuses.js
Summary: fix slowness due to layout thrashing when reloading a large … (#12661)
[mastodon.git] / app / javascript / mastodon / reducers / statuses.js
1 import {
2 REBLOG_REQUEST,
3 REBLOG_FAIL,
4 FAVOURITE_REQUEST,
5 FAVOURITE_FAIL,
6 UNFAVOURITE_SUCCESS,
7 BOOKMARK_REQUEST,
8 BOOKMARK_FAIL,
9 } from '../actions/interactions';
10 import {
11 STATUS_MUTE_SUCCESS,
12 STATUS_UNMUTE_SUCCESS,
13 STATUS_REVEAL,
14 STATUS_HIDE,
15 STATUS_COLLAPSE,
16 } from '../actions/statuses';
17 import { TIMELINE_DELETE } from '../actions/timelines';
18 import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
19 import { Map as ImmutableMap, fromJS } from 'immutable';
20
21 const importStatus = (state, status) => state.set(status.id, fromJS(status));
22
23 const importStatuses = (state, statuses) =>
24 state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status)));
25
26 const deleteStatus = (state, id, references) => {
27 references.forEach(ref => {
28 state = deleteStatus(state, ref[0], []);
29 });
30
31 return state.delete(id);
32 };
33
34 const initialState = ImmutableMap();
35
36 export default function statuses(state = initialState, action) {
37 switch(action.type) {
38 case STATUS_IMPORT:
39 return importStatus(state, action.status);
40 case STATUSES_IMPORT:
41 return importStatuses(state, action.statuses);
42 case FAVOURITE_REQUEST:
43 return state.setIn([action.status.get('id'), 'favourited'], true);
44 case UNFAVOURITE_SUCCESS:
45 const favouritesCount = action.status.get('favourites_count');
46 return state.setIn([action.status.get('id'), 'favourites_count'], favouritesCount - 1);
47 case FAVOURITE_FAIL:
48 return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false);
49 case BOOKMARK_REQUEST:
50 return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'bookmarked'], true);
51 case BOOKMARK_FAIL:
52 return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'bookmarked'], false);
53 case REBLOG_REQUEST:
54 return state.setIn([action.status.get('id'), 'reblogged'], true);
55 case REBLOG_FAIL:
56 return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'reblogged'], false);
57 case STATUS_MUTE_SUCCESS:
58 return state.setIn([action.id, 'muted'], true);
59 case STATUS_UNMUTE_SUCCESS:
60 return state.setIn([action.id, 'muted'], false);
61 case STATUS_REVEAL:
62 return state.withMutations(map => {
63 action.ids.forEach(id => {
64 if (!(state.get(id) === undefined)) {
65 map.setIn([id, 'hidden'], false);
66 }
67 });
68 });
69 case STATUS_HIDE:
70 return state.withMutations(map => {
71 action.ids.forEach(id => {
72 if (!(state.get(id) === undefined)) {
73 map.setIn([id, 'hidden'], true);
74 }
75 });
76 });
77 case STATUS_COLLAPSE:
78 return state.setIn([action.id, 'collapsed'], action.isCollapsed);
79 case TIMELINE_DELETE:
80 return deleteStatus(state, action.id, action.references);
81 default:
82 return state;
83 }
84 };
This page took 0.108558 seconds and 5 git commands to generate.