Skip to content

Commit 9a5d28b

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Change timelines to add new items to pending items when scrolled down (mastodon#11867)
1 parent dbf2a1a commit 9a5d28b

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

app/javascript/mastodon/reducers/notifications.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ const notificationToMap = notification => ImmutableMap({
3535
});
3636

3737
const normalizeNotification = (state, notification, usePendingItems) => {
38-
if (usePendingItems) {
38+
const top = state.get('top');
39+
40+
if (usePendingItems || !top || !state.get('pendingItems').isEmpty()) {
3941
return state.update('pendingItems', list => list.unshift(notificationToMap(notification))).update('unread', unread => unread + 1);
4042
}
4143

42-
const top = state.get('top');
43-
4444
if (!top) {
4545
state = state.update('unread', unread => unread + 1);
4646
}
@@ -63,6 +63,8 @@ const expandNormalizedNotifications = (state, notifications, next, usePendingIte
6363

6464
return state.withMutations(mutable => {
6565
if (!items.isEmpty()) {
66+
usePendingItems = usePendingItems || !mutable.get('top') || !mutable.get('pendingItems').isEmpty();
67+
6668
mutable.update(usePendingItems ? 'pendingItems' : 'items', list => {
6769
const lastIndex = 1 + list.findLastIndex(
6870
item => item !== null && (compareId(item.get('id'), items.last().get('id')) > 0 || item.get('id') === items.last().get('id'))

app/javascript/mastodon/reducers/timelines.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
4040
if (timeline.endsWith(':pinned')) {
4141
mMap.set('items', statuses.map(status => status.get('id')));
4242
} else if (!statuses.isEmpty()) {
43+
usePendingItems = usePendingItems || !mMap.get('top') || !mMap.get('pendingItems').isEmpty();
4344
mMap.update(usePendingItems ? 'pendingItems' : 'items', ImmutableList(), oldIds => {
4445
const newIds = statuses.map(status => status.get('id'));
4546

@@ -60,15 +61,16 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
6061
};
6162

6263
const updateTimeline = (state, timeline, status, usePendingItems) => {
63-
if (usePendingItems) {
64+
const top = state.getIn([timeline, 'top']);
65+
66+
if (usePendingItems || !top || !state.getIn([timeline, 'pendingItems']).isEmpty()) {
6467
if (state.getIn([timeline, 'pendingItems'], ImmutableList()).includes(status.get('id')) || state.getIn([timeline, 'items'], ImmutableList()).includes(status.get('id'))) {
6568
return state;
6669
}
6770

6871
return state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(status.get('id'))).update('unread', unread => unread + 1));
6972
}
7073

71-
const top = state.getIn([timeline, 'top']);
7274
const ids = state.getIn([timeline, 'items'], ImmutableList());
7375
const includesId = ids.includes(status.get('id'));
7476
const unread = state.getIn([timeline, 'unread'], 0);

0 commit comments

Comments
 (0)