diff --git a/ui/redux/actions/notifications.js b/ui/redux/actions/notifications.js index 8a7d96b37..564ab35e3 100644 --- a/ui/redux/actions/notifications.js +++ b/ui/redux/actions/notifications.js @@ -76,21 +76,27 @@ export function doNotificationList() { }; } -export function doReadNotifications() { +export function doReadNotifications(notificationsIds: Array) { return (dispatch: Dispatch, getState: GetState) => { const state = getState(); const notifications = selectNotifications(state); - const unreadNotifications = - notifications && - notifications - .filter((notification) => !notification.is_read) - .map((notification) => notification.id) - .join(','); + const unreadNotifications = notifications && notifications.filter((notification) => !notification.is_read); + + let ids; + if (notificationsIds && Array.isArray(notificationsIds) && notificationsIds.length !== 0) { + // Wipe specified notications. + ids = unreadNotifications + .filter((notification) => notificationsIds.includes(notification.id)) + .map((notification) => notification.id); + } else { + // A null or invalid argument will wipe all unread notifications. + ids = unreadNotifications.map((notification) => notification.id); + } dispatch({ type: ACTIONS.NOTIFICATION_READ_STARTED }); - return Lbryio.call('notification', 'edit', { notification_ids: unreadNotifications, is_read: true }) + return Lbryio.call('notification', 'edit', { notification_ids: ids.join(','), is_read: true }) .then(() => { - dispatch({ type: ACTIONS.NOTIFICATION_READ_COMPLETED }); + dispatch({ type: ACTIONS.NOTIFICATION_READ_COMPLETED, data: { notificationIds: ids } }); }) .catch((error) => { dispatch({ type: ACTIONS.NOTIFICATION_READ_FAILED, data: { error } }); diff --git a/ui/redux/reducers/notifications.js b/ui/redux/reducers/notifications.js index cf2208717..1807c2c73 100644 --- a/ui/redux/reducers/notifications.js +++ b/ui/redux/reducers/notifications.js @@ -55,8 +55,16 @@ export default handleActions( }, [ACTIONS.NOTIFICATION_READ_COMPLETED]: (state, action) => { const { notifications } = state; + const { notificationIds } = action.data; const newNotifications = - notifications && notifications.map((notification) => ({ ...notification, is_read: true })); + notifications && + notifications.map((notification) => { + if (notificationIds.includes(notification.id)) { + return { ...notification, is_read: true }; + } else { + return { ...notification }; + } + }); return { ...state, notifications: newNotifications,