From 75673cf8e35ae985a7f8608b8764a77256d57712 Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 16 Sep 2019 15:45:06 +0200 Subject: [Glitch] Fix “slow mode” issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port f1098675782944fe1dabec71cd58d3d091da06a0 to glitch-soc Signed-off-by: Thibaut Girka --- app/javascript/flavours/glitch/reducers/notifications.js | 6 ++++-- app/javascript/flavours/glitch/reducers/timelines.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'app/javascript/flavours/glitch/reducers') diff --git a/app/javascript/flavours/glitch/reducers/notifications.js b/app/javascript/flavours/glitch/reducers/notifications.js index 135995da6..2413f26fb 100644 --- a/app/javascript/flavours/glitch/reducers/notifications.js +++ b/app/javascript/flavours/glitch/reducers/notifications.js @@ -51,7 +51,7 @@ const notificationToMap = (state, notification) => ImmutableMap({ const normalizeNotification = (state, notification, usePendingItems) => { if (usePendingItems) { - return state.update('pendingItems', list => list.unshift(notificationToMap(state, notification))); + return state.update('pendingItems', list => list.unshift(notificationToMap(state, notification))).update('unread', unread => unread + 1); } const top = !shouldCountUnreadNotifications(state); @@ -117,7 +117,7 @@ const filterNotifications = (state, accountIds) => { }; const clearUnread = (state) => { - state = state.set('unread', 0); + state = state.set('unread', state.get('pendingItems').size); const lastNotification = state.get('items').find(item => item !== null); return state.set('lastReadId', lastNotification ? lastNotification.get('id') : '0'); } @@ -140,6 +140,8 @@ const deleteByStatus = (state, statusId) => { state = state.update('unread', unread => unread - deletedUnread.size); } const helper = list => list.filterNot(item => item !== null && item.get('status') === statusId); + const deletedUnread = state.get('pendingItems').filter(item => item !== null && item.get('status') === statusId && compareId(item.get('id'), lastReadId) > 0); + state = state.update('unread', unread => unread - deletedUnread.size); return state.update('items', helper).update('pendingItems', helper); }; diff --git a/app/javascript/flavours/glitch/reducers/timelines.js b/app/javascript/flavours/glitch/reducers/timelines.js index 9b016a4c6..7fb0a7fc1 100644 --- a/app/javascript/flavours/glitch/reducers/timelines.js +++ b/app/javascript/flavours/glitch/reducers/timelines.js @@ -64,7 +64,7 @@ const updateTimeline = (state, timeline, status, usePendingItems) => { return state; } - return state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(status.get('id')))); + 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']); @@ -127,7 +127,7 @@ const filterTimeline = (timeline, state, relationship, statuses) => { const updateTop = (state, timeline, top) => { return state.update(timeline, initialTimeline, map => map.withMutations(mMap => { - if (top) mMap.set('unread', 0); + if (top) mMap.set('unread', mMap.get('pendingItems').size); mMap.set('top', top); })); }; -- cgit