]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/comments/video-comment-list.component.ts
Fix HTML in account/channel description
[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})
2e46eb97 17export class VideoCommentListComponent extends RestTable 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
93991770
C
43 selectedComments: VideoCommentAdmin[] = []
44 bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = []
45
1fd61899
C
46 inputFilters: AdvancedInputFilter[] = [
47 {
978c87e7
C
48 title: $localize`Advanced filters`,
49 children: [
50 {
dd6d2a7c 51 value: 'local:true',
978c87e7
C
52 label: $localize`Local comments`
53 },
54 {
dd6d2a7c 55 value: 'local:false',
978c87e7 56 label: $localize`Remote comments`
0e6cd1c0
C
57 },
58 {
59 value: 'localVideo:true',
60 label: $localize`Comments on local videos`
978c87e7
C
61 }
62 ]
1fd61899
C
63 }
64 ]
65
f1273314
C
66 get authUser () {
67 return this.auth.getUser()
68 }
69
0f8d00e3 70 constructor (
5ed46c1b
C
71 protected router: Router,
72 protected route: ActivatedRoute,
f1273314 73 private auth: AuthService,
0f8d00e3 74 private notifier: Notifier,
0f8d00e3
C
75 private confirmService: ConfirmService,
76 private videoCommentService: VideoCommentService,
77 private markdownRenderer: MarkdownService,
f1273314 78 private bulkService: BulkService
9df52d66 79 ) {
0f8d00e3
C
80 super()
81
82 this.videoCommentActions = [
83 [
f1273314
C
84 {
85 label: $localize`Delete this comment`,
86 handler: comment => this.deleteComment(comment),
87 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
88 },
0f8d00e3 89
f1273314
C
90 {
91 label: $localize`Delete all comments of this account`,
92 description: $localize`Comments are deleted after a few minutes`,
93 handler: comment => this.deleteUserComments(comment),
94 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
95 }
0f8d00e3
C
96 ]
97 ]
98 }
99
100 ngOnInit () {
101 this.initialize()
93991770
C
102
103 this.bulkCommentActions = [
104 {
105 label: $localize`Delete`,
106 handler: comments => this.removeComments(comments),
107 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
108 iconName: 'delete'
109 }
110 ]
0f8d00e3
C
111 }
112
0f8d00e3
C
113 getIdentifier () {
114 return 'VideoCommentListComponent'
115 }
116
117 toHtml (text: string) {
0e45e336 118 return this.markdownRenderer.textMarkdownToHTML({ markdown: text, withHtml: true, withEmoji: true })
0f8d00e3
C
119 }
120
93991770
C
121 isInSelectionMode () {
122 return this.selectedComments.length !== 0
123 }
124
fbd573e5 125 reloadData () {
0f8d00e3
C
126 this.videoCommentService.getAdminVideoComments({
127 pagination: this.pagination,
128 sort: this.sort,
129 search: this.search
1378c0d3
C
130 }).subscribe({
131 next: async resultList => {
132 this.totalRecords = resultList.total
0f8d00e3 133
1378c0d3 134 this.comments = []
0f8d00e3 135
1378c0d3
C
136 for (const c of resultList.data) {
137 this.comments.push(
138 new VideoCommentAdmin(c, await this.toHtml(c.text))
139 )
140 }
141 },
0f8d00e3 142
1378c0d3
C
143 error: err => this.notifier.error(err.message)
144 })
0f8d00e3 145 }
f1273314 146
98ab5dc8 147 private removeComments (comments: VideoCommentAdmin[]) {
93991770
C
148 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
149
1378c0d3
C
150 this.videoCommentService.deleteVideoComments(commentArgs)
151 .subscribe({
152 next: () => {
eaa52952 153 this.notifier.success(
baf99fcc 154 prepareIcu($localize`{count, plural, =1 {1 comment deleted.} other {{count} comments deleted.}}`)(
eaa52952
C
155 { count: commentArgs.length },
156 $localize`${commentArgs.length} comment(s) deleted.`
157 )
158 )
159
1378c0d3
C
160 this.reloadData()
161 },
93991770 162
1378c0d3 163 error: err => this.notifier.error(err.message),
93991770 164
1378c0d3
C
165 complete: () => this.selectedComments = []
166 })
93991770
C
167 }
168
f1273314
C
169 private deleteComment (comment: VideoCommentAdmin) {
170 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
1378c0d3
C
171 .subscribe({
172 next: () => this.reloadData(),
f1273314 173
1378c0d3
C
174 error: err => this.notifier.error(err.message)
175 })
f1273314
C
176 }
177
178 private async deleteUserComments (comment: VideoCommentAdmin) {
179 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
180 const res = await this.confirmService.confirm(message, $localize`Delete`)
181 if (res === false) return
182
183 const options = {
184 accountName: comment.by,
185 scope: 'instance' as 'instance'
186 }
187
188 this.bulkService.removeCommentsOf(options)
1378c0d3
C
189 .subscribe({
190 next: () => {
f1273314
C
191 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
192 },
193
1378c0d3
C
194 error: err => this.notifier.error(err.message)
195 })
f1273314 196 }
0f8d00e3 197}