about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-07-10 20:02:28 +0200
committerGitHub <noreply@github.com>2020-07-10 20:02:28 +0200
commit7a23347db5be3f262dbcafbecf768588dc648bda (patch)
treeea39baa62e9893e51432d5d8ec2438a803371262 /app
parentddf7cc1ab56b888fdf61ee8cb1456c71cd9c33c9 (diff)
parent3fbcc4871f822712885f3f16b0c8b9b7e1e7780f (diff)
Merge pull request #1381 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app')
-rw-r--r--app/javascript/flavours/glitch/reducers/user_lists.js32
-rw-r--r--app/javascript/mastodon/reducers/user_lists.js32
2 files changed, 32 insertions, 32 deletions
diff --git a/app/javascript/flavours/glitch/reducers/user_lists.js b/app/javascript/flavours/glitch/reducers/user_lists.js
index 3c56031dd..202f9198f 100644
--- a/app/javascript/flavours/glitch/reducers/user_lists.js
+++ b/app/javascript/flavours/glitch/reducers/user_lists.js
@@ -63,16 +63,16 @@ const initialState = ImmutableMap({
   mutes: ImmutableMap(),
 });
 
-const normalizeList = (state, type, id, accounts, next) => {
-  return state.setIn([type, id], ImmutableMap({
+const normalizeList = (state, path, accounts, next) => {
+  return state.setIn(path, ImmutableMap({
     next,
     items: ImmutableList(accounts.map(item => item.id)),
     isLoading: false,
   }));
 };
 
-const appendToList = (state, type, id, accounts, next) => {
-  return state.updateIn([type, id], map => {
+const appendToList = (state, path, accounts, next) => {
+  return state.updateIn(path, map => {
     return map.set('next', next).set('isLoading', false).update('items', list => list.concat(accounts.map(item => item.id)));
   });
 };
@@ -86,9 +86,9 @@ const normalizeFollowRequest = (state, notification) => {
 export default function userLists(state = initialState, action) {
   switch(action.type) {
   case FOLLOWERS_FETCH_SUCCESS:
-    return normalizeList(state, 'followers', action.id, action.accounts, action.next);
+    return normalizeList(state, ['followers', action.id], action.accounts, action.next);
   case FOLLOWERS_EXPAND_SUCCESS:
-    return appendToList(state, 'followers', action.id, action.accounts, action.next);
+    return appendToList(state, ['followers', action.id], action.accounts, action.next);
   case FOLLOWERS_FETCH_REQUEST:
   case FOLLOWERS_EXPAND_REQUEST:
     return state.setIn(['followers', action.id, 'isLoading'], true);
@@ -96,9 +96,9 @@ export default function userLists(state = initialState, action) {
   case FOLLOWERS_EXPAND_FAIL:
     return state.setIn(['followers', action.id, 'isLoading'], false);
   case FOLLOWING_FETCH_SUCCESS:
-    return normalizeList(state, 'following', action.id, action.accounts, action.next);
+    return normalizeList(state, ['following', action.id], action.accounts, action.next);
   case FOLLOWING_EXPAND_SUCCESS:
-    return appendToList(state, 'following', action.id, action.accounts, action.next);
+    return appendToList(state, ['following', action.id], action.accounts, action.next);
   case FOLLOWING_FETCH_REQUEST:
   case FOLLOWING_EXPAND_REQUEST:
     return state.setIn(['following', action.id, 'isLoading'], true);
@@ -112,9 +112,9 @@ export default function userLists(state = initialState, action) {
   case NOTIFICATIONS_UPDATE:
     return action.notification.type === 'follow_request' ? normalizeFollowRequest(state, action.notification) : state;
   case FOLLOW_REQUESTS_FETCH_SUCCESS:
-    return state.setIn(['follow_requests', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['follow_requests', 'next'], action.next).setIn(['follow_requests', 'isLoading'], false);
+    return normalizeList(state, ['follow_requests'], action.accounts, action.next);
   case FOLLOW_REQUESTS_EXPAND_SUCCESS:
-    return state.updateIn(['follow_requests', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['follow_requests', 'next'], action.next).setIn(['follow_requests', 'isLoading'], false);
+    return appendToList(state, ['follow_requests'], action.accounts, action.next);
   case FOLLOW_REQUESTS_FETCH_REQUEST:
   case FOLLOW_REQUESTS_EXPAND_REQUEST:
     return state.setIn(['follow_requests', 'isLoading'], true);
@@ -125,9 +125,9 @@ export default function userLists(state = initialState, action) {
   case FOLLOW_REQUEST_REJECT_SUCCESS:
     return state.updateIn(['follow_requests', 'items'], list => list.filterNot(item => item === action.id));
   case BLOCKS_FETCH_SUCCESS:
-    return state.setIn(['blocks', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['blocks', 'next'], action.next);
+    return normalizeList(state, ['blocks'], action.accounts, action.next);
   case BLOCKS_EXPAND_SUCCESS:
-    return state.updateIn(['blocks', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['blocks', 'next'], action.next);
+    return appendToList(state, ['blocks'], action.accounts, action.next);
   case BLOCKS_FETCH_REQUEST:
   case BLOCKS_EXPAND_REQUEST:
     return state.setIn(['blocks', 'isLoading'], true);
@@ -135,9 +135,9 @@ export default function userLists(state = initialState, action) {
   case BLOCKS_EXPAND_FAIL:
     return state.setIn(['blocks', 'isLoading'], false);
   case MUTES_FETCH_SUCCESS:
-    return state.setIn(['mutes', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
+    return normalizeList(state, ['mutes'], action.accounts, action.next);
   case MUTES_EXPAND_SUCCESS:
-    return state.updateIn(['mutes', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
+    return appendToList(state, ['mutes'], action.accounts, action.next);
   case MUTES_FETCH_REQUEST:
   case MUTES_EXPAND_REQUEST:
     return state.setIn(['mutes', 'isLoading'], true);
@@ -145,9 +145,9 @@ export default function userLists(state = initialState, action) {
   case MUTES_EXPAND_FAIL:
     return state.setIn(['mutes', 'isLoading'], false);
   case DIRECTORY_FETCH_SUCCESS:
-    return state.setIn(['directory', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['directory', 'isLoading'], false);
+    return normalizeList(state, ['directory'], action.accounts, action.next);
   case DIRECTORY_EXPAND_SUCCESS:
-    return state.updateIn(['directory', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['directory', 'isLoading'], false);
+    return appendToList(state, ['directory'], action.accounts, action.next);
   case DIRECTORY_FETCH_REQUEST:
   case DIRECTORY_EXPAND_REQUEST:
     return state.setIn(['directory', 'isLoading'], true);
diff --git a/app/javascript/mastodon/reducers/user_lists.js b/app/javascript/mastodon/reducers/user_lists.js
index e7eef2364..8165952a7 100644
--- a/app/javascript/mastodon/reducers/user_lists.js
+++ b/app/javascript/mastodon/reducers/user_lists.js
@@ -63,16 +63,16 @@ const initialState = ImmutableMap({
   mutes: ImmutableMap(),
 });
 
-const normalizeList = (state, type, id, accounts, next) => {
-  return state.setIn([type, id], ImmutableMap({
+const normalizeList = (state, path, accounts, next) => {
+  return state.setIn(path, ImmutableMap({
     next,
     items: ImmutableList(accounts.map(item => item.id)),
     isLoading: false,
   }));
 };
 
-const appendToList = (state, type, id, accounts, next) => {
-  return state.updateIn([type, id], map => {
+const appendToList = (state, path, accounts, next) => {
+  return state.updateIn(path, map => {
     return map.set('next', next).set('isLoading', false).update('items', list => list.concat(accounts.map(item => item.id)));
   });
 };
@@ -86,9 +86,9 @@ const normalizeFollowRequest = (state, notification) => {
 export default function userLists(state = initialState, action) {
   switch(action.type) {
   case FOLLOWERS_FETCH_SUCCESS:
-    return normalizeList(state, 'followers', action.id, action.accounts, action.next);
+    return normalizeList(state, ['followers', action.id], action.accounts, action.next);
   case FOLLOWERS_EXPAND_SUCCESS:
-    return appendToList(state, 'followers', action.id, action.accounts, action.next);
+    return appendToList(state, ['followers', action.id], action.accounts, action.next);
   case FOLLOWERS_FETCH_REQUEST:
   case FOLLOWERS_EXPAND_REQUEST:
     return state.setIn(['followers', action.id, 'isLoading'], true);
@@ -96,9 +96,9 @@ export default function userLists(state = initialState, action) {
   case FOLLOWERS_EXPAND_FAIL:
     return state.setIn(['followers', action.id, 'isLoading'], false);
   case FOLLOWING_FETCH_SUCCESS:
-    return normalizeList(state, 'following', action.id, action.accounts, action.next);
+    return normalizeList(state, ['following', action.id], action.accounts, action.next);
   case FOLLOWING_EXPAND_SUCCESS:
-    return appendToList(state, 'following', action.id, action.accounts, action.next);
+    return appendToList(state, ['following', action.id], action.accounts, action.next);
   case FOLLOWING_FETCH_REQUEST:
   case FOLLOWING_EXPAND_REQUEST:
     return state.setIn(['following', action.id, 'isLoading'], true);
@@ -112,9 +112,9 @@ export default function userLists(state = initialState, action) {
   case NOTIFICATIONS_UPDATE:
     return action.notification.type === 'follow_request' ? normalizeFollowRequest(state, action.notification) : state;
   case FOLLOW_REQUESTS_FETCH_SUCCESS:
-    return state.setIn(['follow_requests', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['follow_requests', 'next'], action.next).setIn(['follow_requests', 'isLoading'], false);
+    return normalizeList(state, ['follow_requests'], action.accounts, action.next);
   case FOLLOW_REQUESTS_EXPAND_SUCCESS:
-    return state.updateIn(['follow_requests', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['follow_requests', 'next'], action.next).setIn(['follow_requests', 'isLoading'], false);
+    return appendToList(state, ['follow_requests'], action.accounts, action.next);
   case FOLLOW_REQUESTS_FETCH_REQUEST:
   case FOLLOW_REQUESTS_EXPAND_REQUEST:
     return state.setIn(['follow_requests', 'isLoading'], true);
@@ -125,9 +125,9 @@ export default function userLists(state = initialState, action) {
   case FOLLOW_REQUEST_REJECT_SUCCESS:
     return state.updateIn(['follow_requests', 'items'], list => list.filterNot(item => item === action.id));
   case BLOCKS_FETCH_SUCCESS:
-    return state.setIn(['blocks', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['blocks', 'next'], action.next);
+    return normalizeList(state, ['blocks'], action.accounts, action.next);
   case BLOCKS_EXPAND_SUCCESS:
-    return state.updateIn(['blocks', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['blocks', 'next'], action.next);
+    return appendToList(state, ['blocks'], action.accounts, action.next);
   case BLOCKS_FETCH_REQUEST:
   case BLOCKS_EXPAND_REQUEST:
     return state.setIn(['blocks', 'isLoading'], true);
@@ -135,9 +135,9 @@ export default function userLists(state = initialState, action) {
   case BLOCKS_EXPAND_FAIL:
     return state.setIn(['blocks', 'isLoading'], false);
   case MUTES_FETCH_SUCCESS:
-    return state.setIn(['mutes', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
+    return normalizeList(state, ['mutes'], action.accounts, action.next);
   case MUTES_EXPAND_SUCCESS:
-    return state.updateIn(['mutes', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
+    return appendToList(state, ['mutes'], action.accounts, action.next);
   case MUTES_FETCH_REQUEST:
   case MUTES_EXPAND_REQUEST:
     return state.setIn(['mutes', 'isLoading'], true);
@@ -145,9 +145,9 @@ export default function userLists(state = initialState, action) {
   case MUTES_EXPAND_FAIL:
     return state.setIn(['mutes', 'isLoading'], false);
   case DIRECTORY_FETCH_SUCCESS:
-    return state.setIn(['directory', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['directory', 'isLoading'], false);
+    return normalizeList(state, ['directory'], action.accounts, action.next);
   case DIRECTORY_EXPAND_SUCCESS:
-    return state.updateIn(['directory', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['directory', 'isLoading'], false);
+    return appendToList(state, ['directory'], action.accounts, action.next);
   case DIRECTORY_FETCH_REQUEST:
   case DIRECTORY_EXPAND_REQUEST:
     return state.setIn(['directory', 'isLoading'], true);