Skip to content

Commit

Permalink
Fix not being able to load more notifications after trimming (mastodo…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Sep 2, 2024
1 parent 70faafb commit 4a2e66d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/javascript/mastodon/reducers/notification_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ function processNewNotification(
}

function trimNotifications(state: NotificationGroupsState) {
if (state.scrolledToTop) {
if (state.scrolledToTop && state.groups.length > NOTIFICATIONS_TRIM_LIMIT) {
state.groups.splice(NOTIFICATIONS_TRIM_LIMIT);
ensureTrailingGap(state.groups);
}
}

Expand Down Expand Up @@ -400,6 +401,28 @@ function ensureLeadingGap(
}
}

// Ensure the groups list ends with a gap suitable for loading more, mutating it to append one if needed
function ensureTrailingGap(
groups: NotificationGroupsState['groups'],
): NotificationGap {
const groupOrGap = groups.at(-1);

if (groupOrGap?.type === 'gap') {
// We're expecting older notifications, so discard sinceId if it's set
groupOrGap.sinceId = undefined;

return groupOrGap;
} else {
const gap: NotificationGap = {
type: 'gap',
maxId: groupOrGap?.page_min_id,
};

groups.push(gap);
return gap;
}
}

export const notificationGroupsReducer = createReducer<NotificationGroupsState>(
initialState,
(builder) => {
Expand Down

0 comments on commit 4a2e66d

Please sign in to comment.