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