aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/overview/comments/video-comment-list.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin/overview/comments/video-comment-list.component.ts')
-rw-r--r--client/src/app/+admin/overview/comments/video-comment-list.component.ts186
1 files changed, 186 insertions, 0 deletions
diff --git a/client/src/app/+admin/overview/comments/video-comment-list.component.ts b/client/src/app/+admin/overview/comments/video-comment-list.component.ts
new file mode 100644
index 000000000..25fe65133
--- /dev/null
+++ b/client/src/app/+admin/overview/comments/video-comment-list.component.ts
@@ -0,0 +1,186 @@
1import { SortMeta } from 'primeng/api'
2import { Component, OnInit } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router'
4import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
5import { AdvancedInputFilter } from '@app/shared/shared-forms'
6import { DropdownAction } from '@app/shared/shared-main'
7import { BulkService } from '@app/shared/shared-moderation'
8import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
9import { FeedFormat, UserRight } from '@shared/models'
10
11@Component({
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' ]
15})
16export class VideoCommentListComponent extends RestTable implements OnInit {
17 comments: VideoCommentAdmin[]
18 totalRecords = 0
19 sort: SortMeta = { field: 'createdAt', order: -1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21
22 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
23
24 syndicationItems = [
25 {
26 format: FeedFormat.RSS,
27 label: 'media rss 2.0',
28 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
29 },
30 {
31 format: FeedFormat.ATOM,
32 label: 'atom 1.0',
33 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
34 },
35 {
36 format: FeedFormat.JSON,
37 label: 'json 1.0',
38 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
39 }
40 ]
41
42 selectedComments: VideoCommentAdmin[] = []
43 bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = []
44
45 inputFilters: AdvancedInputFilter[] = [
46 {
47 title: $localize`Advanced filters`,
48 children: [
49 {
50 value: 'local:true',
51 label: $localize`Local comments`
52 },
53 {
54 value: 'local:false',
55 label: $localize`Remote comments`
56 }
57 ]
58 }
59 ]
60
61 get authUser () {
62 return this.auth.getUser()
63 }
64
65 constructor (
66 protected router: Router,
67 protected route: ActivatedRoute,
68 private auth: AuthService,
69 private notifier: Notifier,
70 private confirmService: ConfirmService,
71 private videoCommentService: VideoCommentService,
72 private markdownRenderer: MarkdownService,
73 private bulkService: BulkService
74 ) {
75 super()
76
77 this.videoCommentActions = [
78 [
79 {
80 label: $localize`Delete this comment`,
81 handler: comment => this.deleteComment(comment),
82 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
83 },
84
85 {
86 label: $localize`Delete all comments of this account`,
87 description: $localize`Comments are deleted after a few minutes`,
88 handler: comment => this.deleteUserComments(comment),
89 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
90 }
91 ]
92 ]
93 }
94
95 ngOnInit () {
96 this.initialize()
97
98 this.bulkCommentActions = [
99 {
100 label: $localize`Delete`,
101 handler: comments => this.removeComments(comments),
102 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
103 iconName: 'delete'
104 }
105 ]
106 }
107
108 getIdentifier () {
109 return 'VideoCommentListComponent'
110 }
111
112 toHtml (text: string) {
113 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
114 }
115
116 isInSelectionMode () {
117 return this.selectedComments.length !== 0
118 }
119
120 protected reloadData () {
121 this.videoCommentService.getAdminVideoComments({
122 pagination: this.pagination,
123 sort: this.sort,
124 search: this.search
125 }).subscribe({
126 next: async resultList => {
127 this.totalRecords = resultList.total
128
129 this.comments = []
130
131 for (const c of resultList.data) {
132 this.comments.push(
133 new VideoCommentAdmin(c, await this.toHtml(c.text))
134 )
135 }
136 },
137
138 error: err => this.notifier.error(err.message)
139 })
140 }
141
142 private removeComments (comments: VideoCommentAdmin[]) {
143 const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
144
145 this.videoCommentService.deleteVideoComments(commentArgs)
146 .subscribe({
147 next: () => {
148 this.notifier.success($localize`${commentArgs.length} comments deleted.`)
149 this.reloadData()
150 },
151
152 error: err => this.notifier.error(err.message),
153
154 complete: () => this.selectedComments = []
155 })
156 }
157
158 private deleteComment (comment: VideoCommentAdmin) {
159 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
160 .subscribe({
161 next: () => this.reloadData(),
162
163 error: err => this.notifier.error(err.message)
164 })
165 }
166
167 private async deleteUserComments (comment: VideoCommentAdmin) {
168 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
169 const res = await this.confirmService.confirm(message, $localize`Delete`)
170 if (res === false) return
171
172 const options = {
173 accountName: comment.by,
174 scope: 'instance' as 'instance'
175 }
176
177 this.bulkService.removeCommentsOf(options)
178 .subscribe({
179 next: () => {
180 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
181 },
182
183 error: err => this.notifier.error(err.message)
184 })
185 }
186}