]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/comments/video-comment-list.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / comments / video-comment-list.component.ts
CommitLineData
0f8d00e3 1import { SortMeta } from 'primeng/api'
1378c0d3 2import { Component, OnInit } from '@angular/core'
93991770 3import { ActivatedRoute, Router } from '@angular/router'
f1273314 4import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
1fd61899 5import { AdvancedInputFilter } from '@app/shared/shared-forms'
f1273314
C
6import { DropdownAction } from '@app/shared/shared-main'
7import { BulkService } from '@app/shared/shared-moderation'
0f8d00e3 8import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
f1273314 9import { FeedFormat, UserRight } from '@shared/models'
eaa52952 10import { prepareIcu } from '@app/helpers'
0f8d00e3
C
11
12@Component({
13 selector: 'my-video-comment-list',
14 templateUrl: './video-comment-list.component.html',
f1273314 15 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
0f8d00e3 16})
cd940f40 17export class VideoCommentListComponent extends RestTable <VideoCommentAdmin> implements OnInit {
0f8d00e3
C
18 comments: VideoCommentAdmin[]
19 totalRecords = 0
20 sort: SortMeta = { field: 'createdAt', order: -1 }
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22
23 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
24
f1273314
C
25 syndicationItems = [
26 {
27 format: FeedFormat.RSS,
28 label: 'media rss 2.0',
29 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
30 },
31 {
32 format: FeedFormat.ATOM,
33 label: 'atom 1.0',
34 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
35 },
36 {
37 format: FeedFormat.JSON,
38 label: 'json 1.0',
39 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
40 }
41 ]
42
cd940f40 43 bulkActions: DropdownAction<VideoCommentAdmin[]>[] = []
93991770 44
1fd61899
C
45 inputFilters: AdvancedInputFilter[] = [
46 {
978c87e7
C
47 title: $localize`Advanced filters`,
48 children: [
49 {
dd6d2a7c 50 value: 'local:true',
978c87e7
C
51 label: $localize`Local comments`
52 },
53 {
dd6d2a7c 54 value: 'local:false',
978c87e7 55 label: $localize`Remote comments`
0e6cd1c0
C
56 },
57 {
58 value: 'localVideo:true',
59 label: $localize`Comments on local videos`
978c87e7
C
60 }
61 ]
1fd61899
C
62 }
63 ]
64
f1273314
C
65 get authUser () {
66 return this.auth.getUser()
67 }
68
0f8d00e3 69 constructor (
5ed46c1b
C
70 protected router: Router,
71 protected route: ActivatedRoute,
f1273314 72 private auth: AuthService,
0f8d00e3 73 private notifier: Notifier,
0f8d00e3
C
74 private confirmService: ConfirmService,
75 private videoCommentService: VideoCommentService,
76 private markdownRenderer: MarkdownService,
f1273314 77 private bulkService: BulkService
9df52d66 78 ) {
0f8d00e3
C
79 super()
80
81 this.videoCommentActions = [
82 [
f1273314
C
83 {
84 label: $localize`Delete this comment`,
85 handler: comment => this.deleteComment(comment),
86 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
87 },
0f8d00e3 88
f1273314
C
89 {
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)
94 }
0f8d00e3
C
95 ]
96 ]
97 }
98
99 ngOnInit () {
100 this.initialize()
93991770 101
cd940f40 102 this.bulkActions = [
93991770
C
103 {
104 label: $localize`Delete`,
105 handler: comments => this.removeComments(comments),
106 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
107 iconName: 'delete'
108 }
109 ]
0f8d00e3
C
110 }
111
0f8d00e3
C
112 getIdentifier () {
113 return 'VideoCommentListComponent'
114 }
115
116 toHtml (text: string) {
0e45e336 117 return this.markdownRenderer.textMarkdownToHTML({ markdown: text, withHtml: true, withEmoji: true })
0f8d00e3
C
118 }
119
e854d57b 120 protected reloadDataInternal () {
0f8d00e3
C
121 this.videoCommentService.getAdminVideoComments({
122 pagination: this.pagination,
123 sort: this.sort,
124 search: this.search
1378c0d3
C
125 }).subscribe({
126 next: async resultList => {
127 this.totalRecords = resultList.total
0f8d00e3 128
1378c0d3 129 this.comments = []
0f8d00e3 130
1378c0d3
C
131 for (const c of resultList.data) {
132 this.comments.push(
133 new VideoCommentAdmin(c, await this.toHtml(c.text))
134 )
135 }
136 },
0f8d00e3 137
1378c0d3
C
138 error: err => this.notifier.error(err.message)
139 })
0f8d00e3 140 }
f1273314 141
98ab5dc8 142 private removeComments (comments: VideoCommentAdmin[]) {
93991770
C
143 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
144
1378c0d3
C
145 this.videoCommentService.deleteVideoComments(commentArgs)
146 .subscribe({
147 next: () => {
eaa52952 148 this.notifier.success(
baf99fcc 149 prepareIcu($localize`{count, plural, =1 {1 comment deleted.} other {{count} comments deleted.}}`)(
eaa52952
C
150 { count: commentArgs.length },
151 $localize`${commentArgs.length} comment(s) deleted.`
152 )
153 )
154
1378c0d3
C
155 this.reloadData()
156 },
93991770 157
1378c0d3 158 error: err => this.notifier.error(err.message),
93991770 159
cd940f40 160 complete: () => this.selectedRows = []
1378c0d3 161 })
93991770
C
162 }
163
f1273314
C
164 private deleteComment (comment: VideoCommentAdmin) {
165 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
1378c0d3
C
166 .subscribe({
167 next: () => this.reloadData(),
f1273314 168
1378c0d3
C
169 error: err => this.notifier.error(err.message)
170 })
f1273314
C
171 }
172
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
177
178 const options = {
179 accountName: comment.by,
180 scope: 'instance' as 'instance'
181 }
182
183 this.bulkService.removeCommentsOf(options)
1378c0d3
C
184 .subscribe({
185 next: () => {
f1273314
C
186 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
187 },
188
1378c0d3
C
189 error: err => this.notifier.error(err.message)
190 })
f1273314 191 }
0f8d00e3 192}