From f1c0cf98061eee5eb6130b167d033c851ee58f14 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 15 Sep 2020 23:42:58 +0200 Subject: Add button to manually mark all notifications as read --- app/javascript/flavours/glitch/actions/notifications.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/javascript/flavours/glitch/actions') diff --git a/app/javascript/flavours/glitch/actions/notifications.js b/app/javascript/flavours/glitch/actions/notifications.js index ceb1e6df6..b44469cf4 100644 --- a/app/javascript/flavours/glitch/actions/notifications.js +++ b/app/javascript/flavours/glitch/actions/notifications.js @@ -45,6 +45,8 @@ export const NOTIFICATIONS_UNMOUNT = 'NOTIFICATIONS_UNMOUNT'; export const NOTIFICATIONS_SET_VISIBILITY = 'NOTIFICATIONS_SET_VISIBILITY'; +export const NOTIFICATIONS_MARK_AS_READ = 'NOTIFICATIONS_MARK_AS_READ'; + defineMessages({ mention: { id: 'notification.mention', defaultMessage: '{name} mentioned you' }, }); @@ -318,3 +320,9 @@ export function setFilter (filterType) { dispatch(saveSettings()); }; }; + +export function markNotificationsAsRead() { + return { + type: NOTIFICATIONS_MARK_AS_READ, + }; +}; -- cgit From 312c936d5191b682d68b317ed7b6883aeee2c14e Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sat, 19 Sep 2020 13:53:24 +0200 Subject: Minor refactoring and fixups --- app/javascript/flavours/glitch/actions/notifications.js | 1 + .../glitch/features/notifications/components/notification.js | 1 + app/javascript/flavours/glitch/reducers/notifications.js | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'app/javascript/flavours/glitch/actions') diff --git a/app/javascript/flavours/glitch/actions/notifications.js b/app/javascript/flavours/glitch/actions/notifications.js index b44469cf4..ccc427c29 100644 --- a/app/javascript/flavours/glitch/actions/notifications.js +++ b/app/javascript/flavours/glitch/actions/notifications.js @@ -18,6 +18,7 @@ import compareId from 'flavours/glitch/util/compare_id'; import { searchTextFromRawStatus } from 'flavours/glitch/actions/importer/normalizer'; export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE'; +export const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP'; // tracking the notif cleaning request export const NOTIFICATIONS_DELETE_MARKED_REQUEST = 'NOTIFICATIONS_DELETE_MARKED_REQUEST'; diff --git a/app/javascript/flavours/glitch/features/notifications/components/notification.js b/app/javascript/flavours/glitch/features/notifications/components/notification.js index 7b80c2228..bd415856c 100644 --- a/app/javascript/flavours/glitch/features/notifications/components/notification.js +++ b/app/javascript/flavours/glitch/features/notifications/components/notification.js @@ -22,6 +22,7 @@ export default class Notification extends ImmutablePureComponent { cacheMediaWidth: PropTypes.func, cachedMediaWidth: PropTypes.number, onUnmount: PropTypes.func, + unread: PropTypes.bool, }; render () { diff --git a/app/javascript/flavours/glitch/reducers/notifications.js b/app/javascript/flavours/glitch/reducers/notifications.js index 7820f524f..67725b902 100644 --- a/app/javascript/flavours/glitch/reducers/notifications.js +++ b/app/javascript/flavours/glitch/reducers/notifications.js @@ -138,16 +138,16 @@ const updateTop = (state, top) => { state = clearUnread(state); } - return state.set('top', top); + return state; }; const deleteByStatus = (state, statusId) => { - const top = !(shouldCountUnreadNotifications(state)); - if (!top) { + if (shouldCountUnreadNotifications(state)) { const lastReadId = state.get('lastReadId'); const deletedUnread = state.get('items').filter(item => item !== null && item.get('status') === statusId && compareId(item.get('id'), lastReadId) > 0); 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); -- cgit From 787d5d728923393f12421a480b3c7aee789a11fe Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sat, 19 Sep 2020 14:30:09 +0200 Subject: Fix minor bugs --- app/javascript/flavours/glitch/actions/markers.js | 14 +++++++------- app/javascript/flavours/glitch/reducers/notifications.js | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'app/javascript/flavours/glitch/actions') diff --git a/app/javascript/flavours/glitch/actions/markers.js b/app/javascript/flavours/glitch/actions/markers.js index 96e29accf..6b49ebf88 100644 --- a/app/javascript/flavours/glitch/actions/markers.js +++ b/app/javascript/flavours/glitch/actions/markers.js @@ -105,15 +105,15 @@ export function submitMarkers() { }; export const fetchMarkers = () => (dispatch, getState) => { - const params = { timeline: ['notifications'] }; + const params = { timeline: ['notifications'] }; - dispatch(fetchMarkersRequest()); + dispatch(fetchMarkersRequest()); - api(getState).get('/api/v1/markers', { params }).then(response => { - dispatch(fetchMarkersSuccess(response.data)); - }).catch(error => { - dispatch(fetchMarkersFail(error)); - }); + api(getState).get('/api/v1/markers', { params }).then(response => { + dispatch(fetchMarkersSuccess(response.data)); + }).catch(error => { + dispatch(fetchMarkersFail(error)); + }); }; export function fetchMarkersRequest() { diff --git a/app/javascript/flavours/glitch/reducers/notifications.js b/app/javascript/flavours/glitch/reducers/notifications.js index 67725b902..474ca3012 100644 --- a/app/javascript/flavours/glitch/reducers/notifications.js +++ b/app/javascript/flavours/glitch/reducers/notifications.js @@ -112,7 +112,7 @@ const expandNormalizedNotifications = (state, notifications, next, isLoadingRece } else { const mostRecent = items.find(item => item !== null); if (mostRecent && compareId(lastReadId, mostRecent.get('id')) < 0) { - mutable.set('lastReadId', mostRecentId); + mutable.set('lastReadId', mostRecent.get('id')); } } @@ -129,7 +129,7 @@ const clearUnread = (state) => { 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'); -} +}; const updateTop = (state, top) => { state = state.set('top', top); @@ -142,8 +142,9 @@ const updateTop = (state, top) => { }; const deleteByStatus = (state, statusId) => { + const lastReadId = state.get('lastReadId'); + if (shouldCountUnreadNotifications(state)) { - const lastReadId = state.get('lastReadId'); const deletedUnread = state.get('items').filter(item => item !== null && item.get('status') === statusId && compareId(item.get('id'), lastReadId) > 0); state = state.update('unread', unread => unread - deletedUnread.size); } @@ -224,7 +225,7 @@ const recountUnread = (state, last_read_id) => { mutable.set('unread', mutable.get('pendingItems').count(item => item !== null) + mutable.get('items').count(item => item && compareId(item.get('id'), last_read_id) > 0)); } }); -} +}; export default function notifications(state = initialState, action) { let st; -- cgit