mark notification seen on relevant interaction

This commit is contained in:
jessop 2020-10-20 09:29:49 -04:00 committed by Sean Yesmunt
parent 41dfd8a0f8
commit 91d034954e
2 changed files with 26 additions and 1 deletions

View file

@ -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;

View file

@ -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 => {