]>
Commit | Line | Data |
---|---|---|
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 | import { VideoPrivacy } from '../../../../../shared' | |
6 | ||
7 | export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto' | |
8 | ||
9 | @Component({ | |
10 | selector: 'my-video-miniature', | |
11 | styleUrls: [ './video-miniature.component.scss' ], | |
12 | templateUrl: './video-miniature.component.html', | |
13 | changeDetection: ChangeDetectionStrategy.OnPush | |
14 | }) | |
15 | export class VideoMiniatureComponent implements OnInit { | |
16 | @Input() user: User | |
17 | @Input() video: Video | |
18 | @Input() ownerDisplayType: OwnerDisplayType = 'account' | |
19 | ||
20 | private ownerDisplayTypeChosen: 'account' | 'videoChannel' | |
21 | ||
22 | constructor (private serverService: ServerService) { } | |
23 | ||
24 | get isVideoBlur () { | |
25 | return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig()) | |
26 | } | |
27 | ||
28 | ngOnInit () { | |
29 | if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') { | |
30 | this.ownerDisplayTypeChosen = this.ownerDisplayType | |
31 | return | |
32 | } | |
33 | ||
34 | // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12) | |
35 | // -> Use the account name | |
36 | if ( | |
37 | this.video.channel.name === `${this.video.account.name}_channel` || | |
38 | 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}$/) | |
39 | ) { | |
40 | this.ownerDisplayTypeChosen = 'account' | |
41 | } else { | |
42 | this.ownerDisplayTypeChosen = 'videoChannel' | |
43 | } | |
44 | } | |
45 | ||
46 | displayOwnerAccount () { | |
47 | return this.ownerDisplayTypeChosen === 'account' | |
48 | } | |
49 | ||
50 | displayOwnerVideoChannel () { | |
51 | return this.ownerDisplayTypeChosen === 'videoChannel' | |
52 | } | |
53 | ||
54 | isUnlistedVideo () { | |
55 | return this.video.privacy.id === VideoPrivacy.UNLISTED | |
56 | } | |
57 | ||
58 | isPrivateVideo () { | |
59 | return this.video.privacy.id === VideoPrivacy.PRIVATE | |
60 | } | |
61 | } |