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
this.threadLoading[commentId] = true
const params = {
- videoId: this.video.id,
+ videoId: this.video.uuid,
threadId: commentId
}
'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
}
'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) {
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)
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
this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video)
this.loadMoreThreads()
+
+ if (this.activatedRoute.snapshot.params['threadId']) {
+ this.processHighlightedThread(+this.activatedRoute.snapshot.params['threadId'])
+ }
}
}