]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video-miniature.component.ts
Improve videos list client performance
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-miniature.component.ts
CommitLineData
89724816 1import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'
b1fa3eba
C
2import { User } from '../users'
3import { Video } from './video.model'
0883b324 4import { ServerService } from '@app/core'
501bc6c2 5
22a16e36
C
6export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto'
7
501bc6c2
C
8@Component({
9 selector: 'my-video-miniature',
ec8d8440 10 styleUrls: [ './video-miniature.component.scss' ],
89724816
C
11 templateUrl: './video-miniature.component.html',
12 changeDetection: ChangeDetectionStrategy.OnPush
501bc6c2 13})
22a16e36 14export class VideoMiniatureComponent implements OnInit {
df98563e
C
15 @Input() user: User
16 @Input() video: Video
22a16e36
C
17 @Input() ownerDisplayType: OwnerDisplayType = 'account'
18
89724816
C
19 isVideoBlur: boolean
20
22a16e36 21 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
501bc6c2 22
0883b324
C
23 constructor (private serverService: ServerService) { }
24
22a16e36
C
25 ngOnInit () {
26 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
27 this.ownerDisplayTypeChosen = this.ownerDisplayType
28 return
29 }
30
31 // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
32 // -> Use the account name
33 if (
34 this.video.channel.name === `${this.video.account.name}_channel` ||
35 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}$/)
36 ) {
37 this.ownerDisplayTypeChosen = 'account'
38 } else {
39 this.ownerDisplayTypeChosen = 'videoChannel'
40 }
22a16e36 41
89724816 42 this.isVideoBlur = this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
92fb909c 43 }
22a16e36
C
44
45 displayOwnerAccount () {
46 return this.ownerDisplayTypeChosen === 'account'
47 }
48
49 displayOwnerVideoChannel () {
50 return this.ownerDisplayTypeChosen === 'videoChannel'
51 }
501bc6c2 52}