Skip to content

Commit

Permalink
Track deleted channels locally to help with comment spam (#3168)
Browse files Browse the repository at this point in the history
* Track deleted channels locally to help comment spam

* Limit comments to specific creator to a one channel

---------

Co-authored-by: miko <sauce47@posteo.net>
  • Loading branch information
keikari and miko authored Oct 22, 2024
1 parent 19170e4 commit 34cc94f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ui/redux/actions/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen
const myCommentedChannelIds = selectMyCommentedChannelIdsForId(state, claim_id);
const mentionedChannels: Array<MentionedChannel> = [];

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;
Expand All @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 34cc94f

Please sign in to comment.