Skip to content

Commit

Permalink
Set 30min expiration to comment channel localstorage lock
Browse files Browse the repository at this point in the history
  • Loading branch information
miko committed Nov 18, 2024
1 parent 628fb13 commit 33f5403
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions ui/redux/actions/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,15 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen
return;
}

const commentChannelChangeCooldown = 1000 * 60 * 30; // 30min
const channelSwitchCutoffTimestamp = Date.now() - commentChannelChangeCooldown;

let previousCommenterChannel = LocalStorage.getItem(`commenter_${targetClaimId}`);
previousCommenterChannel = previousCommenterChannel ? JSON.parse(previousCommenterChannel) : null;
if (
previousCommenterChannel &&
previousCommenterChannel.claim_id !== activeChannelClaim.claim_id &&
previousCommenterChannel.last_comment_timestamp >= channelSwitchCutoffTimestamp &&
myCommentedChannelIds &&
!myCommentedChannelIds.includes(activeChannelClaim.claim_id)
) {
Expand Down Expand Up @@ -826,23 +830,22 @@ 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));
const previousCommenterChannel = {
claim_id: activeChannelClaim.claim_id,
name: activeChannelClaim.name,
last_comment_timestamp: Date.now(),
};
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({
Expand Down

0 comments on commit 33f5403

Please sign in to comment.