diff options
author | Julien Maulny <julien.maulny@protonmail.com> | 2019-11-15 19:05:08 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-12-04 09:36:45 +0100 |
commit | 69222afac8f8c41d90295b33f0695bbff352851e (patch) | |
tree | 63fe1faea94dd3bfc54e633631eecb275c969e54 /client/src/app/videos/+video-watch/comment/video-comments.component.ts | |
parent | 69c7f7525ddf13b7ced787d8b72ac74b43665517 (diff) | |
download | PeerTube-69222afac8f8c41d90295b33f0695bbff352851e.tar.gz PeerTube-69222afac8f8c41d90295b33f0695bbff352851e.tar.zst PeerTube-69222afac8f8c41d90295b33f0695bbff352851e.zip |
Soft delete video comments instead of detroy
Diffstat (limited to 'client/src/app/videos/+video-watch/comment/video-comments.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comments.component.ts | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.ts b/client/src/app/videos/+video-watch/comment/video-comments.component.ts index 57b98afce..cc8b98b4e 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.ts | |||
@@ -153,10 +153,6 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { | |||
153 | async onWantedToDelete (commentToDelete: VideoComment) { | 153 | async onWantedToDelete (commentToDelete: VideoComment) { |
154 | let message = 'Do you really want to delete this comment?' | 154 | let message = 'Do you really want to delete this comment?' |
155 | 155 | ||
156 | if (commentToDelete.totalReplies !== 0) { | ||
157 | message += this.i18n(' {{totalReplies}} replies will be deleted too.', { totalReplies: commentToDelete.totalReplies }) | ||
158 | } | ||
159 | |||
160 | if (commentToDelete.isLocal) { | 156 | if (commentToDelete.isLocal) { |
161 | message += this.i18n(' The deletion will be sent to remote instances, so they remove the comment too.') | 157 | message += this.i18n(' The deletion will be sent to remote instances, so they remove the comment too.') |
162 | } else { | 158 | } else { |
@@ -169,21 +165,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { | |||
169 | this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id) | 165 | this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id) |
170 | .subscribe( | 166 | .subscribe( |
171 | () => { | 167 | () => { |
172 | // Delete the comment in the tree | 168 | // Mark the comment as deleted |
173 | if (commentToDelete.inReplyToCommentId) { | 169 | this.softDeleteComment(commentToDelete) |
174 | const thread = this.threadComments[commentToDelete.threadId] | ||
175 | if (!thread) { | ||
176 | console.error(`Cannot find thread ${commentToDelete.threadId} of the comment to delete ${commentToDelete.id}`) | ||
177 | return | ||
178 | } | ||
179 | |||
180 | this.deleteLocalCommentThread(thread, commentToDelete) | ||
181 | return | ||
182 | } | ||
183 | |||
184 | // Delete the thread | ||
185 | this.comments = this.comments.filter(c => c.id !== commentToDelete.id) | ||
186 | this.componentPagination.totalItems-- | ||
187 | 170 | ||
188 | if (this.highlightedThread.id === commentToDelete.id) this.highlightedThread = undefined | 171 | if (this.highlightedThread.id === commentToDelete.id) this.highlightedThread = undefined |
189 | }, | 172 | }, |
@@ -204,15 +187,11 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { | |||
204 | } | 187 | } |
205 | } | 188 | } |
206 | 189 | ||
207 | private deleteLocalCommentThread (parentComment: VideoCommentThreadTree, commentToDelete: VideoComment) { | 190 | private softDeleteComment (comment: VideoComment) { |
208 | for (const commentChild of parentComment.children) { | 191 | comment.isDeleted = true |
209 | if (commentChild.comment.id === commentToDelete.id) { | 192 | comment.deletedAt = new Date() |
210 | parentComment.children = parentComment.children.filter(c => c.comment.id !== commentToDelete.id) | 193 | comment.text = '' |
211 | return | 194 | comment.account = null |
212 | } | ||
213 | |||
214 | this.deleteLocalCommentThread(commentChild, commentToDelete) | ||
215 | } | ||
216 | } | 195 | } |
217 | 196 | ||
218 | private resetVideo () { | 197 | private resetVideo () { |