diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index 4d427f02f7..2bf7f08d7a 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -710,6 +710,9 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen const myCommentedChannelIds = selectMyCommentedChannelIdsForId(state, claim_id); const mentionedChannels: Array = []; + const claim = selectClaimForClaimId(state, claim_id); + const targetClaimId = claim.signing_channel ? claim.signing_channel.claim_id : claim_id; // claim_id is for anonymous content and on channel page comments + if (!activeChannelClaim) { console.error('Unable to create comment. No activeChannel is set.'); // eslint-disable-line return; @@ -725,6 +728,23 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen return; } + let previousCommenterChannel = localStorage.getItem(`commenter_${targetClaimId}`); + previousCommenterChannel = previousCommenterChannel ? JSON.parse(previousCommenterChannel) : null; + if ( + previousCommenterChannel && + previousCommenterChannel.claim_id !== activeChannelClaim.claim_id && + myCommentedChannelIds && + !myCommentedChannelIds.includes(activeChannelClaim.claim_id) + ) { + dispatchToast( + dispatch, + __('Commenting from multiple channels is not allowed.'), + previousCommenterChannel.name, + 'long' + ); + return; + } + if (myCommentedChannelIds && myCommentedChannelIds.length) { if (!myCommentedChannelIds.includes(activeChannelClaim.claim_id)) { const claimById = selectClaimsById(state); @@ -805,6 +825,25 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen ...(payment_intent_id ? { payment_intent_id } : {}), }) .then((result: CommentCreateResponse) => { + if (!previousCommenterChannel) { + const previousCommenterChannel = { + claim_id: activeChannelClaim.claim_id, + name: activeChannelClaim.name, + }; + localStorage.setItem(`commenter_${targetClaimId}`, JSON.stringify(previousCommenterChannel)); + + let lastCommentedClaims = localStorage.getItem('lastCommentedClaims'); + lastCommentedClaims = lastCommentedClaims ? JSON.parse(lastCommentedClaims) : []; + if (!lastCommentedClaims.includes(claim_id)) { + lastCommentedClaims.push(claim_id); + if (lastCommentedClaims.length > 100) { + const droppedItemClaimId = lastCommentedClaims.shift(); + localStorage.removeItem(`commenter_${droppedItemClaimId}`); + } + localStorage.setItem('lastCommentedClaims', JSON.stringify(lastCommentedClaims)); + } + } + dispatch({ type: ACTIONS.COMMENT_CREATE_COMPLETED, data: {