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