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'
12 selector: 'my-video-comment-list',
13 templateUrl: './video-comment-list.component.html',
14 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
16 export class VideoCommentListComponent extends RestTable implements OnInit {
17 comments: VideoCommentAdmin[]
19 sort: SortMeta = { field: 'createdAt', order: -1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
26 format: FeedFormat.RSS,
27 label: 'media rss 2.0',
28 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
31 format: FeedFormat.ATOM,
33 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
36 format: FeedFormat.JSON,
38 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
42 selectedComments: VideoCommentAdmin[] = []
43 bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = []
45 inputFilters: AdvancedInputFilter[] = [
47 title: $localize`Advanced filters`,
51 label: $localize`Local comments`
55 label: $localize`Remote comments`
62 return this.auth.getUser()
66 protected router: Router,
67 protected route: ActivatedRoute,
68 private auth: AuthService,
69 private notifier: Notifier,
70 private confirmService: ConfirmService,
71 private videoCommentService: VideoCommentService,
72 private markdownRenderer: MarkdownService,
73 private bulkService: BulkService
77 this.videoCommentActions = [
80 label: $localize`Delete this comment`,
81 handler: comment => this.deleteComment(comment),
82 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
86 label: $localize`Delete all comments of this account`,
87 description: $localize`Comments are deleted after a few minutes`,
88 handler: comment => this.deleteUserComments(comment),
89 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
98 this.bulkCommentActions = [
100 label: $localize`Delete`,
101 handler: comments => this.removeComments(comments),
102 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
109 return 'VideoCommentListComponent'
112 toHtml (text: string) {
113 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
116 isInSelectionMode () {
117 return this.selectedComments.length !== 0
121 this.videoCommentService.getAdminVideoComments({
122 pagination: this.pagination,
126 next: async resultList => {
127 this.totalRecords = resultList.total
131 for (const c of resultList.data) {
133 new VideoCommentAdmin(c, await this.toHtml(c.text))
138 error: err => this.notifier.error(err.message)
142 private removeComments (comments: VideoCommentAdmin[]) {
143 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
145 this.videoCommentService.deleteVideoComments(commentArgs)
148 this.notifier.success($localize`${commentArgs.length} comments deleted.`)
152 error: err => this.notifier.error(err.message),
154 complete: () => this.selectedComments = []
158 private deleteComment (comment: VideoCommentAdmin) {
159 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
161 next: () => this.reloadData(),
163 error: err => this.notifier.error(err.message)
167 private async deleteUserComments (comment: VideoCommentAdmin) {
168 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
169 const res = await this.confirmService.confirm(message, $localize`Delete`)
170 if (res === false) return
173 accountName: comment.by,
174 scope: 'instance' as 'instance'
177 this.bulkService.removeCommentsOf(options)
180 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
183 error: err => this.notifier.error(err.message)