1 import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'
2 import { AuthService, ConfirmService, Notifier, ScreenService } 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 = {
33 selector: 'my-video-actions-dropdown',
34 templateUrl: './video-actions-dropdown.component.html',
35 styleUrls: [ './video-actions-dropdown.component.scss' ]
37 export class VideoActionsDropdownComponent implements OnChanges {
38 @ViewChild('playlistDropdown') playlistDropdown: NgbDropdown
39 @ViewChild('playlistAdd') playlistAdd: VideoAddToPlaylistComponent
41 @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
42 @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
43 @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
44 @ViewChild('liveStreamInformationModal') liveStreamInformationModal: LiveStreamInformationComponent
46 @Input() video: Video | VideoDetails
47 @Input() videoCaptions: VideoCaption[] = []
49 @Input() displayOptions: VideoActionsDisplayType = {
60 @Input() placement = 'left'
62 @Input() label: string
64 @Input() buttonStyled = false
65 @Input() buttonSize: DropdownButtonSize = 'normal'
66 @Input() buttonDirection: DropdownDirection = 'vertical'
68 @Output() videoRemoved = new EventEmitter()
69 @Output() videoUnblocked = new EventEmitter()
70 @Output() videoBlocked = new EventEmitter()
71 @Output() videoAccountMuted = new EventEmitter()
72 @Output() modalOpened = new EventEmitter()
74 videoActions: DropdownAction<{ video: Video }>[][] = []
76 private loaded = false
79 private authService: AuthService,
80 private notifier: Notifier,
81 private confirmService: ConfirmService,
82 private blocklistService: BlocklistService,
83 private videoBlocklistService: VideoBlockService,
84 private screenService: ScreenService,
85 private videoService: VideoService,
86 private redundancyService: RedundancyService
90 return this.authService.getUser()
96 if (this.playlistAdd) this.playlistAdd.reload()
103 return this.authService.isLoggedIn()
106 loadDropdownInformation () {
107 if (!this.isUserLoggedIn() || this.loaded === true) return
111 if (this.displayOptions.playlist) this.playlistAdd.load()
116 showDownloadModal () {
117 this.modalOpened.emit()
119 this.videoDownloadModal.show(this.video as VideoDetails, this.videoCaptions)
123 this.modalOpened.emit()
125 this.videoReportModal.show()
129 this.modalOpened.emit()
131 this.videoBlockModal.show()
134 showLiveInfoModal (video: Video) {
135 this.modalOpened.emit()
137 this.liveStreamInformationModal.show(video)
140 /* Actions checker */
142 isVideoUpdatable () {
143 return this.video.isUpdatableBy(this.user)
146 isVideoRemovable () {
147 return this.video.isRemovableBy(this.user)
150 isVideoBlockable () {
151 return this.video.isBlockableBy(this.user)
154 isVideoUnblockable () {
155 return this.video.isUnblockableBy(this.user)
158 isVideoLiveInfoAvailable () {
159 return this.video.isLiveInfoAvailableBy(this.user)
162 isVideoDownloadable () {
164 this.video.isLive !== true &&
165 this.video instanceof VideoDetails &&
166 this.video.downloadEnabled
169 canVideoBeDuplicated () {
170 return this.video.canBeDuplicatedBy(this.user)
173 isVideoAccountMutable () {
174 return this.video.account.id !== this.user.account.id
177 /* Action handlers */
179 async unblockVideo () {
180 const confirmMessage = $localize`Do you really want to unblock this video? It will be available again in the videos list.`
182 const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`)
183 if (res === false) return
185 this.videoBlocklistService.unblockVideo(this.video.id)
188 this.notifier.success($localize`Video ${this.video.name} unblocked.`)
190 this.video.blacklisted = false
191 this.video.blockedReason = null
193 this.videoUnblocked.emit()
196 err => this.notifier.error(err.message)
200 async removeVideo () {
201 this.modalOpened.emit()
203 let message = $localize`Do you really want to delete this video?`
204 if (this.video.isLive) {
205 message += ' ' + $localize`The live stream will be automatically terminated.`
208 const res = await this.confirmService.confirm(message, $localize`Delete`)
209 if (res === false) return
211 this.videoService.removeVideo(this.video.id)
214 this.notifier.success($localize`Video ${this.video.name} deleted.`)
215 this.videoRemoved.emit()
218 error => this.notifier.error(error.message)
223 this.redundancyService.addVideoRedundancy(this.video)
226 const message = $localize`This video will be duplicated by your instance.`
227 this.notifier.success(message)
230 err => this.notifier.error(err.message)
234 muteVideoAccount () {
235 const params = { nameWithHost: Actor.CREATE_BY_STRING(this.video.account.name, this.video.account.host) }
237 this.blocklistService.blockAccountByUser(params)
240 this.notifier.success($localize`Account ${params.nameWithHost} muted.`)
241 this.videoAccountMuted.emit()
244 err => this.notifier.error(err.message)
249 this.videoBlocked.emit()
252 getPlaylistDropdownPlacement () {
253 if (this.screenService.isInSmallView()) {
254 return 'bottom-right'
257 return 'bottom-left bottom-right'
260 private buildActions () {
261 this.videoActions = [
264 label: $localize`Save to playlist`,
265 handler: () => this.playlistDropdown.toggle(),
266 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist,
267 iconName: 'playlist-add'
270 [ // actions regarding the video
272 label: $localize`Download`,
273 handler: () => this.showDownloadModal(),
274 isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(),
278 label: $localize`Display live information`,
279 handler: ({ video }) => this.showLiveInfoModal(video),
280 isDisplayed: () => this.displayOptions.liveInfo && this.isVideoLiveInfoAvailable(),
284 label: $localize`Update`,
285 linkBuilder: ({ video }) => [ '/videos/update', video.uuid ],
287 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable()
290 label: $localize`Block`,
291 handler: () => this.showBlockModal(),
293 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable()
296 label: $localize`Unblock`,
297 handler: () => this.unblockVideo(),
299 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable()
302 label: $localize`Mirror`,
303 handler: () => this.duplicateVideo(),
304 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(),
305 iconName: 'cloud-download'
308 label: $localize`Delete`,
309 handler: () => this.removeVideo(),
310 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(),
314 label: $localize`Report`,
315 handler: () => this.showReportModal(),
316 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report,
320 [ // actions regarding the account/its server
322 label: $localize`Mute account`,
323 handler: () => this.muteVideoAccount(),
324 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.mute && this.isVideoAccountMutable(),