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