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