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 queryParams: { search: 'local:true' },
48 label: $localize`Local comments`
51 queryParams: { search: 'local:false' },
52 label: $localize`Remote comments`
57 return this.auth.getUser()
61 protected router: Router,
62 protected route: ActivatedRoute,
63 private auth: AuthService,
64 private notifier: Notifier,
65 private confirmService: ConfirmService,
66 private videoCommentService: VideoCommentService,
67 private markdownRenderer: MarkdownService,
68 private bulkService: BulkService
72 this.videoCommentActions = [
75 label: $localize`Delete this comment`,
76 handler: comment => this.deleteComment(comment),
77 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
81 label: $localize`Delete all comments of this account`,
82 description: $localize`Comments are deleted after a few minutes`,
83 handler: comment => this.deleteUserComments(comment),
84 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
93 this.bulkCommentActions = [
95 label: $localize`Delete`,
96 handler: comments => this.removeComments(comments),
97 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
104 return 'VideoCommentListComponent'
107 toHtml (text: string) {
108 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
111 isInSelectionMode () {
112 return this.selectedComments.length !== 0
115 protected reloadData () {
116 this.videoCommentService.getAdminVideoComments({
117 pagination: this.pagination,
121 next: async resultList => {
122 this.totalRecords = resultList.total
126 for (const c of resultList.data) {
128 new VideoCommentAdmin(c, await this.toHtml(c.text))
133 error: err => this.notifier.error(err.message)
137 private async removeComments (comments: VideoCommentAdmin[]) {
138 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
140 this.videoCommentService.deleteVideoComments(commentArgs)
143 this.notifier.success($localize`${commentArgs.length} comments deleted.`)
147 error: err => this.notifier.error(err.message),
149 complete: () => this.selectedComments = []
153 private deleteComment (comment: VideoCommentAdmin) {
154 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
156 next: () => this.reloadData(),
158 error: err => this.notifier.error(err.message)
162 private async deleteUserComments (comment: VideoCommentAdmin) {
163 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
164 const res = await this.confirmService.confirm(message, $localize`Delete`)
165 if (res === false) return
168 accountName: comment.by,
169 scope: 'instance' as 'instance'
172 this.bulkService.removeCommentsOf(options)
175 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
178 error: err => this.notifier.error(err.message)