diff --git a/app/javascript/mastodon/reducers/timelines.js b/app/javascript/mastodon/reducers/timelines.js index d65b817a4..4dd1236a6 100644 --- a/app/javascript/mastodon/reducers/timelines.js +++ b/app/javascript/mastodon/reducers/timelines.js @@ -20,6 +20,8 @@ import { } from '../actions/accounts'; import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; import compareId from '../compare_id'; +import { uniqWithoutNull } from '../utils/uniq'; + const initialState = ImmutableMap(); @@ -52,13 +54,13 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is const firstIndex = oldIds.take(lastIndex).findLastIndex(id => id !== null && compareId(id, newIds.first()) > 0); if (firstIndex < 0) { - return (isPartial ? newIds.unshift(null) : newIds).concat(oldIds.skip(lastIndex)); + return uniqWithoutNull(isPartial ? newIds.unshift(null) : newIds).concat(oldIds.skip(lastIndex)); } - return oldIds.take(firstIndex + 1).concat( + return uniqWithoutNull(oldIds.take(firstIndex + 1).concat( isPartial && oldIds.get(firstIndex) !== null ? newIds.unshift(null) : newIds, oldIds.skip(lastIndex), - ); + )); }); } })); diff --git a/app/javascript/mastodon/utils/uniq.js b/app/javascript/mastodon/utils/uniq.js index 00f1804a1..e6d8fa872 100644 --- a/app/javascript/mastodon/utils/uniq.js +++ b/app/javascript/mastodon/utils/uniq.js @@ -1,3 +1,11 @@ export const uniq = array => { return array.filter((x, i, self) => self.indexOf(x) === i) }; + +export const uniqCompact = array => { + return array.filter((x, i, self) => x && self.indexOf(x) === i) +}; + +export const uniqWithoutNull = array => { + return array.filter((x, i, self) => !x || self.indexOf(x) === i) +};