Change timelines to add new items to pending items when scrolled down (#11867)

remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
ThibG 2019-09-16 19:39:44 +02:00 committed by Eugen Rochko
parent 576377a382
commit d256901f60
2 changed files with 9 additions and 5 deletions

View File

@ -35,12 +35,12 @@ const notificationToMap = notification => ImmutableMap({
});
const normalizeNotification = (state, notification, usePendingItems) => {
if (usePendingItems) {
const top = state.get('top');
if (usePendingItems || !top || !state.get('pendingItems').isEmpty()) {
return state.update('pendingItems', list => list.unshift(notificationToMap(notification))).update('unread', unread => unread + 1);
}
const top = state.get('top');
if (!top) {
state = state.update('unread', unread => unread + 1);
}
@ -63,6 +63,8 @@ const expandNormalizedNotifications = (state, notifications, next, usePendingIte
return state.withMutations(mutable => {
if (!items.isEmpty()) {
usePendingItems = usePendingItems || !mutable.get('top') || !mutable.get('pendingItems').isEmpty();
mutable.update(usePendingItems ? 'pendingItems' : 'items', list => {
const lastIndex = 1 + list.findLastIndex(
item => item !== null && (compareId(item.get('id'), items.last().get('id')) > 0 || item.get('id') === items.last().get('id'))

View File

@ -40,6 +40,7 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
if (timeline.endsWith(':pinned')) {
mMap.set('items', statuses.map(status => status.get('id')));
} else if (!statuses.isEmpty()) {
usePendingItems = usePendingItems || !mMap.get('top') || !mMap.get('pendingItems').isEmpty();
mMap.update(usePendingItems ? 'pendingItems' : 'items', ImmutableList(), oldIds => {
const newIds = statuses.map(status => status.get('id'));
@ -60,7 +61,9 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
};
const updateTimeline = (state, timeline, status, usePendingItems) => {
if (usePendingItems) {
const top = state.getIn([timeline, 'top']);
if (usePendingItems || !top || !state.getIn([timeline, 'pendingItems']).isEmpty()) {
if (state.getIn([timeline, 'pendingItems'], ImmutableList()).includes(status.get('id')) || state.getIn([timeline, 'items'], ImmutableList()).includes(status.get('id'))) {
return state;
}
@ -68,7 +71,6 @@ const updateTimeline = (state, timeline, status, usePendingItems) => {
return state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(status.get('id'))).update('unread', unread => unread + 1));
}
const top = state.getIn([timeline, 'top']);
const ids = state.getIn([timeline, 'items'], ImmutableList());
const includesId = ids.includes(status.get('id'));
const unread = state.getIn([timeline, 'unread'], 0);