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-30 00:00:45 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-30 00:00:45 +0200
commitef2b50c9acf8bdc2119bfe3d8fe127d92f32c0a7 (patch)
tree932297efa748fcc0578303a12829246ddf0f3836 /app/assets/javascripts/components/reducers/timelines.jsx
parenta41c3487bd0564d0a27be5e3937aaf898e34f6f3 (diff)
Deleting statuses from UI
Diffstat (limited to 'app/assets/javascripts/components/reducers/timelines.jsx')
-rw-r--r--app/assets/javascripts/components/reducers/timelines.jsx26
1 files changed, 24 insertions, 2 deletions
diff --git a/app/assets/javascripts/components/reducers/timelines.jsx b/app/assets/javascripts/components/reducers/timelines.jsx
index 3b8beafaa..c4aae7172 100644
--- a/app/assets/javascripts/components/reducers/timelines.jsx
+++ b/app/assets/javascripts/components/reducers/timelines.jsx
@@ -16,7 +16,10 @@ import {
   ACCOUNT_TIMELINE_FETCH_SUCCESS,
   ACCOUNT_TIMELINE_EXPAND_SUCCESS
 }                                from '../actions/accounts';
-import { STATUS_FETCH_SUCCESS }  from '../actions/statuses';
+import {
+  STATUS_FETCH_SUCCESS,
+  STATUS_DELETE_SUCCESS
+}                                from '../actions/statuses';
 import { FOLLOW_SUBMIT_SUCCESS } from '../actions/follow';
 import Immutable                 from 'immutable';
 
@@ -142,10 +145,28 @@ function updateTimeline(state, timeline, status) {
 };
 
 function deleteStatus(state, id) {
+  const status = state.getIn(['statuses', id]);
+
+  if (!status) {
+    return state;
+  }
+
+  // Remove references from timelines
   ['home', 'mentions'].forEach(function (timeline) {
     state = state.update(timeline, list => list.filterNot(item => item === id));
   });
 
+  // Remove references from account timelines
+  state = state.updateIn(['accounts_timelines', status.get('account')], Immutable.List(), list => list.filterNot(item => item === id));
+
+  // Remove reblogs of deleted status
+  const references = state.get('statuses').filter(item => item.get('reblog') === id);
+
+  references.forEach(referencingId => {
+    state = deleteStatus(state, referencingId);
+  });
+
+  // Remove normalized status
   return state.deleteIn(['statuses', id]);
 };
 
@@ -153,7 +174,7 @@ function normalizeAccount(state, account, relationship) {
   if (relationship) {
     state = normalizeRelationship(state, relationship);
   }
-  
+
   return state.setIn(['accounts', account.get('id')], account);
 };
 
@@ -194,6 +215,7 @@ export default function timelines(state = initialState, action) {
     case TIMELINE_UPDATE:
       return updateTimeline(state, action.timeline, Immutable.fromJS(action.status));
     case TIMELINE_DELETE:
+    case STATUS_DELETE_SUCCESS:
       return deleteStatus(state, action.id);
     case REBLOG_SUCCESS:
     case FAVOURITE_SUCCESS: