mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-27 10:30:15 -05:00
parent
6020a21130
commit
4b38ac3bed
@ -18,6 +18,7 @@ import {
|
|||||||
} from 'flavours/glitch/actions/accounts';
|
} from 'flavours/glitch/actions/accounts';
|
||||||
import { TIMELINE_DELETE, TIMELINE_DISCONNECT } from 'flavours/glitch/actions/timelines';
|
import { TIMELINE_DELETE, TIMELINE_DISCONNECT } from 'flavours/glitch/actions/timelines';
|
||||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||||
|
import compareId from 'flavours/glitch/util/compare_id';
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
items: ImmutableList(),
|
items: ImmutableList(),
|
||||||
@ -54,13 +55,6 @@ const normalizeNotification = (state, notification) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const newer = (m, n) => {
|
|
||||||
const mId = m.get('id');
|
|
||||||
const nId = n.get('id');
|
|
||||||
|
|
||||||
return mId.length === nId.length ? mId > nId : mId.length > nId.length;
|
|
||||||
};
|
|
||||||
|
|
||||||
const expandNormalizedNotifications = (state, notifications, next) => {
|
const expandNormalizedNotifications = (state, notifications, next) => {
|
||||||
let items = ImmutableList();
|
let items = ImmutableList();
|
||||||
|
|
||||||
@ -72,11 +66,11 @@ const expandNormalizedNotifications = (state, notifications, next) => {
|
|||||||
if (!items.isEmpty()) {
|
if (!items.isEmpty()) {
|
||||||
mutable.update('items', list => {
|
mutable.update('items', list => {
|
||||||
const lastIndex = 1 + list.findLastIndex(
|
const lastIndex = 1 + list.findLastIndex(
|
||||||
item => item !== null && (newer(item, items.last()) || item.get('id') === items.last().get('id'))
|
item => item !== null && (compareId(item.get('id'), items.last().get('id')) > 0 || item.get('id') === items.last().get('id'))
|
||||||
);
|
);
|
||||||
|
|
||||||
const firstIndex = 1 + list.take(lastIndex).findLastIndex(
|
const firstIndex = 1 + list.take(lastIndex).findLastIndex(
|
||||||
item => item !== null && newer(item, items.first())
|
item => item !== null && compareId(item.get('id'), items.first().get('id')) > 0
|
||||||
);
|
);
|
||||||
|
|
||||||
return list.take(firstIndex).concat(items, list.skip(lastIndex));
|
return list.take(firstIndex).concat(items, list.skip(lastIndex));
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
ACCOUNT_UNFOLLOW_SUCCESS,
|
ACCOUNT_UNFOLLOW_SUCCESS,
|
||||||
} from 'flavours/glitch/actions/accounts';
|
} from 'flavours/glitch/actions/accounts';
|
||||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||||
|
import compareId from 'flavours/glitch/util/compare_id';
|
||||||
|
|
||||||
const initialState = ImmutableMap();
|
const initialState = ImmutableMap();
|
||||||
|
|
||||||
@ -32,8 +33,8 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial) =>
|
|||||||
if (!statuses.isEmpty()) {
|
if (!statuses.isEmpty()) {
|
||||||
mMap.update('items', ImmutableList(), oldIds => {
|
mMap.update('items', ImmutableList(), oldIds => {
|
||||||
const newIds = statuses.map(status => status.get('id'));
|
const newIds = statuses.map(status => status.get('id'));
|
||||||
const lastIndex = oldIds.findLastIndex(id => id !== null && id >= newIds.last()) + 1;
|
const lastIndex = oldIds.findLastIndex(id => id !== null && compareId(id, newIds.last()) >= 0) + 1;
|
||||||
const firstIndex = oldIds.take(lastIndex).findLastIndex(id => id !== null && id > newIds.first());
|
const firstIndex = oldIds.take(lastIndex).findLastIndex(id => id !== null && compareId(id, newIds.first()) >= 0);
|
||||||
|
|
||||||
if (firstIndex < 0) {
|
if (firstIndex < 0) {
|
||||||
return (isPartial ? newIds.unshift(null) : newIds).concat(oldIds.skip(lastIndex));
|
return (isPartial ? newIds.unshift(null) : newIds).concat(oldIds.skip(lastIndex));
|
||||||
|
10
app/javascript/flavours/glitch/util/compare_id.js
Normal file
10
app/javascript/flavours/glitch/util/compare_id.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export default function compareId(id1, id2) {
|
||||||
|
if (id1 === id2) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (id1.length === id2.length) {
|
||||||
|
return id1 > id2 ? 1 : -1;
|
||||||
|
} else {
|
||||||
|
return id1.length > id2.length ? 1 : -1;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user