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:
parent
89faac306a
commit
dc35f8ed24
1 changed files with 17 additions and 13 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue