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