about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers/timelines.jsx
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-18 18:18:46 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-18 18:18:46 +0200
commit0967961de758b375ca61df1ba9b448aaa2e3c1f8 (patch)
tree5935732cf384f05b35d30c16814b481d9012661b /app/assets/javascripts/components/reducers/timelines.jsx
parentdafcb021534d2a19ff5d4c1f9bedafb52a2ce77f (diff)
Improve how account detailed view looks, load account's statuses
Diffstat (limited to 'app/assets/javascripts/components/reducers/timelines.jsx')
-rw-r--r--app/assets/javascripts/components/reducers/timelines.jsx53
1 files changed, 47 insertions, 6 deletions
diff --git a/app/assets/javascripts/components/reducers/timelines.jsx b/app/assets/javascripts/components/reducers/timelines.jsx
index 522d6be39..7fd29c812 100644
--- a/app/assets/javascripts/components/reducers/timelines.jsx
+++ b/app/assets/javascripts/components/reducers/timelines.jsx
@@ -1,20 +1,50 @@
-import { TIMELINE_SET, TIMELINE_UPDATE, TIMELINE_DELETE }                                            from '../actions/timelines';
-import { REBLOG_SUCCESS, FAVOURITE_SUCCESS }                                                         from '../actions/interactions';
-import { ACCOUNT_SET_SELF, ACCOUNT_FETCH_SUCCESS, ACCOUNT_FOLLOW_SUCCESS, ACCOUNT_UNFOLLOW_SUCCESS } from '../actions/accounts';
-import { STATUS_FETCH_SUCCESS }                                                                      from '../actions/statuses';
-import { FOLLOW_SUBMIT_SUCCESS }                                                                     from '../actions/follow';
-import Immutable                                                                                     from 'immutable';
+import {
+  TIMELINE_SET,
+  TIMELINE_UPDATE,
+  TIMELINE_DELETE
+}                                from '../actions/timelines';
+import {
+  REBLOG_SUCCESS,
+  FAVOURITE_SUCCESS
+}                                from '../actions/interactions';
+import {
+  ACCOUNT_SET_SELF,
+  ACCOUNT_FETCH_SUCCESS,
+  ACCOUNT_FOLLOW_SUCCESS,
+  ACCOUNT_UNFOLLOW_SUCCESS,
+  ACCOUNT_TIMELINE_FETCH_SUCCESS
+}                                from '../actions/accounts';
+import { STATUS_FETCH_SUCCESS }  from '../actions/statuses';
+import { FOLLOW_SUBMIT_SUCCESS } from '../actions/follow';
+import Immutable                 from 'immutable';
 
 const initialState = Immutable.Map({
   home: Immutable.List([]),
   mentions: Immutable.List([]),
   statuses: Immutable.Map(),
   accounts: Immutable.Map(),
+  accounts_timelines: Immutable.Map(),
   me: null,
   ancestors: Immutable.Map(),
   descendants: Immutable.Map()
 });
 
+export function selectStatus(state, id) {
+  let status = state.getIn(['timelines', 'statuses', id], null);
+
+  if (status === null) {
+    return null;
+  }
+
+  status = status.set('account', state.getIn(['timelines', 'accounts', status.get('account')]));
+
+  if (status.get('reblog') !== null) {
+    status = status.set('reblog', selectStatus(state, status.get('reblog')));
+  }
+
+  return status;
+};
+
 function statusToMaps(state, status) {
   // Separate account
   let account = status.get('account');
@@ -59,6 +89,15 @@ function timelineToMaps(state, timeline, statuses) {
   return state;
 };
 
+function accountTimelineToMaps(state, accountId, statuses) {
+  statuses.forEach((status, i) => {
+    state = statusToMaps(state, status);
+    state = state.updateIn(['accounts_timelines', accountId], Immutable.List(), list => list.set(i, status.get('id')));
+  });
+
+  return state;
+};
+
 function updateTimelineWithMaps(state, timeline, status) {
   state = statusToMaps(state, status);
   state = state.update(timeline, list => list.unshift(status.get('id')));
@@ -120,6 +159,8 @@ export default function timelines(state = initialState, action) {
       return accountToMaps(state, Immutable.fromJS(action.account));
     case STATUS_FETCH_SUCCESS:
       return contextToMaps(state, Immutable.fromJS(action.status), Immutable.fromJS(action.context.ancestors), Immutable.fromJS(action.context.descendants));
+    case ACCOUNT_TIMELINE_FETCH_SUCCESS:
+      return accountTimelineToMaps(state, action.id, Immutable.fromJS(action.statuses));
     default:
       return state;
   }