Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set 30min expiration to comment channel localstorage lock #3182

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading