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

Comment Tracker: Fix edited comment appears as read instead of unread #1773

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ngoclong19
Copy link
Contributor

Steps to reproduce:

  • Enable ESGST setting "5.7.6 - Fade out read comments"
  • Visit this comment:
    https://www.steamgifts.com/go/comment/vYbrsc9
  • Click the button "Mark all comments in this page as read"
  • Wait for the comment to be edited
  • Reload the page, edited comments appear as read.

Actual results:

  • Open Firefox's add-on debugging tool at:
    about:debugging#/runtime/this-firefox
  • Inspect ESGST
  • In debugging console tab, execute this line:
    browser.storage.local.get('discussions').then((item) => {console.log(JSON.parse(item.discussions)['tnWVh'].readComments['vYbrsc9'])})
  • The value 1688003432 is returned
  • Inspect the comment on SG web site, we could see that the created timestamp is 1688003432 and the edited timestamp is 1688154585.

Expected results:

  • Edited comments show up as unread
  • ESGST should keep track of edited time, then created time, in order of preference.

In this PR, I would like to add the following changes:

  • Fix edited comment appears as read instead of unread
  • Migrate the code to TypeScript.

Copy link
Owner

@rafaelgomesxyz rafaelgomesxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Finally got around to it, just a few comments.

if (!author) {
return;
return {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This messes with the logic, because of:

comment = await this.comments_getInfo(
    matches[i],
    Scope.current?.sourceLink || sourceLink,
    endless ? this.esgst.users : JSON.parse(getValue('users')),
    main
);
if (comment) {
    comments.push(comment);
}

So the empty object will be added to the array and might cause issues with features that rely on this array for actual comment objects.

Better to return null instead.

comment.actions = element;
}
if (!comment.actions) {
return {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to return null instead.

return comment;
}
}
return {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to return null instead.

for (let i = matches.length - 1; i >= 0; --i) {
if (!sourceLink) {
continue;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make much sense here, because sourceLink is queried outside of the loop, so if it doesn't exist, we can return before the loop instead of evaluating it again for each match.

However, I'm not sure that it's a good idea to add this check, as I'm not sure that sourceLink will always exist. This might break the feature in some places. Better to make sourceLink accept HTMLElement | undefined.

element = comment.comment.parentElement;
if (element) {
comment.parent = element;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element = comment.comment.parentElement would already receive either an HTMLElement or null, so there's no need to assign it under a conditional.

element = comment.comment.querySelector('.comment__summary, .comment_body');
if (element) {
comment.summary = element;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment.summary = comment.comment.querySelector('.comment__summary, .comment_body') would already receive either an HTMLElement or undefined, so there's no need to assign it under a conditional.

element = comment.comment.querySelector('.comment__display-state, .comment_body_default');
if (element) {
comment.displayState = element;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment.displayState = comment.comment.querySelector('.comment__display-state, .comment_body_default') would already receive either an HTMLElement or undefined, so there's no need to assign it under a conditional.

.replace(/[^A-Za-z]/g, '')
.match(/^(havea|takea|thanksand|thankyou)?bump(ing|ity|o)?$/i);
if (reMatches) {
comment.bump = reMatches;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment.bump would already receive null if there are no matches, so there's no need to assign it under a conditional.

element = comment.comment.querySelector('.comment__actions, .action_list');
if (element) {
comment.actions = element;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment.actions = comment.comment.querySelector('.comment__actions, .action_list') would already receive either an HTMLElement or undefined, so there's no need to assign it under a conditional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants