about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-23 22:57:57 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-23 22:57:57 +0100
commit7cee27f51790617859da87c7aef432373b40aad4 (patch)
tree68bec6934312f7155faddc96f4b77473ba9a8205 /app/assets/javascripts/components/reducers
parent3373ae02ded0ac5847350da9f9550721cdebe732 (diff)
Fix unfollows not clearing reblogs, fix blocks not clearing reblogs and notifications,
skip ActionCable for follow/unfollow/block events, instead clear UI from
blocked account's posts instantly if block request succeeds. Add forgotten
i18n for sensitive content
Diffstat (limited to 'app/assets/javascripts/components/reducers')
-rw-r--r--app/assets/javascripts/components/reducers/notifications.jsx7
-rw-r--r--app/assets/javascripts/components/reducers/statuses.jsx17
-rw-r--r--app/assets/javascripts/components/reducers/timelines.jsx20
3 files changed, 42 insertions, 2 deletions
diff --git a/app/assets/javascripts/components/reducers/notifications.jsx b/app/assets/javascripts/components/reducers/notifications.jsx
index 0e67e732a..617a833d2 100644
--- a/app/assets/javascripts/components/reducers/notifications.jsx
+++ b/app/assets/javascripts/components/reducers/notifications.jsx
@@ -3,6 +3,7 @@ import {
   NOTIFICATIONS_REFRESH_SUCCESS,
   NOTIFICATIONS_EXPAND_SUCCESS
 } from '../actions/notifications';
+import { ACCOUNT_BLOCK_SUCCESS } from '../actions/accounts';
 import Immutable from 'immutable';
 
 const initialState = Immutable.Map({
@@ -43,6 +44,10 @@ const appendNormalizedNotifications = (state, notifications, next) => {
   return state.update('items', list => list.push(...items)).set('next', next);
 };
 
+const filterNotifications = (state, relationship) => {
+  return state.update('items', list => list.filterNot(item => item.get('account') === relationship.id));
+};
+
 export default function notifications(state = initialState, action) {
   switch(action.type) {
     case NOTIFICATIONS_UPDATE:
@@ -51,6 +56,8 @@ export default function notifications(state = initialState, action) {
       return normalizeNotifications(state, action.notifications, action.next);
     case NOTIFICATIONS_EXPAND_SUCCESS:
       return appendNormalizedNotifications(state, action.notifications, action.next);
+    case ACCOUNT_BLOCK_SUCCESS:
+      return filterNotifications(state, action.relationship);
     default:
       return state;
   }
diff --git a/app/assets/javascripts/components/reducers/statuses.jsx b/app/assets/javascripts/components/reducers/statuses.jsx
index 2a24a75e4..f42b1a481 100644
--- a/app/assets/javascripts/components/reducers/statuses.jsx
+++ b/app/assets/javascripts/components/reducers/statuses.jsx
@@ -16,7 +16,8 @@ import {
 } from '../actions/timelines';
 import {
   ACCOUNT_TIMELINE_FETCH_SUCCESS,
-  ACCOUNT_TIMELINE_EXPAND_SUCCESS
+  ACCOUNT_TIMELINE_EXPAND_SUCCESS,
+  ACCOUNT_BLOCK_SUCCESS
 } from '../actions/accounts';
 import {
   NOTIFICATIONS_UPDATE,
@@ -56,6 +57,18 @@ const deleteStatus = (state, id, references) => {
   return state.delete(id);
 };
 
+const filterStatuses = (state, relationship) => {
+  state.forEach(status => {
+    if (status.get('account') !== relationship.id) {
+      return;
+    }
+
+    state = deleteStatus(state, status.get('id'), state.filter(item => item.get('reblog') === status.get('id')));
+  });
+
+  return state;
+};
+
 const initialState = Immutable.Map();
 
 export default function statuses(state = initialState, action) {
@@ -79,6 +92,8 @@ export default function statuses(state = initialState, action) {
       return normalizeStatuses(state, action.statuses);
     case TIMELINE_DELETE:
       return deleteStatus(state, action.id, action.references);
+    case ACCOUNT_BLOCK_SUCCESS:
+      return filterStatuses(state, action.relationship);
     default:
       return state;
   }
diff --git a/app/assets/javascripts/components/reducers/timelines.jsx b/app/assets/javascripts/components/reducers/timelines.jsx
index 9e79a4100..358734eaf 100644
--- a/app/assets/javascripts/components/reducers/timelines.jsx
+++ b/app/assets/javascripts/components/reducers/timelines.jsx
@@ -13,7 +13,8 @@ import {
 import {
   ACCOUNT_FETCH_SUCCESS,
   ACCOUNT_TIMELINE_FETCH_SUCCESS,
-  ACCOUNT_TIMELINE_EXPAND_SUCCESS
+  ACCOUNT_TIMELINE_EXPAND_SUCCESS,
+  ACCOUNT_BLOCK_SUCCESS
 } from '../actions/accounts';
 import {
   STATUS_FETCH_SUCCESS,
@@ -140,6 +141,21 @@ const deleteStatus = (state, id, accountId, references) => {
   return state;
 };
 
+const filterTimelines = (state, relationship, statuses) => {
+  let references;
+
+  statuses.forEach(status => {
+    if (status.get('account') !== relationship.id) {
+      return;
+    }
+
+    references = statuses.filter(item => item.get('reblog') === status.get('id')).map(item => [item.get('id'), item.get('account')]);
+    state = deleteStatus(state, status.get('id'), status.get('account'), references);
+  });
+
+  return state;
+};
+
 const normalizeContext = (state, id, ancestors, descendants) => {
   const ancestorsIds   = ancestors.map(ancestor => ancestor.get('id'));
   const descendantsIds = descendants.map(descendant => descendant.get('id'));
@@ -166,6 +182,8 @@ export default function timelines(state = initialState, action) {
       return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace);
     case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
       return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
+    case ACCOUNT_BLOCK_SUCCESS:
+      return filterTimelines(state, action.relationship, action.statuses);
     default:
       return state;
   }