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, VideoState } 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.serverService.getHTMLConfig().videoEditor.enabled &&
157 this.video.state?.id === VideoState.PUBLISHED &&
158 this.video.isUpdatableBy(this.user)
161 isVideoRemovable () {
162 return this.video.isRemovableBy(this.user)
165 isVideoBlockable () {
166 return this.video.isBlockableBy(this.user)
169 isVideoUnblockable () {
170 return this.video.isUnblockableBy(this.user)
173 isVideoLiveInfoAvailable () {
174 return this.video.isLiveInfoAvailableBy(this.user)
177 isVideoDownloadable () {
179 this.video.isLive !== true &&
180 this.video instanceof VideoDetails &&
181 this.video.downloadEnabled
184 canVideoBeDuplicated () {
185 return !this.video.isLive && this.video.canBeDuplicatedBy(this.user)
188 isVideoAccountMutable () {
189 return this.video.account.id !== this.user.account.id
192 canRemoveVideoFiles () {
193 return this.video.canRemoveFiles(this.user)
196 canRunTranscoding () {
197 return this.video.canRunTranscoding(this.user)
200 /* Action handlers */
202 async unblockVideo () {
203 const confirmMessage = $localize`Do you really want to unblock ${this.video.name}? It will be available again in the videos list.`
205 const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock ${this.video.name}`)
206 if (res === false) return
208 this.videoBlocklistService.unblockVideo(this.video.id)
211 this.notifier.success($localize`Video ${this.video.name} unblocked.`)
213 this.video.blacklisted = false
214 this.video.blacklistedReason = null
216 this.videoUnblocked.emit()
219 error: err => this.notifier.error(err.message)
223 async removeVideo () {
224 this.modalOpened.emit()
226 let message = $localize`Do you really want to delete ${this.video.name}?`
227 if (this.video.isLive) {
228 message += ' ' + $localize`The live stream will be automatically terminated.`
231 const res = await this.confirmService.confirm(message, $localize`Delete ${this.video.name}`)
232 if (res === false) return
234 this.videoService.removeVideo(this.video.id)
237 this.notifier.success($localize`Video ${this.video.name} deleted.`)
238 this.videoRemoved.emit()
241 error: err => this.notifier.error(err.message)
246 this.redundancyService.addVideoRedundancy(this.video)
249 const message = $localize`${this.video.name} will be duplicated by your instance.`
250 this.notifier.success(message)
253 error: err => this.notifier.error(err.message)
257 muteVideoAccount () {
258 const params = { nameWithHost: Actor.CREATE_BY_STRING(this.video.account.name, this.video.account.host) }
260 this.blocklistService.blockAccountByUser(params)
263 this.notifier.success($localize`Account ${params.nameWithHost} muted.`)
264 this.videoAccountMuted.emit()
267 error: err => this.notifier.error(err.message)
271 async removeVideoFiles (video: Video, type: 'hls' | 'webtorrent') {
272 const confirmMessage = $localize`Do you really want to remove "${this.video.name}" files?`
274 const res = await this.confirmService.confirm(confirmMessage, $localize`Remove "${this.video.name}" files`)
275 if (res === false) return
277 this.videoService.removeVideoFiles([ video.id ], type)
280 this.notifier.success($localize`Removed files of ${video.name}.`)
281 this.videoFilesRemoved.emit()
284 error: err => this.notifier.error(err.message)
288 runTranscoding (video: Video, type: 'hls' | 'webtorrent') {
289 this.videoService.runTranscoding([ video.id ], type)
292 this.notifier.success($localize`Transcoding jobs created for ${video.name}.`)
293 this.transcodingCreated.emit()
296 error: err => this.notifier.error(err.message)
301 this.videoBlocked.emit()
304 getPlaylistDropdownPlacement () {
305 if (this.screenService.isInSmallView()) {
306 return 'bottom-right'
309 return 'bottom-left bottom-right'
312 private buildActions () {
313 this.videoActions = [
316 label: $localize`Save to playlist`,
317 handler: () => this.playlistDropdown.toggle(),
318 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist,
319 iconName: 'playlist-add'
322 [ // actions regarding the video
324 label: $localize`Download`,
325 handler: () => this.showDownloadModal(),
326 isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(),
330 label: $localize`Display live information`,
331 handler: ({ video }) => this.showLiveInfoModal(video),
332 isDisplayed: () => this.displayOptions.liveInfo && this.isVideoLiveInfoAvailable(),
336 label: $localize`Update`,
337 linkBuilder: ({ video }) => [ '/videos/update', video.uuid ],
339 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable()
342 label: $localize`Editor`,
343 linkBuilder: ({ video }) => [ '/video-editor/edit', video.uuid ],
345 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.editor && this.isVideoEditable()
348 label: $localize`Block`,
349 handler: () => this.showBlockModal(),
351 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable()
354 label: $localize`Unblock`,
355 handler: () => this.unblockVideo(),
357 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable()
360 label: $localize`Mirror`,
361 handler: () => this.duplicateVideo(),
362 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(),
363 iconName: 'cloud-download'
366 label: $localize`Delete`,
367 handler: () => this.removeVideo(),
368 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(),
372 label: $localize`Report`,
373 handler: () => this.showReportModal(),
374 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report,
380 label: $localize`Run HLS transcoding`,
381 handler: ({ video }) => this.runTranscoding(video, 'hls'),
382 isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
386 label: $localize`Run WebTorrent transcoding`,
387 handler: ({ video }) => this.runTranscoding(video, 'webtorrent'),
388 isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
392 label: $localize`Delete HLS files`,
393 handler: ({ video }) => this.removeVideoFiles(video, 'hls'),
394 isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
398 label: $localize`Delete WebTorrent files`,
399 handler: ({ video }) => this.removeVideoFiles(video, 'webtorrent'),
400 isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
404 [ // actions regarding the account/its server
406 label: $localize`Mute account`,
407 handler: () => this.muteVideoAccount(),
408 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.mute && this.isVideoAccountMutable(),