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