]>
Commit | Line | Data |
---|---|---|
0f8d00e3 | 1 | import { SortMeta } from 'primeng/api' |
1378c0d3 | 2 | import { Component, OnInit } from '@angular/core' |
93991770 | 3 | import { ActivatedRoute, Router } from '@angular/router' |
f1273314 | 4 | import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core' |
1fd61899 | 5 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
f1273314 C |
6 | import { DropdownAction } from '@app/shared/shared-main' |
7 | import { BulkService } from '@app/shared/shared-moderation' | |
0f8d00e3 | 8 | import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment' |
f1273314 | 9 | import { FeedFormat, UserRight } from '@shared/models' |
0f8d00e3 C |
10 | |
11 | @Component({ | |
12 | selector: 'my-video-comment-list', | |
13 | templateUrl: './video-comment-list.component.html', | |
f1273314 | 14 | styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ] |
0f8d00e3 | 15 | }) |
2e46eb97 | 16 | export class VideoCommentListComponent extends RestTable implements OnInit { |
0f8d00e3 C |
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 | ||
f1273314 C |
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 | ||
93991770 C |
42 | selectedComments: VideoCommentAdmin[] = [] |
43 | bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = [] | |
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 C |
55 | label: $localize`Remote comments` |
56 | } | |
57 | ] | |
1fd61899 C |
58 | } |
59 | ] | |
60 | ||
f1273314 C |
61 | get authUser () { |
62 | return this.auth.getUser() | |
63 | } | |
64 | ||
0f8d00e3 | 65 | constructor ( |
5ed46c1b C |
66 | protected router: Router, |
67 | protected route: ActivatedRoute, | |
f1273314 | 68 | private auth: AuthService, |
0f8d00e3 | 69 | private notifier: Notifier, |
0f8d00e3 C |
70 | private confirmService: ConfirmService, |
71 | private videoCommentService: VideoCommentService, | |
72 | private markdownRenderer: MarkdownService, | |
f1273314 | 73 | private bulkService: BulkService |
9df52d66 | 74 | ) { |
0f8d00e3 C |
75 | super() |
76 | ||
77 | this.videoCommentActions = [ | |
78 | [ | |
f1273314 C |
79 | { |
80 | label: $localize`Delete this comment`, | |
81 | handler: comment => this.deleteComment(comment), | |
82 | isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) | |
83 | }, | |
0f8d00e3 | 84 | |
f1273314 C |
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 | } | |
0f8d00e3 C |
91 | ] |
92 | ] | |
93 | } | |
94 | ||
95 | ngOnInit () { | |
96 | this.initialize() | |
93991770 C |
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 | ] | |
0f8d00e3 C |
106 | } |
107 | ||
0f8d00e3 C |
108 | getIdentifier () { |
109 | return 'VideoCommentListComponent' | |
110 | } | |
111 | ||
112 | toHtml (text: string) { | |
f1273314 | 113 | return this.markdownRenderer.textMarkdownToHTML(text, true, true) |
0f8d00e3 C |
114 | } |
115 | ||
93991770 C |
116 | isInSelectionMode () { |
117 | return this.selectedComments.length !== 0 | |
118 | } | |
119 | ||
2e46eb97 | 120 | protected reloadData () { |
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: () => { | |
148 | this.notifier.success($localize`${commentArgs.length} comments deleted.`) | |
149 | this.reloadData() | |
150 | }, | |
93991770 | 151 | |
1378c0d3 | 152 | error: err => this.notifier.error(err.message), |
93991770 | 153 | |
1378c0d3 C |
154 | complete: () => this.selectedComments = [] |
155 | }) | |
93991770 C |
156 | } |
157 | ||
f1273314 C |
158 | private deleteComment (comment: VideoCommentAdmin) { |
159 | this.videoCommentService.deleteVideoComment(comment.video.id, comment.id) | |
1378c0d3 C |
160 | .subscribe({ |
161 | next: () => this.reloadData(), | |
f1273314 | 162 | |
1378c0d3 C |
163 | error: err => this.notifier.error(err.message) |
164 | }) | |
f1273314 C |
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) | |
1378c0d3 C |
178 | .subscribe({ |
179 | next: () => { | |
f1273314 C |
180 | this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`) |
181 | }, | |
182 | ||
1378c0d3 C |
183 | error: err => this.notifier.error(err.message) |
184 | }) | |
f1273314 | 185 | } |
0f8d00e3 | 186 | } |