]>
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' |
343d1395 | 17 | import { Video, VideoService } from '../shared-main' |
67ed6552 C |
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, | |
343d1395 | 106 | private videoService: VideoService, |
b7819090 | 107 | private cd: ChangeDetectorRef, |
e2409062 | 108 | @Inject(LOCALE_ID) private localeId: string |
435258ea | 109 | ) {} |
0883b324 | 110 | |
7399a79f | 111 | get authorAccount () { |
80dea8f4 C |
112 | return this.serverConfig.client.videos.miniature.preferAuthorDisplayName |
113 | ? this.video.account.displayName | |
114 | : this.video.byAccount | |
7399a79f | 115 | } |
116 | ||
117 | get authorChannel () { | |
80dea8f4 C |
118 | return this.serverConfig.client.videos.miniature.preferAuthorDisplayName |
119 | ? this.video.channel.displayName | |
120 | : this.video.byVideoChannel | |
7399a79f | 121 | } |
122 | ||
d1a63fc7 | 123 | get isVideoBlur () { |
ba430d75 | 124 | return this.video.isVideoNSFWForUser(this.user, this.serverConfig) |
d1a63fc7 C |
125 | } |
126 | ||
22a16e36 | 127 | ngOnInit () { |
2989628b C |
128 | this.serverConfig = this.serverService.getHTMLConfig() |
129 | this.buildVideoLink() | |
ba430d75 | 130 | |
3a0fb65c | 131 | this.setUpBy() |
22a16e36 | 132 | |
66357162 | 133 | this.channelLinkTitle = $localize`${this.video.channel.name} (channel page)` |
435258ea | 134 | |
8dfceec4 C |
135 | // We rely on mouseenter to lazy load actions |
136 | if (this.screenService.isInTouchScreen()) { | |
743f023c | 137 | this.loadActions() |
22a16e36 | 138 | } |
92fb909c | 139 | } |
22a16e36 | 140 | |
5fb2e288 | 141 | buildVideoLink () { |
0bdad52f | 142 | if (this.videoLinkType === 'internal' || !this.video.url) { |
d4a8e7a6 | 143 | this.videoRouterLink = Video.buildWatchUrl(this.video) |
0bdad52f C |
144 | return |
145 | } | |
5fb2e288 | 146 | |
0bdad52f C |
147 | if (this.videoLinkType === 'external') { |
148 | this.videoRouterLink = null | |
149 | this.videoHref = this.video.url | |
150 | this.videoTarget = '_blank' | |
5fb2e288 C |
151 | return |
152 | } | |
153 | ||
0bdad52f C |
154 | // Lazy load |
155 | this.videoRouterLink = [ '/search/lazy-load-video', { url: this.video.url } ] | |
5fb2e288 C |
156 | } |
157 | ||
22a16e36 | 158 | displayOwnerAccount () { |
733dbc53 | 159 | return this.ownerDisplayType === 'account' |
22a16e36 C |
160 | } |
161 | ||
162 | displayOwnerVideoChannel () { | |
733dbc53 | 163 | return this.ownerDisplayType === 'videoChannel' |
22a16e36 | 164 | } |
017c3dca C |
165 | |
166 | isUnlistedVideo () { | |
167 | return this.video.privacy.id === VideoPrivacy.UNLISTED | |
168 | } | |
169 | ||
170 | isPrivateVideo () { | |
171 | return this.video.privacy.id === VideoPrivacy.PRIVATE | |
172 | } | |
e2409062 C |
173 | |
174 | getStateLabel (video: Video) { | |
dedc7abb C |
175 | if (!video.state) return '' |
176 | ||
e2409062 | 177 | if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) { |
66357162 | 178 | return $localize`Published` |
e2409062 C |
179 | } |
180 | ||
181 | if (video.scheduledUpdate) { | |
182 | const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId) | |
eaa52952 | 183 | return $localize`Publication scheduled on ${updateAt}` |
e2409062 C |
184 | } |
185 | ||
221ee1ad C |
186 | if (video.state.id === VideoState.TRANSCODING_FAILED) { |
187 | return $localize`Transcoding failed` | |
188 | } | |
189 | ||
dbd9fb44 C |
190 | if (video.state.id === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE_FAILED) { |
191 | return $localize`Move to external storage failed` | |
192 | } | |
193 | ||
e2409062 | 194 | if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) { |
66357162 | 195 | return $localize`Waiting transcoding` |
e2409062 C |
196 | } |
197 | ||
198 | if (video.state.id === VideoState.TO_TRANSCODE) { | |
66357162 | 199 | return $localize`To transcode` |
e2409062 C |
200 | } |
201 | ||
202 | if (video.state.id === VideoState.TO_IMPORT) { | |
66357162 | 203 | return $localize`To import` |
e2409062 C |
204 | } |
205 | ||
c729caf6 C |
206 | if (video.state.id === VideoState.TO_EDIT) { |
207 | return $localize`To edit` | |
208 | } | |
209 | ||
e2409062 C |
210 | return '' |
211 | } | |
3a0fb65c C |
212 | |
213 | loadActions () { | |
214 | if (this.displayVideoActions) this.showActions = true | |
b7819090 C |
215 | |
216 | this.loadWatchLater() | |
3a0fb65c C |
217 | } |
218 | ||
5baee5fc RK |
219 | onVideoBlocked () { |
220 | this.videoBlocked.emit() | |
3a0fb65c C |
221 | } |
222 | ||
5baee5fc RK |
223 | onVideoUnblocked () { |
224 | this.videoUnblocked.emit() | |
3a0fb65c C |
225 | } |
226 | ||
227 | onVideoRemoved () { | |
228 | this.videoRemoved.emit() | |
229 | } | |
230 | ||
d473fd94 RK |
231 | onVideoAccountMuted () { |
232 | this.videoAccountMuted.emit() | |
233 | } | |
234 | ||
b7819090 C |
235 | isUserLoggedIn () { |
236 | return this.authService.isLoggedIn() | |
237 | } | |
238 | ||
239 | onWatchLaterClick (currentState: boolean) { | |
240 | if (currentState === true) this.removeFromWatchLater() | |
241 | else this.addToWatchLater() | |
242 | ||
243 | this.inWatchLaterPlaylist = !currentState | |
244 | } | |
245 | ||
246 | addToWatchLater () { | |
247 | const body = { videoId: this.video.id } | |
248 | ||
1378c0d3 C |
249 | this.videoPlaylistService.addVideoInPlaylist(this.watchLaterPlaylist.id, body) |
250 | .subscribe( | |
251 | res => { | |
252 | this.watchLaterPlaylist.playlistElementId = res.videoPlaylistElement.id | |
253 | } | |
254 | ) | |
b7819090 C |
255 | } |
256 | ||
257 | removeFromWatchLater () { | |
51b34a11 | 258 | this.videoPlaylistService.removeVideoFromPlaylist(this.watchLaterPlaylist.id, this.watchLaterPlaylist.playlistElementId, this.video.id) |
b7819090 C |
259 | .subscribe( |
260 | _ => { /* empty */ } | |
261 | ) | |
262 | } | |
263 | ||
264 | isWatchLaterPlaylistDisplayed () { | |
5fb2e288 | 265 | return this.displayVideoActions && this.isUserLoggedIn() && this.inWatchLaterPlaylist !== undefined |
b7819090 C |
266 | } |
267 | ||
0f7407d9 C |
268 | getClasses () { |
269 | return { | |
270 | 'display-as-row': this.displayAsRow | |
271 | } | |
272 | } | |
273 | ||
3a0fb65c | 274 | private setUpBy () { |
3fca30a7 C |
275 | if (this.displayOptions.forceChannelInBy) { |
276 | this.ownerDisplayType = 'videoChannel' | |
277 | return | |
278 | } | |
279 | ||
343d1395 | 280 | this.ownerDisplayType = this.videoService.buildDefaultOwnerDisplayType(this.video) |
3a0fb65c | 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 | ||
15beb866 | 305 | this.videoPlaylistService.runVideoExistsInPlaylistCheck(this.video.id) |
b7819090 | 306 | } |
501bc6c2 | 307 | } |