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