From d99f91bceb01b8d7bd48a3872d894226512cc09f Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 25 Aug 2022 17:36:54 +0200 Subject: [PATCH] [Glitch] Fix quickly switching notification filters resulting in empty or incorrect list Port 55bef1e34fc3b07ed7f762d565a161e74e128016 to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/actions/notifications.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/notifications.js b/app/javascript/flavours/glitch/actions/notifications.js index ae3ee1a4c24..4581ebc36f3 100644 --- a/app/javascript/flavours/glitch/actions/notifications.js +++ b/app/javascript/flavours/glitch/actions/notifications.js @@ -153,15 +153,22 @@ const excludeTypesFromFilter = filter => { const noOp = () => {}; +let expandNotificationsController = new AbortController(); + export function expandNotifications({ maxId, forceLoad } = {}, done = noOp) { return (dispatch, getState) => { const activeFilter = getState().getIn(['settings', 'notifications', 'quickFilter', 'active']); const notifications = getState().get('notifications'); const isLoadingMore = !!maxId; - if (notifications.get('isLoading') && !forceLoad) { - done(); - return; + if (notifications.get('isLoading')) { + if (forceLoad) { + expandNotificationsController.abort(); + expandNotificationsController = new AbortController(); + } else { + done(); + return; + } } const params = { @@ -186,7 +193,7 @@ export function expandNotifications({ maxId, forceLoad } = {}, done = noOp) { dispatch(expandNotificationsRequest(isLoadingMore)); - api(getState).get('/api/v1/notifications', { params }).then(response => { + api(getState).get('/api/v1/notifications', { params, signal: expandNotificationsController.signal }).then(response => { const next = getLinks(response).refs.find(link => link.rel === 'next'); dispatch(importFetchedAccounts(response.data.map(item => item.account))); @@ -227,7 +234,7 @@ export function expandNotificationsFail(error, isLoadingMore) { type: NOTIFICATIONS_EXPAND_FAIL, error, skipLoading: !isLoadingMore, - skipAlert: !isLoadingMore, + skipAlert: !isLoadingMore || error.name === 'AbortError', }; };