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