[Glitch] Fix comparing id

Port 0ba49eca8b to glitch-soc
This commit is contained in:
Thibaut Girka
2018-05-27 19:33:28 +02:00
committed by ThibG
parent 6020a21130
commit 4b38ac3bed
3 changed files with 16 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ import {
ACCOUNT_UNFOLLOW_SUCCESS,
} from 'flavours/glitch/actions/accounts';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
import compareId from 'flavours/glitch/util/compare_id';
const initialState = ImmutableMap();
@@ -32,8 +33,8 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial) =>
if (!statuses.isEmpty()) {
mMap.update('items', ImmutableList(), oldIds => {
const newIds = statuses.map(status => status.get('id'));
const lastIndex = oldIds.findLastIndex(id => id !== null && id >= newIds.last()) + 1;
const firstIndex = oldIds.take(lastIndex).findLastIndex(id => id !== null && id > newIds.first());
const lastIndex = oldIds.findLastIndex(id => id !== null && compareId(id, newIds.last()) >= 0) + 1;
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));