From 69222afac8f8c41d90295b33f0695bbff352851e Mon Sep 17 00:00:00 2001 From: Julien Maulny Date: Fri, 15 Nov 2019 19:05:08 +0100 Subject: Soft delete video comments instead of detroy --- .../comment/video-comment.component.html | 47 ++++++++++++++++------ .../comment/video-comment.component.scss | 11 +++-- .../comment/video-comment.component.ts | 2 +- .../+video-watch/comment/video-comment.model.ts | 16 +++++--- .../comment/video-comments.component.ts | 35 ++++------------ 5 files changed, 62 insertions(+), 49 deletions(-) (limited to 'client/src') diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.html b/client/src/app/videos/+video-watch/comment/video-comment.component.html index 60b803206..6ec35d63b 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.html +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.html @@ -1,22 +1,45 @@
- Avatar + Avatar + +
-
Highlighted comment
+ +
Highlighted comment
- -
+ +
-
-
Reply
-
Delete
-
+
+
Reply
+
Delete
+
+
+ + + + +
+ This comment has been deleted +
+
{ - // Delete the comment in the tree - if (commentToDelete.inReplyToCommentId) { - const thread = this.threadComments[commentToDelete.threadId] - if (!thread) { - console.error(`Cannot find thread ${commentToDelete.threadId} of the comment to delete ${commentToDelete.id}`) - return - } - - this.deleteLocalCommentThread(thread, commentToDelete) - return - } - - // Delete the thread - this.comments = this.comments.filter(c => c.id !== commentToDelete.id) - this.componentPagination.totalItems-- + // Mark the comment as deleted + this.softDeleteComment(commentToDelete) if (this.highlightedThread.id === commentToDelete.id) this.highlightedThread = undefined }, @@ -204,15 +187,11 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { } } - private deleteLocalCommentThread (parentComment: VideoCommentThreadTree, commentToDelete: VideoComment) { - for (const commentChild of parentComment.children) { - if (commentChild.comment.id === commentToDelete.id) { - parentComment.children = parentComment.children.filter(c => c.comment.id !== commentToDelete.id) - return - } - - this.deleteLocalCommentThread(commentChild, commentToDelete) - } + private softDeleteComment (comment: VideoComment) { + comment.isDeleted = true + comment.deletedAt = new Date() + comment.text = '' + comment.account = null } private resetVideo () { -- cgit v1.2.3