]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-watch/comment/video-comments.component.ts
Fix comments count
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-watch / comment / video-comments.component.ts
index 9e8e143c257e658856e4dcdfbaca2a12de324968..f83a73ccd5f0792aa0180133defdb1baca765c34 100644 (file)
@@ -5,6 +5,7 @@ import { AuthService, ComponentPagination, ConfirmService, hasMoreItems, Notifie
 import { HooksService } from '@app/core/plugins/hooks.service'
 import { Syndication, VideoDetails } from '@app/shared/shared-main'
 import { VideoComment, VideoCommentService, VideoCommentThreadTree } from '@app/shared/shared-video-comment'
+import { ThisReceiver } from '@angular/compiler'
 
 @Component({
   selector: 'my-video-comments',
@@ -121,7 +122,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
     obs.subscribe(
       res => {
         this.comments = this.comments.concat(res.data)
-        this.componentPagination.totalItems = res.total
+        // Client does not display removed comments
+        this.componentPagination.totalItems = res.total - this.comments.filter(c => c.isDeleted).length
 
         this.onDataSubject.next(res.data)
         this.hooks.runAction('action:video-watch.video-threads.loaded', 'video-watch', { data: this.componentPagination })
@@ -133,7 +135,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
 
   onCommentThreadCreated (comment: VideoComment) {
     this.comments.unshift(comment)
-    delete this.commentThreadRedraftValue
+    this.commentThreadRedraftValue = undefined
   }
 
   onWantedToReply (comment: VideoComment) {
@@ -142,7 +144,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
 
   onResetReply () {
     this.inReplyToCommentId = undefined
-    delete this.commentReplyRedraftValue
+    this.commentReplyRedraftValue = undefined
   }
 
   onThreadCreated (commentTree: VideoCommentThreadTree) {
@@ -160,7 +162,11 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
     this.timestampClicked.emit(timestamp)
   }
 
-  async onWantedToDelete(commentToDelete: VideoComment, title = $localize`Delete`, message = $localize`Do you really want to delete this comment?`): Promise<boolean> {
+  async onWantedToDelete (
+    commentToDelete: VideoComment,
+    title = $localize`Delete`,
+    message = $localize`Do you really want to delete this comment?`
+  ): Promise<boolean> {
     if (commentToDelete.isLocal || this.video.isLocal) {
       message += $localize` The deletion will be sent to remote instances so they can reflect the change.`
     } else {
@@ -195,10 +201,13 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
     if (confirm) {
       this.inReplyToCommentId = commentToRedraft.inReplyToCommentId
 
+      // Restore line feed for editing
+      const commentToRedraftText = commentToRedraft.text.replace(/<br.?\/?>/g, '\r\n')
+
       if (commentToRedraft.threadId === commentToRedraft.id) {
-        this.commentThreadRedraftValue = commentToRedraft.text
+        this.commentThreadRedraftValue = commentToRedraftText
       } else {
-        this.commentReplyRedraftValue = commentToRedraft.text
+        this.commentReplyRedraftValue = commentToRedraftText
       }
 
     }