]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-watch/shared/comment/video-comments.component.ts
Remove suppressImplicitAnyIndexErrors
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-watch / shared / comment / video-comments.component.ts
index 2c39e63fbd372526ef483a604e0a3518000a3f0b..96bdb28c9088128627e533b3cb7f54bd9096bfa6 100644 (file)
@@ -5,11 +5,12 @@ 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 { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
 
 @Component({
   selector: 'my-video-comments',
   templateUrl: './video-comments.component.html',
-  styleUrls: ['./video-comments.component.scss']
+  styleUrls: [ './video-comments.component.scss' ]
 })
 export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
   @ViewChild('commentHighlightBlock') commentHighlightBlock: ElementRef
@@ -78,7 +79,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
     this.threadLoading[commentId] = true
 
     const params = {
-      videoId: this.video.id,
+      videoId: this.video.uuid,
       threadId: commentId
     }
 
@@ -90,27 +91,34 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
       'filter:api.video-watch.video-thread-replies.list.result'
     )
 
-    obs.subscribe(
-        res => {
-          this.threadComments[commentId] = res
-          this.threadLoading[commentId] = false
-          this.hooks.runAction('action:video-watch.video-thread-replies.loaded', 'video-watch', { data: res })
+    obs.subscribe({
+      next: res => {
+        this.threadComments[commentId] = res
+        this.threadLoading[commentId] = false
+        this.hooks.runAction('action:video-watch.video-thread-replies.loaded', 'video-watch', { data: res })
 
-          if (highlightThread) {
-            this.highlightedThread = new VideoComment(res.comment)
+        if (highlightThread) {
+          this.highlightedThread = new VideoComment(res.comment)
 
-            // Scroll to the highlighted thread
-            setTimeout(() => this.commentHighlightBlock.nativeElement.scrollIntoView(), 0)
-          }
-        },
+          // Scroll to the highlighted thread
+          setTimeout(() => this.commentHighlightBlock.nativeElement.scrollIntoView(), 0)
+        }
+      },
+
+      error: err => {
+        // We may try to fetch highlighted thread of another video, skip the error if it is the case
+        // We'll retry the request on video Input() change
+        const errorBody = err.body as PeerTubeProblemDocument
+        if (highlightThread && errorBody?.code === ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO) return
 
-        err => this.notifier.error(err.message)
-      )
+        this.notifier.error(err.message)
+      }
+    })
   }
 
   loadMoreThreads () {
     const params = {
-      videoId: this.video.id,
+      videoId: this.video.uuid,
       componentPagination: this.componentPagination,
       sort: this.sort
     }
@@ -123,18 +131,19 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
       'filter:api.video-watch.video-threads.list.result'
     )
 
-    obs.subscribe(
-      res => {
+    obs.subscribe({
+      next: res => {
         this.comments = this.comments.concat(res.data)
         this.componentPagination.totalItems = res.total
         this.totalNotDeletedComments = res.totalNotDeletedComments
 
         this.onDataSubject.next(res.data)
+
         this.hooks.runAction('action:video-watch.video-threads.loaded', 'video-watch', { data: this.componentPagination })
       },
 
-      err => this.notifier.error(err.message)
-    )
+      error: err => this.notifier.error(err.message)
+    })
   }
 
   onCommentThreadCreated (comment: VideoComment) {
@@ -181,8 +190,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
     if (res === false) return false
 
     this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id)
-      .subscribe(
-        () => {
+      .subscribe({
+        next: () => {
           if (this.highlightedThread?.id === commentToDelete.id) {
             commentToDelete = this.comments.find(c => c.id === commentToDelete.id)
 
@@ -193,14 +202,18 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
           this.softDeleteComment(commentToDelete)
         },
 
-        err => this.notifier.error(err.message)
-      )
+        error: err => this.notifier.error(err.message)
+      })
 
     return true
   }
 
   async onWantedToRedraft (commentToRedraft: VideoComment) {
-    const confirm = await this.onWantedToDelete(commentToRedraft, $localize`Delete and re-draft`, $localize`Do you really want to delete and re-draft this comment?`)
+    const confirm = await this.onWantedToDelete(
+      commentToRedraft,
+      $localize`Delete and re-draft`,
+      $localize`Do you really want to delete and re-draft this comment?`
+    )
 
     if (confirm) {
       this.inReplyToCommentId = commentToRedraft.inReplyToCommentId
@@ -249,6 +262,10 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
 
       this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video)
       this.loadMoreThreads()
+
+      if (this.activatedRoute.snapshot.params['threadId']) {
+        this.processHighlightedThread(+this.activatedRoute.snapshot.params['threadId'])
+      }
     }
   }