]>
Commit | Line | Data |
---|---|---|
5fb2e288 | 1 | import { switchMap } from 'rxjs/operators' |
b7819090 C |
2 | import { |
3 | ChangeDetectionStrategy, | |
4 | ChangeDetectorRef, | |
5 | Component, | |
6 | EventEmitter, | |
7 | Inject, | |
8 | Input, | |
9 | LOCALE_ID, | |
10 | OnInit, | |
11 | Output | |
12 | } from '@angular/core' | |
67ed6552 | 13 | import { AuthService, ScreenService, ServerService, User } from '@app/core' |
38a3ccc7 | 14 | import { HTMLServerConfig, VideoExistInPlaylist, VideoPlaylistType, VideoPrivacy, VideoState } from '@shared/models' |
37a44fc9 | 15 | import { LinkType } from '../../../types/link.type' |
06ec4bdd | 16 | import { ActorAvatarSize } from '../shared-actor-image/actor-avatar.component' |
67ed6552 C |
17 | import { Video } from '../shared-main' |
18 | import { VideoPlaylistService } from '../shared-video-playlist' | |
19 | import { VideoActionsDisplayType } from './video-actions-dropdown.component' | |
501bc6c2 | 20 | |
e2409062 C |
21 | export type MiniatureDisplayOptions = { |
22 | date?: boolean | |
23 | views?: boolean | |
c2caa99b | 24 | avatar?: boolean |
e2409062 C |
25 | privacyLabel?: boolean |
26 | privacyText?: boolean | |
27 | state?: boolean | |
28 | blacklistInfo?: boolean | |
29 | nsfw?: boolean | |
3fca30a7 C |
30 | |
31 | by?: boolean | |
32 | forceChannelInBy?: boolean | |
e2409062 | 33 | } |
501bc6c2 C |
34 | @Component({ |
35 | selector: 'my-video-miniature', | |
ec8d8440 | 36 | styleUrls: [ './video-miniature.component.scss' ], |
89724816 C |
37 | templateUrl: './video-miniature.component.html', |
38 | changeDetection: ChangeDetectionStrategy.OnPush | |
501bc6c2 | 39 | }) |
22a16e36 | 40 | export class VideoMiniatureComponent implements OnInit { |
df98563e C |
41 | @Input() user: User |
42 | @Input() video: Video | |
38a3ccc7 | 43 | @Input() containedInPlaylists: VideoExistInPlaylist[] |
e2409062 | 44 | |
e2409062 C |
45 | @Input() displayOptions: MiniatureDisplayOptions = { |
46 | date: true, | |
47 | views: true, | |
48 | by: true, | |
c2caa99b | 49 | avatar: false, |
e2409062 C |
50 | privacyLabel: false, |
51 | privacyText: false, | |
52 | state: false, | |
3fca30a7 C |
53 | blacklistInfo: false, |
54 | forceChannelInBy: false | |
e2409062 | 55 | } |
384ba8b7 | 56 | |
3a0fb65c | 57 | @Input() displayVideoActions = true |
384ba8b7 C |
58 | @Input() videoActionsDisplayOptions: VideoActionsDisplayType = { |
59 | playlist: true, | |
60 | download: false, | |
61 | update: true, | |
62 | blacklist: true, | |
63 | delete: true, | |
64 | report: true, | |
65 | duplicate: true, | |
66 | mute: true, | |
67 | studio: false, | |
68 | stats: false | |
69 | } | |
0f7407d9 | 70 | |
06ec4bdd C |
71 | @Input() actorImageSize: ActorAvatarSize = '40' |
72 | ||
0f7407d9 | 73 | @Input() displayAsRow = false |
3a0fb65c | 74 | |
37a44fc9 | 75 | @Input() videoLinkType: LinkType = 'internal' |
5fb2e288 | 76 | |
5baee5fc RK |
77 | @Output() videoBlocked = new EventEmitter() |
78 | @Output() videoUnblocked = new EventEmitter() | |
3a0fb65c | 79 | @Output() videoRemoved = new EventEmitter() |
d473fd94 | 80 | @Output() videoAccountMuted = new EventEmitter() |
3a0fb65c | 81 | |
3a0fb65c | 82 | showActions = false |
2989628b | 83 | serverConfig: HTMLServerConfig |
22a16e36 | 84 | |
b7819090 C |
85 | addToWatchLaterText: string |
86 | addedToWatchLaterText: string | |
87 | inWatchLaterPlaylist: boolean | |
435258ea | 88 | channelLinkTitle = '' |
b7819090 C |
89 | |
90 | watchLaterPlaylist: { | |
91 | id: number | |
92 | playlistElementId?: number | |
93 | } | |
94 | ||
d4a8e7a6 | 95 | videoRouterLink: string | any[] = [] |
0bdad52f C |
96 | videoHref: string |
97 | videoTarget: string | |
5fb2e288 | 98 | |
733dbc53 | 99 | private ownerDisplayType: 'account' | 'videoChannel' |
501bc6c2 | 100 | |
e2409062 | 101 | constructor ( |
3a0fb65c | 102 | private screenService: ScreenService, |
e2409062 | 103 | private serverService: ServerService, |
b7819090 C |
104 | private authService: AuthService, |
105 | private videoPlaylistService: VideoPlaylistService, | |
106 | private cd: ChangeDetectorRef, | |
e2409062 | 107 | @Inject(LOCALE_ID) private localeId: string |
435258ea | 108 | ) {} |
0883b324 | 109 | |
7399a79f | 110 | get authorAccount () { |
80dea8f4 C |
111 | return this.serverConfig.client.videos.miniature.preferAuthorDisplayName |
112 | ? this.video.account.displayName | |
113 | : this.video.byAccount | |
7399a79f | 114 | } |
115 | ||
116 | get authorChannel () { | |
80dea8f4 C |
117 | return this.serverConfig.client.videos.miniature.preferAuthorDisplayName |
118 | ? this.video.channel.displayName | |
119 | : this.video.byVideoChannel | |
7399a79f | 120 | } |
121 | ||
d1a63fc7 | 122 | get isVideoBlur () { |
ba430d75 | 123 | return this.video.isVideoNSFWForUser(this.user, this.serverConfig) |
d1a63fc7 C |
124 | } |
125 | ||
22a16e36 | 126 | ngOnInit () { |
2989628b C |
127 | this.serverConfig = this.serverService.getHTMLConfig() |
128 | this.buildVideoLink() | |
ba430d75 | 129 | |
3a0fb65c | 130 | this.setUpBy() |
22a16e36 | 131 | |
66357162 | 132 | this.channelLinkTitle = $localize`${this.video.channel.name} (channel page)` |
435258ea | 133 | |
8dfceec4 C |
134 | // We rely on mouseenter to lazy load actions |
135 | if (this.screenService.isInTouchScreen()) { | |
743f023c | 136 | this.loadActions() |
22a16e36 | 137 | } |
92fb909c | 138 | } |
22a16e36 | 139 | |
5fb2e288 | 140 | buildVideoLink () { |
0bdad52f | 141 | if (this.videoLinkType === 'internal' || !this.video.url) { |
d4a8e7a6 | 142 | this.videoRouterLink = Video.buildWatchUrl(this.video) |
0bdad52f C |
143 | return |
144 | } | |
5fb2e288 | 145 | |
0bdad52f C |
146 | if (this.videoLinkType === 'external') { |
147 | this.videoRouterLink = null | |
148 | this.videoHref = this.video.url | |
149 | this.videoTarget = '_blank' | |
5fb2e288 C |
150 | return |
151 | } | |
152 | ||
0bdad52f C |
153 | // Lazy load |
154 | this.videoRouterLink = [ '/search/lazy-load-video', { url: this.video.url } ] | |
5fb2e288 C |
155 | } |
156 | ||
22a16e36 | 157 | displayOwnerAccount () { |
733dbc53 | 158 | return this.ownerDisplayType === 'account' |
22a16e36 C |
159 | } |
160 | ||
161 | displayOwnerVideoChannel () { | |
733dbc53 | 162 | return this.ownerDisplayType === 'videoChannel' |
22a16e36 | 163 | } |
017c3dca C |
164 | |
165 | isUnlistedVideo () { | |
166 | return this.video.privacy.id === VideoPrivacy.UNLISTED | |
167 | } | |
168 | ||
169 | isPrivateVideo () { | |
170 | return this.video.privacy.id === VideoPrivacy.PRIVATE | |
171 | } | |
e2409062 C |
172 | |
173 | getStateLabel (video: Video) { | |
dedc7abb C |
174 | if (!video.state) return '' |
175 | ||
e2409062 | 176 | if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) { |
66357162 | 177 | return $localize`Published` |
e2409062 C |
178 | } |
179 | ||
180 | if (video.scheduledUpdate) { | |
181 | const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId) | |
eaa52952 | 182 | return $localize`Publication scheduled on ${updateAt}` |
e2409062 C |
183 | } |
184 | ||
221ee1ad C |
185 | if (video.state.id === VideoState.TRANSCODING_FAILED) { |
186 | return $localize`Transcoding failed` | |
187 | } | |
188 | ||
dbd9fb44 C |
189 | if (video.state.id === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE_FAILED) { |
190 | return $localize`Move to external storage failed` | |
191 | } | |
192 | ||
e2409062 | 193 | if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) { |
66357162 | 194 | return $localize`Waiting transcoding` |
e2409062 C |
195 | } |
196 | ||
197 | if (video.state.id === VideoState.TO_TRANSCODE) { | |
66357162 | 198 | return $localize`To transcode` |
e2409062 C |
199 | } |
200 | ||
201 | if (video.state.id === VideoState.TO_IMPORT) { | |
66357162 | 202 | return $localize`To import` |
e2409062 C |
203 | } |
204 | ||
c729caf6 C |
205 | if (video.state.id === VideoState.TO_EDIT) { |
206 | return $localize`To edit` | |
207 | } | |
208 | ||
e2409062 C |
209 | return '' |
210 | } | |
3a0fb65c C |
211 | |
212 | loadActions () { | |
213 | if (this.displayVideoActions) this.showActions = true | |
b7819090 C |
214 | |
215 | this.loadWatchLater() | |
3a0fb65c C |
216 | } |
217 | ||
5baee5fc RK |
218 | onVideoBlocked () { |
219 | this.videoBlocked.emit() | |
3a0fb65c C |
220 | } |
221 | ||
5baee5fc RK |
222 | onVideoUnblocked () { |
223 | this.videoUnblocked.emit() | |
3a0fb65c C |
224 | } |
225 | ||
226 | onVideoRemoved () { | |
227 | this.videoRemoved.emit() | |
228 | } | |
229 | ||
d473fd94 RK |
230 | onVideoAccountMuted () { |
231 | this.videoAccountMuted.emit() | |
232 | } | |
233 | ||
b7819090 C |
234 | isUserLoggedIn () { |
235 | return this.authService.isLoggedIn() | |
236 | } | |
237 | ||
238 | onWatchLaterClick (currentState: boolean) { | |
239 | if (currentState === true) this.removeFromWatchLater() | |
240 | else this.addToWatchLater() | |
241 | ||
242 | this.inWatchLaterPlaylist = !currentState | |
243 | } | |
244 | ||
245 | addToWatchLater () { | |
246 | const body = { videoId: this.video.id } | |
247 | ||
1378c0d3 C |
248 | this.videoPlaylistService.addVideoInPlaylist(this.watchLaterPlaylist.id, body) |
249 | .subscribe( | |
250 | res => { | |
251 | this.watchLaterPlaylist.playlistElementId = res.videoPlaylistElement.id | |
252 | } | |
253 | ) | |
b7819090 C |
254 | } |
255 | ||
256 | removeFromWatchLater () { | |
51b34a11 | 257 | this.videoPlaylistService.removeVideoFromPlaylist(this.watchLaterPlaylist.id, this.watchLaterPlaylist.playlistElementId, this.video.id) |
b7819090 C |
258 | .subscribe( |
259 | _ => { /* empty */ } | |
260 | ) | |
261 | } | |
262 | ||
263 | isWatchLaterPlaylistDisplayed () { | |
5fb2e288 | 264 | return this.displayVideoActions && this.isUserLoggedIn() && this.inWatchLaterPlaylist !== undefined |
b7819090 C |
265 | } |
266 | ||
0f7407d9 C |
267 | getClasses () { |
268 | return { | |
269 | 'display-as-row': this.displayAsRow | |
270 | } | |
271 | } | |
272 | ||
3a0fb65c | 273 | private setUpBy () { |
3fca30a7 C |
274 | if (this.displayOptions.forceChannelInBy) { |
275 | this.ownerDisplayType = 'videoChannel' | |
276 | return | |
277 | } | |
278 | ||
733dbc53 | 279 | const accountName = this.video.account.name |
3a0fb65c | 280 | |
deb8b9cd | 281 | // If the video channel name is an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12) |
733dbc53 | 282 | // Or has not been customized (default created channel display name) |
3a0fb65c C |
283 | // -> Use the account name |
284 | if ( | |
733dbc53 C |
285 | this.video.channel.displayName === `Default ${accountName} channel` || |
286 | this.video.channel.displayName === `Main ${accountName} channel` || | |
3a0fb65c C |
287 | this.video.channel.name.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/) |
288 | ) { | |
733dbc53 | 289 | this.ownerDisplayType = 'account' |
3a0fb65c | 290 | } else { |
733dbc53 | 291 | this.ownerDisplayType = 'videoChannel' |
3a0fb65c C |
292 | } |
293 | } | |
b7819090 C |
294 | |
295 | private loadWatchLater () { | |
51b34a11 C |
296 | if (!this.isUserLoggedIn() || this.inWatchLaterPlaylist !== undefined) return |
297 | ||
298 | this.authService.userInformationLoaded | |
299 | .pipe(switchMap(() => this.videoPlaylistService.listenToVideoPlaylistChange(this.video.id))) | |
300 | .subscribe(existResult => { | |
301 | const watchLaterPlaylist = this.authService.getUser().specialPlaylists.find(p => p.type === VideoPlaylistType.WATCH_LATER) | |
302 | const existsInWatchLater = existResult.find(r => r.playlistId === watchLaterPlaylist.id) | |
303 | this.inWatchLaterPlaylist = false | |
304 | ||
305 | this.watchLaterPlaylist = { | |
306 | id: watchLaterPlaylist.id | |
307 | } | |
308 | ||
309 | if (existsInWatchLater) { | |
310 | this.inWatchLaterPlaylist = true | |
311 | this.watchLaterPlaylist.playlistElementId = existsInWatchLater.playlistElementId | |
312 | } | |
313 | ||
314 | this.cd.markForCheck() | |
315 | }) | |
316 | ||
15beb866 | 317 | this.videoPlaylistService.runVideoExistsInPlaylistCheck(this.video.id) |
b7819090 | 318 | } |
501bc6c2 | 319 | } |