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