+ onThreadCreated (commentTree: VideoCommentThreadTree) {
+ this.viewReplies(commentTree.comment.id)
+ }
+
+ async onWantedToDelete (commentToDelete: VideoComment) {
+ let message = 'Do you really want to delete this comment?'
+ if (commentToDelete.totalReplies !== 0) {
+ message += this.i18n(' {{totalReplies}} replies will be deleted too.', { totalReplies: commentToDelete.totalReplies })
+ }
+
+ const res = await this.confirmService.confirm(message, this.i18n('Delete'))
+ if (res === false) return
+
+ this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id)
+ .subscribe(
+ () => {
+ // 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--
+
+ if (this.highlightedThread.id === commentToDelete.id) this.highlightedThread = undefined
+ },
+
+ err => this.notificationsService.error(this.i18n('Error'), err.message)
+ )
+ }
+