]>
Commit | Line | Data |
---|---|---|
22a16e36 | 1 | import { UserRight, VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared' |
47564bbe C |
2 | import { AuthUser } from '../../core' |
3 | import { Video } from '../../shared/video/video.model' | |
ad9e39fb | 4 | import { Account } from '@app/shared/account/account.model' |
22a16e36 | 5 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' |
404b54e1 C |
6 | |
7 | export class VideoDetails extends Video implements VideoDetailsServerModel { | |
09700934 | 8 | descriptionPath: string |
2422c46b | 9 | support: string |
09700934 | 10 | channel: VideoChannel |
404b54e1 | 11 | tags: string[] |
404b54e1 | 12 | files: VideoFile[] |
b1fa3eba | 13 | account: Account |
09700934 C |
14 | commentsEnabled: boolean |
15 | ||
2186386c C |
16 | waitTranscoding: boolean |
17 | state: VideoConstant<VideoState> | |
18 | ||
6a9e1d42 C |
19 | likesPercent: number |
20 | dislikesPercent: number | |
404b54e1 | 21 | |
7ce44a74 C |
22 | constructor (hash: VideoDetailsServerModel, translations = {}) { |
23 | super(hash, translations) | |
404b54e1 | 24 | |
2de96f4d | 25 | this.descriptionPath = hash.descriptionPath |
404b54e1 | 26 | this.files = hash.files |
22a16e36 | 27 | this.channel = new VideoChannel(hash.channel) |
ad9e39fb | 28 | this.account = new Account(hash.account) |
d48ff09d | 29 | this.tags = hash.tags |
07fa4c97 | 30 | this.support = hash.support |
47564bbe | 31 | this.commentsEnabled = hash.commentsEnabled |
6a9e1d42 | 32 | |
20b40b19 | 33 | this.buildLikeAndDislikePercents() |
404b54e1 C |
34 | } |
35 | ||
954605a8 | 36 | isRemovableBy (user: AuthUser) { |
09700934 | 37 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) |
404b54e1 C |
38 | } |
39 | ||
954605a8 | 40 | isBlackistableBy (user: AuthUser) { |
191764f3 C |
41 | return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true |
42 | } | |
43 | ||
44 | isUnblacklistableBy (user: AuthUser) { | |
45 | return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true | |
404b54e1 C |
46 | } |
47 | ||
954605a8 | 48 | isUpdatableBy (user: AuthUser) { |
09700934 | 49 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) |
404b54e1 | 50 | } |
20b40b19 C |
51 | |
52 | buildLikeAndDislikePercents () { | |
53 | this.likesPercent = (this.likes / (this.likes + this.dislikes)) * 100 | |
54 | this.dislikesPercent = (this.dislikes / (this.likes + this.dislikes)) * 100 | |
55 | } | |
404b54e1 | 56 | } |