]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video-details.model.ts
a1f7207a28149febeed5a569435dcf97da8a48a6
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-details.model.ts
1 import {
2 UserRight,
3 VideoChannel,
4 VideoDetails as VideoDetailsServerModel,
5 VideoFile,
6 VideoPrivacy
7 } from '../../../../../shared'
8 import { Account } from '../../../../../shared/models/actors'
9 import { VideoConstant } from '../../../../../shared/models/videos/video.model'
10 import { AuthUser } from '../../core'
11 import { Video } from '../../shared/video/video.model'
12
13 export class VideoDetails extends Video implements VideoDetailsServerModel {
14 privacy: VideoConstant<VideoPrivacy>
15 descriptionPath: string
16 support: string
17 channel: VideoChannel
18 tags: string[]
19 files: VideoFile[]
20 account: Account
21 commentsEnabled: boolean
22
23 likesPercent: number
24 dislikesPercent: number
25
26 constructor (hash: VideoDetailsServerModel) {
27 super(hash)
28
29 this.privacy = hash.privacy
30 this.descriptionPath = hash.descriptionPath
31 this.files = hash.files
32 this.channel = hash.channel
33 this.account = hash.account
34 this.tags = hash.tags
35 this.support = hash.support
36 this.commentsEnabled = hash.commentsEnabled
37
38 this.buildLikeAndDislikePercents()
39 }
40
41 isRemovableBy (user: AuthUser) {
42 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
43 }
44
45 isBlackistableBy (user: AuthUser) {
46 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
47 }
48
49 isUpdatableBy (user: AuthUser) {
50 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
51 }
52
53 buildLikeAndDislikePercents () {
54 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
55 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100
56 }
57 }