1 import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'
2 import { AuthService, ConfirmService, Notifier, ScreenService, ServerService } from '@app/core'
3 import { BlocklistService, VideoBlockComponent, VideoBlockService, VideoReportComponent } from '@app/shared/shared-moderation'
4 import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'
5 import { VideoCaption } from '@shared/models'
15 } from '../shared-main'
16 import { LiveStreamInformationComponent } from '../shared-video-live'
17 import { VideoAddToPlaylistComponent } from '../shared-video-playlist'
18 import { VideoDownloadComponent } from './video-download.component'
20 export type VideoActionsDisplayType = {
36 selector: 'my-video-actions-dropdown',
37 templateUrl: './video-actions-dropdown.component.html',
38 styleUrls: [ './video-actions-dropdown.component.scss' ]
40 export class VideoActionsDropdownComponent implements OnChanges {
41 @ViewChild('playlistDropdown') playlistDropdown: NgbDropdown
42 @ViewChild('playlistAdd') playlistAdd: VideoAddToPlaylistComponent
44 @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
45 @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
46 @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
47 @ViewChild('liveStreamInformationModal') liveStreamInformationModal: LiveStreamInformationComponent
49 @Input() video: Video | VideoDetails
50 @Input() videoCaptions: VideoCaption[] = []
52 @Input() displayOptions: VideoActionsDisplayType = {
66 @Input() placement = 'left'
68 @Input() label: string
70 @Input() buttonStyled = false
71 @Input() buttonSize: DropdownButtonSize = 'normal'
72 @Input() buttonDirection: DropdownDirection = 'vertical'
74 @Output() videoFilesRemoved = new EventEmitter()
75 @Output() videoRemoved = new EventEmitter()
76 @Output() videoUnblocked = new EventEmitter()
77 @Output() videoBlocked = new EventEmitter()
78 @Output() videoAccountMuted = new EventEmitter()
79 @Output() transcodingCreated = new EventEmitter()
80 @Output() modalOpened = new EventEmitter()
82 videoActions: DropdownAction<{ video: Video }>[][] = []
84 private loaded = false
87 private authService: AuthService,
88 private notifier: Notifier,
89 private confirmService: ConfirmService,
90 private blocklistService: BlocklistService,
91 private videoBlocklistService: VideoBlockService,
92 private screenService: ScreenService,
93 private videoService: VideoService,
94 private redundancyService: RedundancyService,
95 private serverService: ServerService
99 return this.authService.getUser()
105 if (this.playlistAdd) this.playlistAdd.reload()
112 return this.authService.isLoggedIn()
115 loadDropdownInformation () {
116 if (!this.isUserLoggedIn() || this.loaded === true) return
120 if (this.displayOptions.playlist) this.playlistAdd.load()
125 showDownloadModal () {
126 this.modalOpened.emit()
128 this.videoDownloadModal.show(this.video as VideoDetails, this.videoCaptions)
132 this.modalOpened.emit()
134 this.videoReportModal.show()
138 this.modalOpened.emit()
140 this.videoBlockModal.show([ this.video ])
143 showLiveInfoModal (video: Video) {
144 this.modalOpened.emit()
146 this.liveStreamInformationModal.show(video)
149 /* Actions checker */
151 isVideoUpdatable () {
152 return this.video.isUpdatableBy(this.user)
156 return this.video.isEditableBy(this.user, this.serverService.getHTMLConfig().videoEditor.enabled)
159 isVideoRemovable () {
160 return this.video.isRemovableBy(this.user)
163 isVideoBlockable () {
164 return this.video.isBlockableBy(this.user)
167 isVideoUnblockable () {
168 return this.video.isUnblockableBy(this.user)
171 isVideoLiveInfoAvailable () {
172 return this.video.isLiveInfoAvailableBy(this.user)
175 isVideoDownloadable () {
177 this.video.isLive !== true &&
178 this.video instanceof VideoDetails &&
179 this.video.downloadEnabled
182 canVideoBeDuplicated () {
183 return !this.video.isLive && this.video.canBeDuplicatedBy(this.user)
186 isVideoAccountMutable () {
187 return this.video.account.id !== this.user.account.id
190 canRemoveVideoFiles () {
191 return this.video.canRemoveFiles(this.user)
194 canRunTranscoding () {
195 return this.video.canRunTranscoding(this.user)
198 /* Action handlers */
200 async unblockVideo () {
201 const confirmMessage = $localize`Do you really want to unblock ${this.video.name}? It will be available again in the videos list.`
203 const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock ${this.video.name}`)
204 if (res === false) return
206 this.videoBlocklistService.unblockVideo(this.video.id)
209 this.notifier.success($localize`Video ${this.video.name} unblocked.`)
211 this.video.blacklisted = false
212 this.video.blacklistedReason = null
214 this.videoUnblocked.emit()
217 error: err => this.notifier.error(err.message)
221 async removeVideo () {
222 this.modalOpened.emit()
224 let message = $localize`Do you really want to delete ${this.video.name}?`
225 if (this.video.isLive) {
226 message += ' ' + $localize`The live stream will be automatically terminated.`
229 const res = await this.confirmService.confirm(message, $localize`Delete ${this.video.name}`)
230 if (res === false) return
232 this.videoService.removeVideo(this.video.id)
235 this.notifier.success($localize`Video ${this.video.name} deleted.`)
236 this.videoRemoved.emit()
239 error: err => this.notifier.error(err.message)
244 this.redundancyService.addVideoRedundancy(this.video)
247 const message = $localize`${this.video.name} will be duplicated by your instance.`
248 this.notifier.success(message)
251 error: err => this.notifier.error(err.message)
255 muteVideoAccount () {
256 const params = { nameWithHost: Actor.CREATE_BY_STRING(this.video.account.name, this.video.account.host) }
258 this.blocklistService.blockAccountByUser(params)
261 this.notifier.success($localize`Account ${params.nameWithHost} muted.`)
262 this.videoAccountMuted.emit()
265 error: err => this.notifier.error(err.message)
269 async removeVideoFiles (video: Video, type: 'hls' | 'webtorrent') {
270 const confirmMessage = $localize`Do you really want to remove "${this.video.name}" files?`
272 const res = await this.confirmService.confirm(confirmMessage, $localize`Remove "${this.video.name}" files`)
273 if (res === false) return
275 this.videoService.removeVideoFiles([ video.id ], type)
278 this.notifier.success($localize`Removed files of ${video.name}.`)
279 this.videoFilesRemoved.emit()
282 error: err => this.notifier.error(err.message)
286 runTranscoding (video: Video, type: 'hls' | 'webtorrent') {
287 this.videoService.runTranscoding([ video.id ], type)
290 this.notifier.success($localize`Transcoding jobs created for ${video.name}.`)
291 this.transcodingCreated.emit()
294 error: err => this.notifier.error(err.message)
299 this.videoBlocked.emit()
302 getPlaylistDropdownPlacement () {
303 if (this.screenService.isInSmallView()) {
304 return 'bottom-right'
307 return 'bottom-left bottom-right'
310 private buildActions () {
311 this.videoActions = [
314 label: $localize`Save to playlist`,
315 handler: () => this.playlistDropdown.toggle(),
316 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist,
317 iconName: 'playlist-add'
320 [ // actions regarding the video
322 label: $localize`Download`,
323 handler: () => this.showDownloadModal(),
324 isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(),
328 label: $localize`Display live information`,
329 handler: ({ video }) => this.showLiveInfoModal(video),
330 isDisplayed: () => this.displayOptions.liveInfo && this.isVideoLiveInfoAvailable(),
334 label: $localize`Update`,
335 linkBuilder: ({ video }) => [ '/videos/update', video.uuid ],
337 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable()
340 label: $localize`Editor`,
341 linkBuilder: ({ video }) => [ '/video-editor/edit', video.uuid ],
343 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.editor && this.isVideoEditable()
346 label: $localize`Block`,
347 handler: () => this.showBlockModal(),
349 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable()
352 label: $localize`Unblock`,
353 handler: () => this.unblockVideo(),
355 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable()
358 label: $localize`Mirror`,
359 handler: () => this.duplicateVideo(),
360 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(),
361 iconName: 'cloud-download'
364 label: $localize`Delete`,
365 handler: () => this.removeVideo(),
366 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(),
370 label: $localize`Report`,
371 handler: () => this.showReportModal(),
372 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report,
378 label: $localize`Run HLS transcoding`,
379 handler: ({ video }) => this.runTranscoding(video, 'hls'),
380 isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
384 label: $localize`Run WebTorrent transcoding`,
385 handler: ({ video }) => this.runTranscoding(video, 'webtorrent'),
386 isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
390 label: $localize`Delete HLS files`,
391 handler: ({ video }) => this.removeVideoFiles(video, 'hls'),
392 isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
396 label: $localize`Delete WebTorrent files`,
397 handler: ({ video }) => this.removeVideoFiles(video, 'webtorrent'),
398 isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
402 [ // actions regarding the account/its server
404 label: $localize`Mute account`,
405 handler: () => this.muteVideoAccount(),
406 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.mute && this.isVideoAccountMutable(),