diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-12-07 14:12:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-07 14:12:55 +0100 |
commit | c8a1faa86b2eb2e0350b384fe66431bec663fdae (patch) | |
tree | 449ea33a2043fe936228ffa5d644db93282a8d70 /app/javascript | |
parent | b59fb28e90bc21d6fd1a6bafd13cfbd81ab5be54 (diff) |
Fix potential duplicate statuses in Explore tab (#22121)
Diffstat (limited to 'app/javascript')
-rw-r--r-- | app/javascript/mastodon/reducers/status_lists.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/app/javascript/mastodon/reducers/status_lists.js b/app/javascript/mastodon/reducers/status_lists.js index a7c56cc19..106f64d32 100644 --- a/app/javascript/mastodon/reducers/status_lists.js +++ b/app/javascript/mastodon/reducers/status_lists.js @@ -25,7 +25,7 @@ import { TRENDS_STATUSES_EXPAND_SUCCESS, TRENDS_STATUSES_EXPAND_FAIL, } from '../actions/trends'; -import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; +import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable'; import { FAVOURITE_SUCCESS, UNFAVOURITE_SUCCESS, @@ -43,22 +43,22 @@ const initialState = ImmutableMap({ favourites: ImmutableMap({ next: null, loaded: false, - items: ImmutableList(), + items: ImmutableOrderedSet(), }), bookmarks: ImmutableMap({ next: null, loaded: false, - items: ImmutableList(), + items: ImmutableOrderedSet(), }), pins: ImmutableMap({ next: null, loaded: false, - items: ImmutableList(), + items: ImmutableOrderedSet(), }), trending: ImmutableMap({ next: null, loaded: false, - items: ImmutableList(), + items: ImmutableOrderedSet(), }), }); @@ -67,7 +67,7 @@ const normalizeList = (state, listType, statuses, next) => { map.set('next', next); map.set('loaded', true); map.set('isLoading', false); - map.set('items', ImmutableList(statuses.map(item => item.id))); + map.set('items', ImmutableOrderedSet(statuses.map(item => item.id))); })); }; @@ -75,20 +75,22 @@ const appendToList = (state, listType, statuses, next) => { return state.update(listType, listMap => listMap.withMutations(map => { map.set('next', next); map.set('isLoading', false); - map.set('items', map.get('items').concat(statuses.map(item => item.id))); + map.set('items', map.get('items').union(statuses.map(item => item.id))); })); }; const prependOneToList = (state, listType, status) => { - return state.update(listType, listMap => listMap.withMutations(map => { - map.set('items', map.get('items').unshift(status.get('id'))); - })); + return state.updateIn([listType, 'items'], (list) => { + if (list.includes(status.get('id'))) { + return list; + } else { + return ImmutableOrderedSet([status.get('id')]).union(list); + } + }); }; const removeOneFromList = (state, listType, status) => { - return state.update(listType, listMap => listMap.withMutations(map => { - map.set('items', map.get('items').filter(item => item !== status.get('id'))); - })); + return state.updateIn([listType, 'items'], (list) => list.delete(status.get('id'))); }; export default function statusLists(state = initialState, action) { @@ -139,7 +141,7 @@ export default function statusLists(state = initialState, action) { return removeOneFromList(state, 'pins', action.status); case ACCOUNT_BLOCK_SUCCESS: case ACCOUNT_MUTE_SUCCESS: - return state.updateIn(['trending', 'items'], ImmutableList(), list => list.filterNot(statusId => action.statuses.getIn([statusId, 'account']) === action.relationship.id)); + return state.updateIn(['trending', 'items'], ImmutableOrderedSet(), list => list.filterNot(statusId => action.statuses.getIn([statusId, 'account']) === action.relationship.id)); default: return state; } |