1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
5 import { AdvancedInputFilter } from '@app/shared/shared-forms'
6 import { DropdownAction } from '@app/shared/shared-main'
7 import { BulkService } from '@app/shared/shared-moderation'
8 import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
9 import { FeedFormat, UserRight } from '@shared/models'
10 import { prepareIcu } from '@app/helpers'
13 selector: 'my-video-comment-list',
14 templateUrl: './video-comment-list.component.html',
15 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
17 export class VideoCommentListComponent extends RestTable implements OnInit {
18 comments: VideoCommentAdmin[]
20 sort: SortMeta = { field: 'createdAt', order: -1 }
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
27 format: FeedFormat.RSS,
28 label: 'media rss 2.0',
29 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
32 format: FeedFormat.ATOM,
34 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
37 format: FeedFormat.JSON,
39 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
43 selectedComments: VideoCommentAdmin[] = []
44 bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = []
46 inputFilters: AdvancedInputFilter[] = [
48 title: $localize`Advanced filters`,
52 label: $localize`Local comments`
56 label: $localize`Remote comments`
59 value: 'localVideo:true',
60 label: $localize`Comments on local videos`
67 return this.auth.getUser()
71 protected router: Router,
72 protected route: ActivatedRoute,
73 private auth: AuthService,
74 private notifier: Notifier,
75 private confirmService: ConfirmService,
76 private videoCommentService: VideoCommentService,
77 private markdownRenderer: MarkdownService,
78 private bulkService: BulkService
82 this.videoCommentActions = [
85 label: $localize`Delete this comment`,
86 handler: comment => this.deleteComment(comment),
87 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
91 label: $localize`Delete all comments of this account`,
92 description: $localize`Comments are deleted after a few minutes`,
93 handler: comment => this.deleteUserComments(comment),
94 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
103 this.bulkCommentActions = [
105 label: $localize`Delete`,
106 handler: comments => this.removeComments(comments),
107 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
114 return 'VideoCommentListComponent'
117 toHtml (text: string) {
118 return this.markdownRenderer.textMarkdownToHTML({ markdown: text, withHtml: true, withEmoji: true })
121 isInSelectionMode () {
122 return this.selectedComments.length !== 0
126 this.videoCommentService.getAdminVideoComments({
127 pagination: this.pagination,
131 next: async resultList => {
132 this.totalRecords = resultList.total
136 for (const c of resultList.data) {
138 new VideoCommentAdmin(c, await this.toHtml(c.text))
143 error: err => this.notifier.error(err.message)
147 private removeComments (comments: VideoCommentAdmin[]) {
148 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
150 this.videoCommentService.deleteVideoComments(commentArgs)
153 this.notifier.success(
154 prepareIcu($localize`{count, plural, =1 {1 comment deleted.} other {{count} comments deleted.}}`)(
155 { count: commentArgs.length },
156 $localize`${commentArgs.length} comment(s) deleted.`
163 error: err => this.notifier.error(err.message),
165 complete: () => this.selectedComments = []
169 private deleteComment (comment: VideoCommentAdmin) {
170 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
172 next: () => this.reloadData(),
174 error: err => this.notifier.error(err.message)
178 private async deleteUserComments (comment: VideoCommentAdmin) {
179 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
180 const res = await this.confirmService.confirm(message, $localize`Delete`)
181 if (res === false) return
184 accountName: comment.by,
185 scope: 'instance' as 'instance'
188 this.bulkService.removeCommentsOf(options)
191 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
194 error: err => this.notifier.error(err.message)