1 import { SortMeta } from 'primeng/api'
2 import { filter } from 'rxjs/operators'
3 import { AfterViewInit, Component, OnInit } from '@angular/core'
4 import { ActivatedRoute, Params, Router } from '@angular/router'
5 import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
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()
45 return this.auth.getUser()
49 protected router: Router,
50 protected route: ActivatedRoute,
51 private auth: AuthService,
52 private notifier: Notifier,
53 private confirmService: ConfirmService,
54 private videoCommentService: VideoCommentService,
55 private markdownRenderer: MarkdownService,
56 private bulkService: BulkService
60 this.videoCommentActions = [
63 label: $localize`Delete this comment`,
64 handler: comment => this.deleteComment(comment),
65 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
69 label: $localize`Delete all comments of this account`,
70 description: $localize`Comments are deleted after a few minutes`,
71 handler: comment => this.deleteUserComments(comment),
72 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
80 this.listenToSearchChange()
84 if (this.search) this.setTableFilter(this.search)
88 return 'VideoCommentListComponent'
91 toHtml (text: string) {
92 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
95 protected loadData () {
96 this.videoCommentService.getAdminVideoComments({
97 pagination: this.pagination,
101 async resultList => {
102 this.totalRecords = resultList.total
106 for (const c of resultList.data) {
108 new VideoCommentAdmin(c, await this.toHtml(c.text))
113 err => this.notifier.error(err.message)
117 private deleteComment (comment: VideoCommentAdmin) {
118 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
120 () => this.loadData(),
122 err => this.notifier.error(err.message)
126 private async deleteUserComments (comment: VideoCommentAdmin) {
127 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
128 const res = await this.confirmService.confirm(message, $localize`Delete`)
129 if (res === false) return
132 accountName: comment.by,
133 scope: 'instance' as 'instance'
136 this.bulkService.removeCommentsOf(options)
139 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
142 err => this.notifier.error(err.message)