4 VideoDetails as VideoDetailsServerModel,
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'
13 export class VideoDetails extends Video implements VideoDetailsServerModel {
14 privacy: VideoConstant<VideoPrivacy>
15 descriptionPath: string
21 commentsEnabled: boolean
24 dislikesPercent: number
26 constructor (hash: VideoDetailsServerModel) {
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
35 this.support = hash.support
36 this.commentsEnabled = hash.commentsEnabled
38 this.buildLikeAndDislikePercents()
41 isRemovableBy (user: AuthUser) {
42 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
45 isBlackistableBy (user: AuthUser) {
46 return user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true && this.isLocal === false
49 isUpdatableBy (user: AuthUser) {
50 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
53 buildLikeAndDislikePercents () {
54 this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100
55 this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100