]>
Commit | Line | Data |
---|---|---|
b7819090 C |
1 | import { |
2 | ChangeDetectionStrategy, | |
3 | ChangeDetectorRef, | |
4 | Component, | |
5 | EventEmitter, | |
6 | Inject, | |
7 | Input, | |
8 | LOCALE_ID, | |
9 | OnInit, | |
10 | Output | |
11 | } from '@angular/core' | |
b1fa3eba C |
12 | import { User } from '../users' |
13 | import { Video } from './video.model' | |
b7819090 C |
14 | import { AuthService, ServerService } from '@app/core' |
15 | import { ServerConfig, VideoPlaylistType, VideoPrivacy, VideoState } from '../../../../../shared' | |
e2409062 | 16 | import { I18n } from '@ngx-translate/i18n-polyfill' |
3a0fb65c C |
17 | import { VideoActionsDisplayType } from '@app/shared/video/video-actions-dropdown.component' |
18 | import { ScreenService } from '@app/shared/misc/screen.service' | |
b7819090 | 19 | import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' |
51b34a11 | 20 | import { switchMap } from 'rxjs/operators' |
501bc6c2 | 21 | |
22a16e36 | 22 | export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto' |
e2409062 C |
23 | export type MiniatureDisplayOptions = { |
24 | date?: boolean | |
25 | views?: boolean | |
26 | by?: boolean | |
c2caa99b | 27 | avatar?: boolean |
e2409062 C |
28 | privacyLabel?: boolean |
29 | privacyText?: boolean | |
30 | state?: boolean | |
31 | blacklistInfo?: boolean | |
32 | nsfw?: boolean | |
33 | } | |
22a16e36 | 34 | |
501bc6c2 C |
35 | @Component({ |
36 | selector: 'my-video-miniature', | |
ec8d8440 | 37 | styleUrls: [ './video-miniature.component.scss' ], |
89724816 C |
38 | templateUrl: './video-miniature.component.html', |
39 | changeDetection: ChangeDetectionStrategy.OnPush | |
501bc6c2 | 40 | }) |
22a16e36 | 41 | export class VideoMiniatureComponent implements OnInit { |
df98563e C |
42 | @Input() user: User |
43 | @Input() video: Video | |
e2409062 | 44 | |
22a16e36 | 45 | @Input() ownerDisplayType: OwnerDisplayType = 'account' |
e2409062 C |
46 | @Input() displayOptions: MiniatureDisplayOptions = { |
47 | date: true, | |
48 | views: true, | |
49 | by: true, | |
c2caa99b | 50 | avatar: false, |
e2409062 C |
51 | privacyLabel: false, |
52 | privacyText: false, | |
53 | state: false, | |
54 | blacklistInfo: false | |
55 | } | |
56 | @Input() displayAsRow = false | |
3a0fb65c | 57 | @Input() displayVideoActions = true |
e66883b3 | 58 | @Input() fitWidth = false |
3a0fb65c C |
59 | |
60 | @Output() videoBlacklisted = new EventEmitter() | |
61 | @Output() videoUnblacklisted = new EventEmitter() | |
62 | @Output() videoRemoved = new EventEmitter() | |
63 | ||
64 | videoActionsDisplayOptions: VideoActionsDisplayType = { | |
65 | playlist: true, | |
66 | download: false, | |
67 | update: true, | |
68 | blacklist: true, | |
69 | delete: true, | |
b764380a | 70 | report: true, |
988af781 | 71 | duplicate: true |
3a0fb65c C |
72 | } |
73 | showActions = false | |
ba430d75 | 74 | serverConfig: ServerConfig |
22a16e36 | 75 | |
b7819090 C |
76 | addToWatchLaterText: string |
77 | addedToWatchLaterText: string | |
78 | inWatchLaterPlaylist: boolean | |
79 | ||
80 | watchLaterPlaylist: { | |
81 | id: number | |
82 | playlistElementId?: number | |
83 | } | |
84 | ||
22a16e36 | 85 | private ownerDisplayTypeChosen: 'account' | 'videoChannel' |
501bc6c2 | 86 | |
e2409062 | 87 | constructor ( |
3a0fb65c | 88 | private screenService: ScreenService, |
e2409062 C |
89 | private serverService: ServerService, |
90 | private i18n: I18n, | |
b7819090 C |
91 | private authService: AuthService, |
92 | private videoPlaylistService: VideoPlaylistService, | |
93 | private cd: ChangeDetectorRef, | |
e2409062 | 94 | @Inject(LOCALE_ID) private localeId: string |
b7819090 C |
95 | ) { |
96 | ||
97 | } | |
0883b324 | 98 | |
d1a63fc7 | 99 | get isVideoBlur () { |
ba430d75 | 100 | return this.video.isVideoNSFWForUser(this.user, this.serverConfig) |
d1a63fc7 C |
101 | } |
102 | ||
22a16e36 | 103 | ngOnInit () { |
ba430d75 C |
104 | this.serverConfig = this.serverService.getTmpConfig() |
105 | this.serverService.getConfig() | |
106 | .subscribe(config => this.serverConfig = config) | |
107 | ||
3a0fb65c | 108 | this.setUpBy() |
22a16e36 | 109 | |
8dfceec4 C |
110 | // We rely on mouseenter to lazy load actions |
111 | if (this.screenService.isInTouchScreen()) { | |
743f023c | 112 | this.loadActions() |
22a16e36 | 113 | } |
92fb909c | 114 | } |
22a16e36 C |
115 | |
116 | displayOwnerAccount () { | |
117 | return this.ownerDisplayTypeChosen === 'account' | |
118 | } | |
119 | ||
120 | displayOwnerVideoChannel () { | |
121 | return this.ownerDisplayTypeChosen === 'videoChannel' | |
122 | } | |
017c3dca C |
123 | |
124 | isUnlistedVideo () { | |
125 | return this.video.privacy.id === VideoPrivacy.UNLISTED | |
126 | } | |
127 | ||
128 | isPrivateVideo () { | |
129 | return this.video.privacy.id === VideoPrivacy.PRIVATE | |
130 | } | |
e2409062 C |
131 | |
132 | getStateLabel (video: Video) { | |
dedc7abb C |
133 | if (!video.state) return '' |
134 | ||
e2409062 C |
135 | if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) { |
136 | return this.i18n('Published') | |
137 | } | |
138 | ||
139 | if (video.scheduledUpdate) { | |
140 | const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId) | |
141 | return this.i18n('Publication scheduled on ') + updateAt | |
142 | } | |
143 | ||
144 | if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) { | |
145 | return this.i18n('Waiting transcoding') | |
146 | } | |
147 | ||
148 | if (video.state.id === VideoState.TO_TRANSCODE) { | |
149 | return this.i18n('To transcode') | |
150 | } | |
151 | ||
152 | if (video.state.id === VideoState.TO_IMPORT) { | |
153 | return this.i18n('To import') | |
154 | } | |
155 | ||
156 | return '' | |
157 | } | |
3a0fb65c C |
158 | |
159 | loadActions () { | |
160 | if (this.displayVideoActions) this.showActions = true | |
b7819090 C |
161 | |
162 | this.loadWatchLater() | |
3a0fb65c C |
163 | } |
164 | ||
165 | onVideoBlacklisted () { | |
166 | this.videoBlacklisted.emit() | |
167 | } | |
168 | ||
169 | onVideoUnblacklisted () { | |
170 | this.videoUnblacklisted.emit() | |
171 | } | |
172 | ||
173 | onVideoRemoved () { | |
174 | this.videoRemoved.emit() | |
175 | } | |
176 | ||
b7819090 C |
177 | isUserLoggedIn () { |
178 | return this.authService.isLoggedIn() | |
179 | } | |
180 | ||
181 | onWatchLaterClick (currentState: boolean) { | |
182 | if (currentState === true) this.removeFromWatchLater() | |
183 | else this.addToWatchLater() | |
184 | ||
185 | this.inWatchLaterPlaylist = !currentState | |
186 | } | |
187 | ||
188 | addToWatchLater () { | |
189 | const body = { videoId: this.video.id } | |
190 | ||
191 | this.videoPlaylistService.addVideoInPlaylist(this.watchLaterPlaylist.id, body).subscribe( | |
192 | res => { | |
193 | this.watchLaterPlaylist.playlistElementId = res.videoPlaylistElement.id | |
194 | } | |
195 | ) | |
196 | } | |
197 | ||
198 | removeFromWatchLater () { | |
51b34a11 | 199 | this.videoPlaylistService.removeVideoFromPlaylist(this.watchLaterPlaylist.id, this.watchLaterPlaylist.playlistElementId, this.video.id) |
b7819090 C |
200 | .subscribe( |
201 | _ => { /* empty */ } | |
202 | ) | |
203 | } | |
204 | ||
205 | isWatchLaterPlaylistDisplayed () { | |
80adb036 | 206 | return this.isUserLoggedIn() && this.inWatchLaterPlaylist !== undefined |
b7819090 C |
207 | } |
208 | ||
3a0fb65c C |
209 | private setUpBy () { |
210 | if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') { | |
211 | this.ownerDisplayTypeChosen = this.ownerDisplayType | |
212 | return | |
213 | } | |
214 | ||
215 | // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12) | |
216 | // -> Use the account name | |
217 | if ( | |
218 | this.video.channel.name === `${this.video.account.name}_channel` || | |
219 | 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}$/) | |
220 | ) { | |
221 | this.ownerDisplayTypeChosen = 'account' | |
222 | } else { | |
223 | this.ownerDisplayTypeChosen = 'videoChannel' | |
224 | } | |
225 | } | |
b7819090 C |
226 | |
227 | private loadWatchLater () { | |
51b34a11 C |
228 | if (!this.isUserLoggedIn() || this.inWatchLaterPlaylist !== undefined) return |
229 | ||
230 | this.authService.userInformationLoaded | |
231 | .pipe(switchMap(() => this.videoPlaylistService.listenToVideoPlaylistChange(this.video.id))) | |
232 | .subscribe(existResult => { | |
233 | const watchLaterPlaylist = this.authService.getUser().specialPlaylists.find(p => p.type === VideoPlaylistType.WATCH_LATER) | |
234 | const existsInWatchLater = existResult.find(r => r.playlistId === watchLaterPlaylist.id) | |
235 | this.inWatchLaterPlaylist = false | |
236 | ||
237 | this.watchLaterPlaylist = { | |
238 | id: watchLaterPlaylist.id | |
239 | } | |
240 | ||
241 | if (existsInWatchLater) { | |
242 | this.inWatchLaterPlaylist = true | |
243 | this.watchLaterPlaylist.playlistElementId = existsInWatchLater.playlistElementId | |
244 | } | |
245 | ||
246 | this.cd.markForCheck() | |
247 | }) | |
248 | ||
249 | this.videoPlaylistService.runPlaylistCheck(this.video.id) | |
b7819090 | 250 | } |
501bc6c2 | 251 | } |