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 { DropdownAction } from '@app/shared/shared-main'
6 import { BulkService } from '@app/shared/shared-moderation'
7 import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
8 import { FeedFormat, UserRight } from '@shared/models'
11 selector: 'my-video-comment-list',
12 templateUrl: './video-comment-list.component.html',
13 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
15 export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit {
16 baseRoute = '/admin/moderation/video-comments/list'
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 selectedComments: VideoCommentAdmin[] = []
44 bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = []
47 return this.auth.getUser()
51 protected router: Router,
52 protected route: ActivatedRoute,
53 private auth: AuthService,
54 private notifier: Notifier,
55 private confirmService: ConfirmService,
56 private videoCommentService: VideoCommentService,
57 private markdownRenderer: MarkdownService,
58 private bulkService: BulkService
62 this.videoCommentActions = [
65 label: $localize`Delete this comment`,
66 handler: comment => this.deleteComment(comment),
67 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
71 label: $localize`Delete all comments of this account`,
72 description: $localize`Comments are deleted after a few minutes`,
73 handler: comment => this.deleteUserComments(comment),
74 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
82 this.listenToSearchChange()
84 this.bulkCommentActions = [
86 label: $localize`Delete`,
87 handler: comments => this.removeComments(comments),
88 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
95 if (this.search) this.setTableFilter(this.search)
99 return 'VideoCommentListComponent'
102 toHtml (text: string) {
103 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
106 isInSelectionMode () {
107 return this.selectedComments.length !== 0
110 protected loadData () {
111 this.videoCommentService.getAdminVideoComments({
112 pagination: this.pagination,
116 async resultList => {
117 this.totalRecords = resultList.total
121 for (const c of resultList.data) {
123 new VideoCommentAdmin(c, await this.toHtml(c.text))
128 err => this.notifier.error(err.message)
132 private async removeComments (comments: VideoCommentAdmin[]) {
133 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
135 this.videoCommentService.deleteVideoComments(commentArgs).subscribe(
137 this.notifier.success($localize`${commentArgs.length} comments deleted.`)
141 err => this.notifier.error(err.message),
143 () => this.selectedComments = []
147 private deleteComment (comment: VideoCommentAdmin) {
148 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
150 () => this.loadData(),
152 err => this.notifier.error(err.message)
156 private async deleteUserComments (comment: VideoCommentAdmin) {
157 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
158 const res = await this.confirmService.confirm(message, $localize`Delete`)
159 if (res === false) return
162 accountName: comment.by,
163 scope: 'instance' as 'instance'
166 this.bulkService.removeCommentsOf(options)
169 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
172 err => this.notifier.error(err.message)