]>
Commit | Line | Data |
---|---|---|
54e78847 | 1 | import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core' |
67ed6552 | 2 | import { AuthService, ConfirmService, Notifier, ScreenService } from '@app/core' |
66357162 | 3 | import { BlocklistService, VideoBlockComponent, VideoBlockService, VideoReportComponent } from '@app/shared/shared-moderation' |
3a0fb65c | 4 | import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' |
b46cf4b9 | 5 | import { UserRight, VideoCaption } from '@shared/models' |
66357162 C |
6 | import { |
7 | Actor, | |
8 | DropdownAction, | |
9 | DropdownButtonSize, | |
10 | DropdownDirection, | |
11 | RedundancyService, | |
12 | Video, | |
13 | VideoDetails, | |
14 | VideoService | |
15 | } from '../shared-main' | |
f8c00564 | 16 | import { LiveStreamInformationComponent } from '../shared-video-live' |
67ed6552 C |
17 | import { VideoAddToPlaylistComponent } from '../shared-video-playlist' |
18 | import { VideoDownloadComponent } from './video-download.component' | |
3a0fb65c C |
19 | |
20 | export type VideoActionsDisplayType = { | |
21 | playlist?: boolean | |
22 | download?: boolean | |
23 | update?: boolean | |
24 | blacklist?: boolean | |
25 | delete?: boolean | |
26 | report?: boolean | |
b764380a | 27 | duplicate?: boolean |
d473fd94 | 28 | mute?: boolean |
f8c00564 | 29 | liveInfo?: boolean |
b46cf4b9 | 30 | removeFiles?: boolean |
3a0fb65c C |
31 | } |
32 | ||
33 | @Component({ | |
34 | selector: 'my-video-actions-dropdown', | |
35 | templateUrl: './video-actions-dropdown.component.html', | |
36 | styleUrls: [ './video-actions-dropdown.component.scss' ] | |
37 | }) | |
4da22f64 | 38 | export class VideoActionsDropdownComponent implements OnChanges { |
2f5d2ec5 C |
39 | @ViewChild('playlistDropdown') playlistDropdown: NgbDropdown |
40 | @ViewChild('playlistAdd') playlistAdd: VideoAddToPlaylistComponent | |
3a0fb65c | 41 | |
2f5d2ec5 C |
42 | @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent |
43 | @ViewChild('videoReportModal') videoReportModal: VideoReportComponent | |
5baee5fc | 44 | @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent |
f8c00564 | 45 | @ViewChild('liveStreamInformationModal') liveStreamInformationModal: LiveStreamInformationComponent |
3a0fb65c C |
46 | |
47 | @Input() video: Video | VideoDetails | |
8ba9c205 | 48 | @Input() videoCaptions: VideoCaption[] = [] |
3a0fb65c C |
49 | |
50 | @Input() displayOptions: VideoActionsDisplayType = { | |
51 | playlist: false, | |
52 | download: true, | |
53 | update: true, | |
54 | blacklist: true, | |
55 | delete: true, | |
b764380a | 56 | report: true, |
d473fd94 | 57 | duplicate: true, |
f8c00564 C |
58 | mute: true, |
59 | liveInfo: false | |
3a0fb65c | 60 | } |
8dfceec4 | 61 | @Input() placement = 'left' |
3a0fb65c C |
62 | |
63 | @Input() label: string | |
64 | ||
65 | @Input() buttonStyled = false | |
66 | @Input() buttonSize: DropdownButtonSize = 'normal' | |
67 | @Input() buttonDirection: DropdownDirection = 'vertical' | |
68 | ||
b46cf4b9 | 69 | @Output() videoFilesRemoved = new EventEmitter() |
3a0fb65c | 70 | @Output() videoRemoved = new EventEmitter() |
5baee5fc RK |
71 | @Output() videoUnblocked = new EventEmitter() |
72 | @Output() videoBlocked = new EventEmitter() | |
d473fd94 | 73 | @Output() videoAccountMuted = new EventEmitter() |
689a4f69 | 74 | @Output() modalOpened = new EventEmitter() |
3a0fb65c C |
75 | |
76 | videoActions: DropdownAction<{ video: Video }>[][] = [] | |
77 | ||
78 | private loaded = false | |
79 | ||
80 | constructor ( | |
81 | private authService: AuthService, | |
82 | private notifier: Notifier, | |
83 | private confirmService: ConfirmService, | |
d473fd94 | 84 | private blocklistService: BlocklistService, |
5baee5fc | 85 | private videoBlocklistService: VideoBlockService, |
3a0fb65c C |
86 | private screenService: ScreenService, |
87 | private videoService: VideoService, | |
66357162 | 88 | private redundancyService: RedundancyService |
3a0fb65c C |
89 | ) { } |
90 | ||
91 | get user () { | |
92 | return this.authService.getUser() | |
93 | } | |
94 | ||
95 | ngOnChanges () { | |
1c8ddbfa C |
96 | if (this.loaded) { |
97 | this.loaded = false | |
3bc68dfd | 98 | if (this.playlistAdd) this.playlistAdd.reload() |
1c8ddbfa C |
99 | } |
100 | ||
3a0fb65c C |
101 | this.buildActions() |
102 | } | |
103 | ||
104 | isUserLoggedIn () { | |
105 | return this.authService.isLoggedIn() | |
106 | } | |
107 | ||
108 | loadDropdownInformation () { | |
109 | if (!this.isUserLoggedIn() || this.loaded === true) return | |
110 | ||
111 | this.loaded = true | |
112 | ||
113 | if (this.displayOptions.playlist) this.playlistAdd.load() | |
114 | } | |
115 | ||
116 | /* Show modals */ | |
117 | ||
118 | showDownloadModal () { | |
689a4f69 C |
119 | this.modalOpened.emit() |
120 | ||
8ba9c205 | 121 | this.videoDownloadModal.show(this.video as VideoDetails, this.videoCaptions) |
3a0fb65c C |
122 | } |
123 | ||
124 | showReportModal () { | |
689a4f69 C |
125 | this.modalOpened.emit() |
126 | ||
3a0fb65c C |
127 | this.videoReportModal.show() |
128 | } | |
129 | ||
5baee5fc | 130 | showBlockModal () { |
689a4f69 C |
131 | this.modalOpened.emit() |
132 | ||
3cfa8176 | 133 | this.videoBlockModal.show([ this.video ]) |
3a0fb65c C |
134 | } |
135 | ||
f8c00564 C |
136 | showLiveInfoModal (video: Video) { |
137 | this.modalOpened.emit() | |
138 | ||
139 | this.liveStreamInformationModal.show(video) | |
140 | } | |
141 | ||
3a0fb65c C |
142 | /* Actions checker */ |
143 | ||
144 | isVideoUpdatable () { | |
145 | return this.video.isUpdatableBy(this.user) | |
146 | } | |
147 | ||
148 | isVideoRemovable () { | |
149 | return this.video.isRemovableBy(this.user) | |
150 | } | |
151 | ||
5baee5fc RK |
152 | isVideoBlockable () { |
153 | return this.video.isBlockableBy(this.user) | |
3a0fb65c C |
154 | } |
155 | ||
5baee5fc RK |
156 | isVideoUnblockable () { |
157 | return this.video.isUnblockableBy(this.user) | |
3a0fb65c C |
158 | } |
159 | ||
f8c00564 C |
160 | isVideoLiveInfoAvailable () { |
161 | return this.video.isLiveInfoAvailableBy(this.user) | |
162 | } | |
163 | ||
72675ebe | 164 | isVideoDownloadable () { |
a5cf76af C |
165 | return this.video && |
166 | this.video.isLive !== true && | |
167 | this.video instanceof VideoDetails && | |
168 | this.video.downloadEnabled | |
72675ebe C |
169 | } |
170 | ||
b764380a | 171 | canVideoBeDuplicated () { |
17b7d4b3 | 172 | return !this.video.isLive && this.video.canBeDuplicatedBy(this.user) |
b764380a C |
173 | } |
174 | ||
d473fd94 RK |
175 | isVideoAccountMutable () { |
176 | return this.video.account.id !== this.user.account.id | |
177 | } | |
178 | ||
b46cf4b9 C |
179 | canRemoveVideoFiles () { |
180 | return this.user.hasRight(UserRight.MANAGE_VIDEO_FILES) && this.video.hasHLS() && this.video.hasWebTorrent() | |
181 | } | |
182 | ||
3a0fb65c C |
183 | /* Action handlers */ |
184 | ||
5baee5fc | 185 | async unblockVideo () { |
bc844338 | 186 | const confirmMessage = $localize`Do you really want to unblock ${this.video.name}? It will be available again in the videos list.` |
3a0fb65c | 187 | |
bc844338 | 188 | const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock ${this.video.name}`) |
3a0fb65c C |
189 | if (res === false) return |
190 | ||
d473fd94 | 191 | this.videoBlocklistService.unblockVideo(this.video.id) |
1378c0d3 C |
192 | .subscribe({ |
193 | next: () => { | |
66357162 | 194 | this.notifier.success($localize`Video ${this.video.name} unblocked.`) |
3a0fb65c | 195 | |
d473fd94 | 196 | this.video.blacklisted = false |
2760b454 | 197 | this.video.blacklistedReason = null |
3a0fb65c | 198 | |
d473fd94 RK |
199 | this.videoUnblocked.emit() |
200 | }, | |
3a0fb65c | 201 | |
1378c0d3 C |
202 | error: err => this.notifier.error(err.message) |
203 | }) | |
3a0fb65c C |
204 | } |
205 | ||
206 | async removeVideo () { | |
689a4f69 C |
207 | this.modalOpened.emit() |
208 | ||
bc844338 | 209 | let message = $localize`Do you really want to delete ${this.video.name}?` |
d846d99c C |
210 | if (this.video.isLive) { |
211 | message += ' ' + $localize`The live stream will be automatically terminated.` | |
212 | } | |
213 | ||
bc844338 | 214 | const res = await this.confirmService.confirm(message, $localize`Delete ${this.video.name}`) |
3a0fb65c C |
215 | if (res === false) return |
216 | ||
217 | this.videoService.removeVideo(this.video.id) | |
1378c0d3 C |
218 | .subscribe({ |
219 | next: () => { | |
66357162 | 220 | this.notifier.success($localize`Video ${this.video.name} deleted.`) |
3a0fb65c C |
221 | this.videoRemoved.emit() |
222 | }, | |
223 | ||
1378c0d3 C |
224 | error: err => this.notifier.error(err.message) |
225 | }) | |
3a0fb65c C |
226 | } |
227 | ||
b764380a C |
228 | duplicateVideo () { |
229 | this.redundancyService.addVideoRedundancy(this.video) | |
1378c0d3 C |
230 | .subscribe({ |
231 | next: () => { | |
bc844338 | 232 | const message = $localize`${this.video.name} will be duplicated by your instance.` |
d473fd94 RK |
233 | this.notifier.success(message) |
234 | }, | |
b764380a | 235 | |
1378c0d3 C |
236 | error: err => this.notifier.error(err.message) |
237 | }) | |
d473fd94 RK |
238 | } |
239 | ||
240 | muteVideoAccount () { | |
241 | const params = { nameWithHost: Actor.CREATE_BY_STRING(this.video.account.name, this.video.account.host) } | |
242 | ||
243 | this.blocklistService.blockAccountByUser(params) | |
1378c0d3 C |
244 | .subscribe({ |
245 | next: () => { | |
66357162 | 246 | this.notifier.success($localize`Account ${params.nameWithHost} muted.`) |
d473fd94 RK |
247 | this.videoAccountMuted.emit() |
248 | }, | |
249 | ||
1378c0d3 C |
250 | error: err => this.notifier.error(err.message) |
251 | }) | |
b764380a C |
252 | } |
253 | ||
b46cf4b9 C |
254 | async removeVideoFiles (video: Video, type: 'hls' | 'webtorrent') { |
255 | const confirmMessage = $localize`Do you really want to remove "${this.video.name}" files?` | |
256 | ||
257 | const res = await this.confirmService.confirm(confirmMessage, $localize`Remove "${this.video.name}" files`) | |
258 | if (res === false) return | |
259 | ||
260 | this.videoService.removeVideoFiles([ video.id ], type) | |
261 | .subscribe({ | |
262 | next: () => { | |
263 | this.notifier.success($localize`Removed files of ${video.name}.`) | |
264 | this.videoFilesRemoved.emit() | |
265 | }, | |
266 | ||
267 | error: err => this.notifier.error(err.message) | |
268 | }) | |
269 | } | |
270 | ||
5baee5fc RK |
271 | onVideoBlocked () { |
272 | this.videoBlocked.emit() | |
3a0fb65c C |
273 | } |
274 | ||
275 | getPlaylistDropdownPlacement () { | |
276 | if (this.screenService.isInSmallView()) { | |
277 | return 'bottom-right' | |
278 | } | |
279 | ||
280 | return 'bottom-left bottom-right' | |
281 | } | |
282 | ||
283 | private buildActions () { | |
f238aec5 C |
284 | this.videoActions = [ |
285 | [ | |
3a0fb65c | 286 | { |
66357162 | 287 | label: $localize`Save to playlist`, |
3a0fb65c | 288 | handler: () => this.playlistDropdown.toggle(), |
f238aec5 | 289 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist, |
3a0fb65c C |
290 | iconName: 'playlist-add' |
291 | } | |
f238aec5 | 292 | ], |
d473fd94 | 293 | [ // actions regarding the video |
3a0fb65c | 294 | { |
66357162 | 295 | label: $localize`Download`, |
3a0fb65c | 296 | handler: () => this.showDownloadModal(), |
72675ebe | 297 | isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(), |
3a0fb65c C |
298 | iconName: 'download' |
299 | }, | |
f8c00564 C |
300 | { |
301 | label: $localize`Display live information`, | |
302 | handler: ({ video }) => this.showLiveInfoModal(video), | |
3bc68dfd | 303 | isDisplayed: () => this.displayOptions.liveInfo && this.isVideoLiveInfoAvailable(), |
f8c00564 C |
304 | iconName: 'live' |
305 | }, | |
3a0fb65c | 306 | { |
66357162 | 307 | label: $localize`Update`, |
3a0fb65c C |
308 | linkBuilder: ({ video }) => [ '/videos/update', video.uuid ], |
309 | iconName: 'edit', | |
f238aec5 | 310 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable() |
3a0fb65c C |
311 | }, |
312 | { | |
66357162 | 313 | label: $localize`Block`, |
5baee5fc | 314 | handler: () => this.showBlockModal(), |
3a0fb65c | 315 | iconName: 'no', |
5baee5fc | 316 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable() |
3a0fb65c C |
317 | }, |
318 | { | |
66357162 | 319 | label: $localize`Unblock`, |
5baee5fc | 320 | handler: () => this.unblockVideo(), |
3a0fb65c | 321 | iconName: 'undo', |
5baee5fc | 322 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable() |
3a0fb65c | 323 | }, |
b764380a | 324 | { |
66357162 | 325 | label: $localize`Mirror`, |
b764380a C |
326 | handler: () => this.duplicateVideo(), |
327 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(), | |
328 | iconName: 'cloud-download' | |
329 | }, | |
3a0fb65c | 330 | { |
66357162 | 331 | label: $localize`Delete`, |
3a0fb65c | 332 | handler: () => this.removeVideo(), |
f238aec5 | 333 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(), |
3a0fb65c | 334 | iconName: 'delete' |
d473fd94 | 335 | }, |
3a0fb65c | 336 | { |
66357162 | 337 | label: $localize`Report`, |
3a0fb65c | 338 | handler: () => this.showReportModal(), |
f238aec5 | 339 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report, |
c41c0e28 | 340 | iconName: 'flag' |
3a0fb65c | 341 | } |
d473fd94 | 342 | ], |
b46cf4b9 C |
343 | [ |
344 | { | |
345 | label: $localize`Delete HLS files`, | |
346 | handler: ({ video }) => this.removeVideoFiles(video, 'hls'), | |
347 | isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(), | |
348 | iconName: 'delete' | |
349 | }, | |
350 | { | |
351 | label: $localize`Delete WebTorrent files`, | |
352 | handler: ({ video }) => this.removeVideoFiles(video, 'webtorrent'), | |
353 | isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(), | |
354 | iconName: 'delete' | |
355 | } | |
356 | ], | |
d473fd94 RK |
357 | [ // actions regarding the account/its server |
358 | { | |
66357162 | 359 | label: $localize`Mute account`, |
d473fd94 RK |
360 | handler: () => this.muteVideoAccount(), |
361 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.mute && this.isVideoAccountMutable(), | |
362 | iconName: 'no' | |
363 | } | |
f238aec5 C |
364 | ] |
365 | ] | |
3a0fb65c C |
366 | } |
367 | } |