diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index 5b8f29688..3a2639892 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -2,7 +2,7 @@ import * as ACTIONS from 'constants/action_types'; import * as REACTION_TYPES from 'constants/reactions'; import { Lbry, selectClaimsByUri, selectMyChannelClaims } from 'lbry-redux'; -import { doToast } from 'redux/actions/notifications'; +import { doToast, doSeeNotifications } from 'redux/actions/notifications'; import { makeSelectCommentIdsForUri, makeSelectMyReactionsForComment, @@ -10,6 +10,7 @@ import { selectPendingCommentReacts, selectCommentChannel, } from 'redux/selectors/comments'; +import { makeSelectNotificationForCommentId } from 'redux/selectors/notifications'; export function doCommentList(uri: string, page: number = 1, pageSize: number = 99999) { return (dispatch: Dispatch, getState: GetState) => { @@ -104,6 +105,10 @@ export function doCommentReact(commentId: string, type: string) { const channel = selectCommentChannel(state); const pendingReacts = selectPendingCommentReacts(state); const myChannels = selectMyChannelClaims(state); + const notification = makeSelectNotificationForCommentId(commentId)(state); + if (notification && !notification.is_seen) { + dispatch(doSeeNotifications([notification.id])); + } const exclusiveTypes = { [REACTION_TYPES.LIKE]: REACTION_TYPES.DISLIKE, [REACTION_TYPES.DISLIKE]: REACTION_TYPES.LIKE, @@ -205,6 +210,13 @@ export function doCommentCreate( type: ACTIONS.COMMENT_CREATE_STARTED, }); + if (parent_id) { + const notification = makeSelectNotificationForCommentId(parent_id)(state); + if (notification && !notification.is_seen) { + dispatch(doSeeNotifications([notification.id])); + } + } + const myChannels = selectMyChannelClaims(state); const namedChannelClaim = myChannels && myChannels.find(myChannel => myChannel.name === channel); const channel_id = namedChannelClaim.claim_id; diff --git a/ui/redux/selectors/notifications.js b/ui/redux/selectors/notifications.js index 211d6800b..ea7f04fb2 100644 --- a/ui/redux/selectors/notifications.js +++ b/ui/redux/selectors/notifications.js @@ -4,6 +4,19 @@ export const selectState = state => state.notifications || {}; export const selectNotifications = createSelector(selectState, state => state.notifications); +export const makeSelectNotificationForCommentId = id => + createSelector(selectNotifications, notifications => { + const match = + notifications && + notifications.find( + n => + n.notification_parameters && + n.notification_parameters.dynamic && + n.notification_parameters.dynamic.hash === id + ); + return match; + }); + export const selectIsFetchingNotifications = createSelector(selectState, state => state.fetchingNotifications); export const selectUnreadNotificationCount = createSelector(selectNotifications, notifications => {