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`
63 return this.auth.getUser()
67 protected router: Router,
68 protected route: ActivatedRoute,
69 private auth: AuthService,
70 private notifier: Notifier,
71 private confirmService: ConfirmService,
72 private videoCommentService: VideoCommentService,
73 private markdownRenderer: MarkdownService,
74 private bulkService: BulkService
78 this.videoCommentActions = [
81 label: $localize`Delete this comment`,
82 handler: comment => this.deleteComment(comment),
83 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
87 label: $localize`Delete all comments of this account`,
88 description: $localize`Comments are deleted after a few minutes`,
89 handler: comment => this.deleteUserComments(comment),
90 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
99 this.bulkCommentActions = [
101 label: $localize`Delete`,
102 handler: comments => this.removeComments(comments),
103 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
110 return 'VideoCommentListComponent'
113 toHtml (text: string) {
114 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
117 isInSelectionMode () {
118 return this.selectedComments.length !== 0
122 this.videoCommentService.getAdminVideoComments({
123 pagination: this.pagination,
127 next: async resultList => {
128 this.totalRecords = resultList.total
132 for (const c of resultList.data) {
134 new VideoCommentAdmin(c, await this.toHtml(c.text))
139 error: err => this.notifier.error(err.message)
143 private removeComments (comments: VideoCommentAdmin[]) {
144 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
146 this.videoCommentService.deleteVideoComments(commentArgs)
149 this.notifier.success(
150 prepareIcu($localize`{count, plural, =1 {1 comment deleted.} other {{count} comments deleted.}}`)(
151 { count: commentArgs.length },
152 $localize`${commentArgs.length} comment(s) deleted.`
159 error: err => this.notifier.error(err.message),
161 complete: () => this.selectedComments = []
165 private deleteComment (comment: VideoCommentAdmin) {
166 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
168 next: () => this.reloadData(),
170 error: err => this.notifier.error(err.message)
174 private async deleteUserComments (comment: VideoCommentAdmin) {
175 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
176 const res = await this.confirmService.confirm(message, $localize`Delete`)
177 if (res === false) return
180 accountName: comment.by,
181 scope: 'instance' as 'instance'
184 this.bulkService.removeCommentsOf(options)
187 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
190 error: err => this.notifier.error(err.message)