forked from treehouse/mastodon
[Glitch] Fix “load more” adding older toots/notifications to pending items
Port 577706987d
to glitch-soc
Signed-off-by: Thibaut Girka <thib@sitedethib.com>
signup-info-prompt
parent
844e0fb48c
commit
b840de580f
|
@ -165,7 +165,7 @@ export function expandNotifications({ maxId } = {}, done = noOp) {
|
||||||
dispatch(importFetchedAccounts(response.data.map(item => item.account)));
|
dispatch(importFetchedAccounts(response.data.map(item => item.account)));
|
||||||
dispatch(importFetchedStatuses(response.data.map(item => item.status).filter(status => !!status)));
|
dispatch(importFetchedStatuses(response.data.map(item => item.status).filter(status => !!status)));
|
||||||
|
|
||||||
dispatch(expandNotificationsSuccess(response.data, next ? next.uri : null, isLoadingMore, isLoadingRecent && preferPendingItems));
|
dispatch(expandNotificationsSuccess(response.data, next ? next.uri : null, isLoadingMore, isLoadingRecent, isLoadingRecent && preferPendingItems));
|
||||||
fetchRelatedRelationships(dispatch, response.data);
|
fetchRelatedRelationships(dispatch, response.data);
|
||||||
done();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
@ -182,11 +182,12 @@ export function expandNotificationsRequest(isLoadingMore) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function expandNotificationsSuccess(notifications, next, isLoadingMore, usePendingItems) {
|
export function expandNotificationsSuccess(notifications, next, isLoadingMore, isLoadingRecent, usePendingItems) {
|
||||||
return {
|
return {
|
||||||
type: NOTIFICATIONS_EXPAND_SUCCESS,
|
type: NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
notifications,
|
notifications,
|
||||||
next,
|
next,
|
||||||
|
isLoadingRecent: isLoadingRecent,
|
||||||
usePendingItems,
|
usePendingItems,
|
||||||
skipLoading: !isLoadingMore,
|
skipLoading: !isLoadingMore,
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,7 +71,7 @@ const normalizeNotification = (state, notification, usePendingItems) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const expandNormalizedNotifications = (state, notifications, next, usePendingItems) => {
|
const expandNormalizedNotifications = (state, notifications, next, isLoadingRecent, usePendingItems) => {
|
||||||
const top = !(shouldCountUnreadNotifications(state));
|
const top = !(shouldCountUnreadNotifications(state));
|
||||||
const lastReadId = state.get('lastReadId');
|
const lastReadId = state.get('lastReadId');
|
||||||
let items = ImmutableList();
|
let items = ImmutableList();
|
||||||
|
@ -82,7 +82,7 @@ const expandNormalizedNotifications = (state, notifications, next, usePendingIte
|
||||||
|
|
||||||
return state.withMutations(mutable => {
|
return state.withMutations(mutable => {
|
||||||
if (!items.isEmpty()) {
|
if (!items.isEmpty()) {
|
||||||
usePendingItems = usePendingItems || !mutable.get('top') || !mutable.get('pendingItems').isEmpty();
|
usePendingItems = isLoadingRecent && (usePendingItems || !mutable.get('top') || !mutable.get('pendingItems').isEmpty());
|
||||||
|
|
||||||
mutable.update(usePendingItems ? 'pendingItems' : 'items', list => {
|
mutable.update(usePendingItems ? 'pendingItems' : 'items', list => {
|
||||||
const lastIndex = 1 + list.findLastIndex(
|
const lastIndex = 1 + list.findLastIndex(
|
||||||
|
@ -220,7 +220,7 @@ export default function notifications(state = initialState, action) {
|
||||||
case NOTIFICATIONS_UPDATE:
|
case NOTIFICATIONS_UPDATE:
|
||||||
return normalizeNotification(state, action.notification, action.usePendingItems);
|
return normalizeNotification(state, action.notification, action.usePendingItems);
|
||||||
case NOTIFICATIONS_EXPAND_SUCCESS:
|
case NOTIFICATIONS_EXPAND_SUCCESS:
|
||||||
return expandNormalizedNotifications(state, action.notifications, action.next, action.usePendingItems);
|
return expandNormalizedNotifications(state, action.notifications, action.next, action.isLoadingRecent, action.usePendingItems);
|
||||||
case ACCOUNT_BLOCK_SUCCESS:
|
case ACCOUNT_BLOCK_SUCCESS:
|
||||||
return filterNotifications(state, [action.relationship.id]);
|
return filterNotifications(state, [action.relationship.id]);
|
||||||
case ACCOUNT_MUTE_SUCCESS:
|
case ACCOUNT_MUTE_SUCCESS:
|
||||||
|
|
|
@ -40,7 +40,7 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
|
||||||
if (timeline.endsWith(':pinned')) {
|
if (timeline.endsWith(':pinned')) {
|
||||||
mMap.set('items', statuses.map(status => status.get('id')));
|
mMap.set('items', statuses.map(status => status.get('id')));
|
||||||
} else if (!statuses.isEmpty()) {
|
} else if (!statuses.isEmpty()) {
|
||||||
usePendingItems = usePendingItems || !mMap.get('top') || !mMap.get('pendingItems').isEmpty();
|
usePendingItems = isLoadingRecent && (usePendingItems || !mMap.get('top') || !mMap.get('pendingItems').isEmpty());
|
||||||
mMap.update(usePendingItems ? 'pendingItems' : 'items', ImmutableList(), oldIds => {
|
mMap.update(usePendingItems ? 'pendingItems' : '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 && compareId(id, newIds.last()) >= 0) + 1;
|
const lastIndex = oldIds.findLastIndex(id => id !== null && compareId(id, newIds.last()) >= 0) + 1;
|
||||||
|
|
Loading…
Reference in New Issue