From 0967961de758b375ca61df1ba9b448aaa2e3c1f8 Mon Sep 17 00:00:00 2001
From: Eugen Rochko <eugen@zeonfederated.com>
Date: Sun, 18 Sep 2016 18:18:46 +0200
Subject: Improve how account detailed view looks, load account's statuses

---
 .../javascripts/components/reducers/timelines.jsx  | 53 +++++++++++++++++++---
 1 file changed, 47 insertions(+), 6 deletions(-)

(limited to 'app/assets/javascripts/components/reducers/timelines.jsx')

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;
   }
-- 
cgit 

