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 <VideoCommentAdmin> 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 bulkActions: DropdownAction<VideoCommentAdmin[]>[] = []
45 inputFilters: AdvancedInputFilter[] = [
47 title: $localize`Advanced filters`,
51 label: $localize`Local comments`
55 label: $localize`Remote comments`
58 value: 'localVideo:true',
59 label: $localize`Comments on local videos`
66 return this.auth.getUser()
70 protected router: Router,
71 protected route: ActivatedRoute,
72 private auth: AuthService,
73 private notifier: Notifier,
74 private confirmService: ConfirmService,
75 private videoCommentService: VideoCommentService,
76 private markdownRenderer: MarkdownService,
77 private bulkService: BulkService
81 this.videoCommentActions = [
84 label: $localize`Delete this comment`,
85 handler: comment => this.deleteComment(comment),
86 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
90 label: $localize`Delete all comments of this account`,
91 description: $localize`Comments are deleted after a few minutes`,
92 handler: comment => this.deleteUserComments(comment),
93 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
104 label: $localize`Delete`,
105 handler: comments => this.removeComments(comments),
106 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
113 return 'VideoCommentListComponent'
116 toHtml (text: string) {
117 return this.markdownRenderer.textMarkdownToHTML({ markdown: text, withHtml: true, withEmoji: true })
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(
149 prepareIcu($localize`{count, plural, =1 {1 comment deleted.} other {{count} comments deleted.}}`)(
150 { count: commentArgs.length },
151 $localize`${commentArgs.length} comment(s) deleted.`
158 error: err => this.notifier.error(err.message),
160 complete: () => this.selectedRows = []
164 private deleteComment (comment: VideoCommentAdmin) {
165 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
167 next: () => this.reloadData(),
169 error: err => this.notifier.error(err.message)
173 private async deleteUserComments (comment: VideoCommentAdmin) {
174 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
175 const res = await this.confirmService.confirm(message, $localize`Delete`)
176 if (res === false) return
179 accountName: comment.by,
180 scope: 'instance' as 'instance'
183 this.bulkService.removeCommentsOf(options)
186 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
189 error: err => this.notifier.error(err.message)