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