about summary refs log tree commit diff
path: root/app/javascript/flavours
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-04-19 16:43:02 +0200
committerThibaut Girka <thib@sitedethib.com>2018-04-19 16:43:02 +0200
commit13fa8ec2c7d75c2d6a2d49c49a87b5fb08c95d14 (patch)
tree2b61463251139de949ab6684823631c4fbd1e50b /app/javascript/flavours
parentf84b4d90cba24b3cd57cb07cfc4b3a4dca25015f (diff)
[Glitch] Fix status filtering in contexts reducer
Port 1a37d7e252aa41fd1c66e780e1a2a1426d8f3545 to glitch-soc
Diffstat (limited to 'app/javascript/flavours')
-rw-r--r--app/javascript/flavours/glitch/reducers/contexts.js38
1 files changed, 22 insertions, 16 deletions
diff --git a/app/javascript/flavours/glitch/reducers/contexts.js b/app/javascript/flavours/glitch/reducers/contexts.js
index 59dabc2b9..effd70756 100644
--- a/app/javascript/flavours/glitch/reducers/contexts.js
+++ b/app/javascript/flavours/glitch/reducers/contexts.js
@@ -21,24 +21,30 @@ const normalizeContext = (state, id, ancestors, descendants) => {
   });
 };
 
-const deleteFromContexts = (state, id) => {
-  state.getIn(['descendants', id], ImmutableList()).forEach(descendantId => {
-    state = state.updateIn(['ancestors', descendantId], ImmutableList(), list => list.filterNot(itemId => itemId === id));
-  });
+const deleteFromContexts = (immutableState, ids) => immutableState.withMutations(state => {
+  state.update('ancestors', immutableAncestors => immutableAncestors.withMutations(ancestors => {
+    state.update('descendants', immutableDescendants => immutableDescendants.withMutations(descendants => {
+      ids.forEach(id => {
+        descendants.get(id, ImmutableList()).forEach(descendantId => {
+          ancestors.update(descendantId, ImmutableList(), list => list.filterNot(itemId => itemId === id));
+        });
 
-  state.getIn(['ancestors', id], ImmutableList()).forEach(ancestorId => {
-    state = state.updateIn(['descendants', ancestorId], ImmutableList(), list => list.filterNot(itemId => itemId === id));
-  });
+        ancestors.get(id, ImmutableList()).forEach(ancestorId => {
+          descendants.update(ancestorId, ImmutableList(), list => list.filterNot(itemId => itemId === id));
+        });
 
-  state = state.deleteIn(['descendants', id]).deleteIn(['ancestors', id]);
+        descendants.delete(id);
+        ancestors.delete(id);
+      });
+    }));
+  }));
+});
 
-  return state;
-};
+const filterContexts = (state, relationship, statuses) => {
+  const ownedStatusIds = statuses.filter(status => status.get('account') === relationship.id)
+                                 .map(status => status.get('id'));
 
-const filterContexts = (state, relationship) => {
-  return state.map(
-    statuses => statuses.filter(
-      status => status.get('account') !== relationship.id));
+  return deleteFromContexts(state, ownedStatusIds);
 };
 
 const updateContext = (state, status, references) => {
@@ -61,11 +67,11 @@ export default function contexts(state = initialState, action) {
   switch(action.type) {
   case ACCOUNT_BLOCK_SUCCESS:
   case ACCOUNT_MUTE_SUCCESS:
-    return filterContexts(state, action.relationship);
+    return filterContexts(state, action.relationship, action.statuses);
   case CONTEXT_FETCH_SUCCESS:
     return normalizeContext(state, action.id, action.ancestors, action.descendants);
   case TIMELINE_DELETE:
-    return deleteFromContexts(state, action.id);
+    return deleteFromContexts(state, [action.id]);
   case TIMELINE_CONTEXT_UPDATE:
     return updateContext(state, action.status, action.references);
   default: