From e80ec7c78665d95278ec8b804ba298f734c5ff98 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Oct 2020 15:24:12 +1100 Subject: [PATCH 1/7] feat: Change 'Reply' to 'Comment in Thread' --- views/media.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/media.pug b/views/media.pug index c8a6e144..a28b38ac 100644 --- a/views/media.pug +++ b/views/media.pug @@ -779,7 +779,7 @@ block content a(href=`/user/${comment.commenter.channelUrl}` style="color:#d2d2d2;margin-right:5px;") #{comment.commenter.channelName || comment.commenter.channelUrl} p.fw(style="display:inline-block;") - #{comment.timeAgo}   if user && !viewingUserIsBlocked - a.reply-link(style="cursor:pointer") Reply + a.reply-link(style="cursor:pointer") Comment in Thread // delete button // if uploader or admin or commenter, let them delete comment if isUploaderOrAdmin || ( user && comment.commenter._id == user._id ) From 745b2e63da5972d8fa5cb5eca2e5d76fc4946b1b Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Oct 2020 16:01:08 +1100 Subject: [PATCH 2/7] feat: delete and block user buttons to thread comments --- views/media.pug | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/views/media.pug b/views/media.pug index a28b38ac..5cd7be6f 100644 --- a/views/media.pug +++ b/views/media.pug @@ -813,6 +813,17 @@ block content p.fw(style="text-align:left;display:inline-block;") a(href=`/user/${responseComment.commenter.channelUrl}` style="color:#d2d2d2;margin-right:5px;") #{responseComment.commenter.channelName || responseComment.commenter.channelUrl} p.fw(style="display:inline-block;") - #{responseComment.timeAgo}   + // delete button + // if uploader, admin or commenter, let them delete comment + if isUploaderOrAdmin || ( user && comment.commenter._id == user._id ) + a.delete-comment-button(style="margin-left:9px;cursor:pointer;" commentId=comment._id) Delete + + // if uploader, allow (un)blocking a user + // uploader cannot (un)block themselves + if isUploader && !comment.commenter.isBlocked && ( user && comment.commenter._id != user._id ) + a.block-user-button(style="margin-left:9px;cursor:pointer;" blockedusername=comment.commenter.channelUrl) Block User + if isUploader && comment.commenter.isBlocked && ( user && comment.commenter._id != user._id ) + a.unblock-user-button(style="margin-left:9px;cursor:pointer;" blockedusername=comment.commenter.channelUrl) Unblock User p.fw(style="text-align:left;") #{responseComment.text} //div.reply-container(style="display:none") From 8e846c6d66ec7469080fd368938059f241651081 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Oct 2020 16:02:48 +1100 Subject: [PATCH 3/7] refactor: Change delete-comment-btn event handler name --- views/media.pug | 2 +- .../mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/views/media.pug b/views/media.pug index 5cd7be6f..e9361a22 100644 --- a/views/media.pug +++ b/views/media.pug @@ -783,7 +783,7 @@ block content // delete button // if uploader or admin or commenter, let them delete comment if isUploaderOrAdmin || ( user && comment.commenter._id == user._id ) - a.delete-comment-button(style="margin-left:9px;cursor:pointer;" commentId=comment._id) Delete + a.delete-comment-thread-button(style="margin-left:9px;cursor:pointer;" commentId=comment._id) Delete if isUploader && !comment.commenter.isBlocked a.block-user-button(style="margin-left:9px;cursor:pointer;" blockedusername=comment.commenter.channelUrl) Block User diff --git a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug index 77956368..09df24b7 100644 --- a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug +++ b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug @@ -36,7 +36,7 @@ script. } - $('.delete-comment-button').on('release click', function (e) { + $('.delete-comment-thread-button').on('release click', function (e) { var commentThread = $(this).parent().parent().parent().parent(); From 7ad7825049471ff51da884d50bf6d3fab3210bd9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Oct 2020 19:56:23 +1100 Subject: [PATCH 4/7] refactor: Make deleteComments func more generic --- .../deleteCommentAndBlockUnblockUserJs.pug | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug index 09df24b7..7d67c375 100644 --- a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug +++ b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug @@ -1,6 +1,6 @@ script. $(function(){ - function deleteComment(commentId, commentThread) { + function deleteComment(commentId, comment) { var upload = '#{upload._id}'; @@ -21,7 +21,7 @@ script. swal('Comment deleted!'); - commentThread.hide(); + comment.hide(); // remove comment From ca938fb81c6150aa2b16f8e20163c844c3027c58 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Oct 2020 20:03:21 +1100 Subject: [PATCH 5/7] feat: Add delete thread comment functionality --- lib/mediaPlayer/generateCommentsObjects.js | 2 +- views/media.pug | 2 +- .../deleteCommentAndBlockUnblockUserJs.pug | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/mediaPlayer/generateCommentsObjects.js b/lib/mediaPlayer/generateCommentsObjects.js index b936b668..ff8acbe8 100644 --- a/lib/mediaPlayer/generateCommentsObjects.js +++ b/lib/mediaPlayer/generateCommentsObjects.js @@ -11,7 +11,7 @@ async function generateComments(uploadId){ upload: uploadId, visibility: 'public', inResponseTo : {$exists: false} - }).populate({path: 'responses commenter', populate: {path: 'commenter'}}); + }).populate({path: 'responses commenter', match: { visibility: { $ne: 'removed' } }, populate: {path: 'commenter'}}); let commentCount = 0; for(const comment of comments){ diff --git a/views/media.pug b/views/media.pug index e9361a22..b8a58785 100644 --- a/views/media.pug +++ b/views/media.pug @@ -816,7 +816,7 @@ block content // delete button // if uploader, admin or commenter, let them delete comment if isUploaderOrAdmin || ( user && comment.commenter._id == user._id ) - a.delete-comment-button(style="margin-left:9px;cursor:pointer;" commentId=comment._id) Delete + a.delete-thread-comment-button(style="margin-left:9px;cursor:pointer;" commentId=responseComment._id) Delete // if uploader, allow (un)blocking a user // uploader cannot (un)block themselves diff --git a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug index 7d67c375..a9b746e0 100644 --- a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug +++ b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug @@ -60,6 +60,30 @@ script. }) }) + $('.delete-thread-comment-button').on('release click', function (e) { + + var threadComment = $(this).parent().parent().parent(); + + var commentId = $(this).attr('commentId'); + + // dont move browser + e.preventDefault(); + + swal({ + title: "Delete Comment", + text: "Are you sure you want to delete the comment?", + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Delete Comment' + }).then(function (result) { + if (result.value) { + deleteComment(commentId, threadComment) + } else { + swal.close(); + } + }) + }) + function blockUser(blockedUsername) { var csrf = '#{_csrf}' From d806a07e3dcef2cfcce4b0f624972de7b111f098 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Oct 2020 20:19:40 +1100 Subject: [PATCH 6/7] fix: Add logic to hide Block User btn if comment is by same user --- views/media.pug | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/media.pug b/views/media.pug index b8a58785..fa0c8b00 100644 --- a/views/media.pug +++ b/views/media.pug @@ -785,9 +785,9 @@ block content if isUploaderOrAdmin || ( user && comment.commenter._id == user._id ) a.delete-comment-thread-button(style="margin-left:9px;cursor:pointer;" commentId=comment._id) Delete - if isUploader && !comment.commenter.isBlocked + if isUploader && !comment.commenter.isBlocked && ( user && comment.commenter._id != user._id ) a.block-user-button(style="margin-left:9px;cursor:pointer;" blockedusername=comment.commenter.channelUrl) Block User - if isUploader && comment.commenter.isBlocked + if isUploader && comment.commenter.isBlocked && ( user && comment.commenter._id != user._id ) a.unblock-user-button(style="margin-left:9px;cursor:pointer;" blockedusername=comment.commenter.channelUrl) Unblock User From f90aff73b6fe4013a24a40ee6e4489ea5e4e3c81 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 12 Oct 2020 07:26:44 +1100 Subject: [PATCH 7/7] refactor: Change threadComment to commentInThread --- .../deleteCommentAndBlockUnblockUserJs.pug | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug index a9b746e0..88d2d1c1 100644 --- a/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug +++ b/views/mediaPlayerPartials/deleteCommentAndBlockUnblockUserJs.pug @@ -62,7 +62,7 @@ script. $('.delete-thread-comment-button').on('release click', function (e) { - var threadComment = $(this).parent().parent().parent(); + var commentInThread = $(this).parent().parent().parent(); var commentId = $(this).attr('commentId'); @@ -77,7 +77,7 @@ script. confirmButtonText: 'Delete Comment' }).then(function (result) { if (result.value) { - deleteComment(commentId, threadComment) + deleteComment(commentId, commentInThread) } else { swal.close(); }