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