1 import { SortMeta } from 'primeng/api'
2 import { AfterViewInit, 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, AfterViewInit {
17 baseRoute = '/admin/moderation/video-comments/list'
19 comments: VideoCommentAdmin[]
21 sort: SortMeta = { field: 'createdAt', order: -1 }
22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
24 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
28 format: FeedFormat.RSS,
29 label: 'media rss 2.0',
30 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
33 format: FeedFormat.ATOM,
35 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
38 format: FeedFormat.JSON,
40 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
44 selectedComments: VideoCommentAdmin[] = []
45 bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = []
47 inputFilters: AdvancedInputFilter[] = [
49 queryParams: { 'search': 'local:true' },
50 label: $localize`Local comments`
53 queryParams: { 'search': 'local:false' },
54 label: $localize`Remote comments`
59 return this.auth.getUser()
63 protected router: Router,
64 protected route: ActivatedRoute,
65 private auth: AuthService,
66 private notifier: Notifier,
67 private confirmService: ConfirmService,
68 private videoCommentService: VideoCommentService,
69 private markdownRenderer: MarkdownService,
70 private bulkService: BulkService
74 this.videoCommentActions = [
77 label: $localize`Delete this comment`,
78 handler: comment => this.deleteComment(comment),
79 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
83 label: $localize`Delete all comments of this account`,
84 description: $localize`Comments are deleted after a few minutes`,
85 handler: comment => this.deleteUserComments(comment),
86 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
94 this.listenToSearchChange()
96 this.bulkCommentActions = [
98 label: $localize`Delete`,
99 handler: comments => this.removeComments(comments),
100 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
107 if (this.search) this.setTableFilter(this.search, false)
111 return 'VideoCommentListComponent'
114 toHtml (text: string) {
115 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
118 isInSelectionMode () {
119 return this.selectedComments.length !== 0
122 protected loadData () {
123 this.videoCommentService.getAdminVideoComments({
124 pagination: this.pagination,
128 async resultList => {
129 this.totalRecords = resultList.total
133 for (const c of resultList.data) {
135 new VideoCommentAdmin(c, await this.toHtml(c.text))
140 err => this.notifier.error(err.message)
144 private async removeComments (comments: VideoCommentAdmin[]) {
145 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
147 this.videoCommentService.deleteVideoComments(commentArgs).subscribe(
149 this.notifier.success($localize`${commentArgs.length} comments deleted.`)
153 err => this.notifier.error(err.message),
155 () => this.selectedComments = []
159 private deleteComment (comment: VideoCommentAdmin) {
160 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
162 () => this.loadData(),
164 err => this.notifier.error(err.message)
168 private async deleteUserComments (comment: VideoCommentAdmin) {
169 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
170 const res = await this.confirmService.confirm(message, $localize`Delete`)
171 if (res === false) return
174 accountName: comment.by,
175 scope: 'instance' as 'instance'
178 this.bulkService.removeCommentsOf(options)
181 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
184 err => this.notifier.error(err.message)