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