Remove optional chaining syntax from comments page initializer (#15277)

* Remove questionable syntax from comments initializer

Not sure what ?. is, changing to . to placate the asset precompiler

* Restore conditional access

Rather than changing the ?. to ., wrap the chained access in a guard
clause.

* Fix error in logic

First pass had wrapped this in an "if currentUser" which caused the
else block only to hide comments when no user was logged in, however
the actual behavior should have been to hide comments unless current
user was an article author.
This commit is contained in:
Daniel Uber 2021-11-03 13:04:28 -04:00 committed by GitHub
parent 89faac306a
commit dc35f8ed24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -602,23 +602,27 @@ function handleHiddenComments(commentableType){
if(commentableType === "Article"){
const articleContainer = document.querySelector('#article-show-container');
if(articleContainer){
commentableAuthorIds.push(articleContainer?.dataset?.authorId);
coAuthorIds = articleContainer?.dataset?.coAuthorIds;
if(coAuthorIds){
coAuthorIds.split(',').forEach(coAuthorId => {
commentableAuthorIds.push(coAuthorId);
});
if (articleContainer.dataset) {
commentableAuthorIds.push(articleContainer.dataset.authorId);
coAuthorIds = articleContainer.dataset.coAuthorIds;
if(coAuthorIds){
coAuthorIds.split(',').forEach(coAuthorId => {
commentableAuthorIds.push(coAuthorId);
});
}
}
}
else {
const commentsContainer = document.querySelector('#comments-container');
if(commentsContainer){
commentableAuthorIds.push(commentsContainer?.dataset?.commentableAuthorId);
coAuthorIds = commentsContainer?.dataset?.commentableCoAuthorIds;
if(coAuthorIds){
coAuthorIds.split(',').forEach(coAuthorId => {
commentableAuthorIds.push(coAuthorId);
});
if(commentsContainer.dataset) {
commentableAuthorIds.push(commentsContainer.dataset.commentableAuthorId);
coAuthorIds = commentsContainer.dataset.commentableCoAuthorIds;
if(coAuthorIds){
coAuthorIds.split(',').forEach(coAuthorId => {
commentableAuthorIds.push(coAuthorId);
});
}
}
}
}
@ -628,7 +632,7 @@ function handleHiddenComments(commentableType){
commentableAuthorIds.push(podCastEpisodeContainer.dataset.creatorId);
}
}
if (commentableAuthorIds.includes(currentUser?.id?.toString())){
if(currentUser && commentableAuthorIds.includes(currentUser.id.toString())){
collapseCommentsHiddenByCommentableUser();
}
else {