]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video/video.model.ts
Refactor actor avatar display
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video.model.ts
CommitLineData
3a0fb65c 1import { AuthUser } from '@app/core'
67ed6552 2import { User } from '@app/core/users/user.model'
72493e44 3import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
69524f6e
C
4import { Account } from '@app/shared/shared-main/account/account.model'
5import { Actor } from '@app/shared/shared-main/account/actor.model'
6import { VideoChannel } from '@app/shared/shared-main/video-channel/video-channel.model'
bd45d503 7import { peertubeTranslate } from '@shared/core-utils/i18n'
67ed6552 8import {
f4796856 9 ActorImage,
67ed6552
C
10 ServerConfig,
11 UserRight,
12 Video as VideoServerModel,
13 VideoConstant,
14 VideoPrivacy,
15 VideoScheduleUpdate,
16 VideoState
17} from '@shared/models'
92fb909c 18
69f616ab 19export class Video implements VideoServerModel {
22a16e36
C
20 byVideoChannel: string
21 byAccount: string
22
52d9f792 23 videoChannelAvatarUrl: string
22a16e36 24
df98563e 25 createdAt: Date
6d33593a 26 updatedAt: Date
2922e048 27 publishedAt: Date
c8034165 28 originallyPublishedAt: Date | string
09700934
C
29 category: VideoConstant<number>
30 licence: VideoConstant<number>
9d3ef9fe 31 language: VideoConstant<string>
2243730c 32 privacy: VideoConstant<VideoPrivacy>
df98563e
C
33 description: string
34 duration: number
35 durationLabel: string
0a6658fd
C
36 id: number
37 uuid: string
df98563e 38 isLocal: boolean
df98563e 39 name: string
60862425 40 serverHost: string
df98563e
C
41 thumbnailPath: string
42 thumbnailUrl: string
5fb2e288 43
c6c0fa6c
C
44 isLive: boolean
45
43f61d26
C
46 previewPath: string
47 previewUrl: string
5fb2e288 48
d8755eed
C
49 embedPath: string
50 embedUrl: string
5fb2e288
C
51
52 url?: string
53
df98563e
C
54 views: number
55 likes: number
56 dislikes: number
57 nsfw: boolean
b64c950a 58
c910f667
C
59 originInstanceUrl: string
60 originInstanceHost: string
61
2186386c
C
62 waitTranscoding?: boolean
63 state?: VideoConstant<VideoState>
bbe0f064 64 scheduledUpdate?: VideoScheduleUpdate
191764f3 65 blacklisted?: boolean
5baee5fc 66 blockedReason?: string
2186386c 67
b64c950a 68 account: {
03e12d7c 69 id: number
b64c950a
C
70 name: string
71 displayName: string
72 url: string
0f320037 73 host: string
f4796856 74 avatar?: ActorImage
0f320037
C
75 }
76
77 channel: {
78 id: number
0f320037
C
79 name: string
80 displayName: string
81 url: string
b64c950a 82 host: string
f4796856 83 avatar?: ActorImage
b64c950a 84 }
aff038cd 85
6e46de09
C
86 userHistory?: {
87 currentTime: number
88 }
89
7294aab0
C
90 pluginData?: any
91
191764f3
C
92 static buildClientUrl (videoUUID: string) {
93 return '/videos/watch/' + videoUUID
94 }
95
7ce44a74 96 constructor (hash: VideoServerModel, translations = {}) {
c5911fd3 97 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 98
d592e0a9 99 this.createdAt = new Date(hash.createdAt.toString())
2922e048 100 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 101 this.category = hash.category
df98563e 102 this.licence = hash.licence
df98563e 103 this.language = hash.language
2243730c 104 this.privacy = hash.privacy
2186386c
C
105 this.waitTranscoding = hash.waitTranscoding
106 this.state = hash.state
df98563e 107 this.description = hash.description
c910f667 108
c6c0fa6c
C
109 this.isLive = hash.isLive
110
df98563e 111 this.duration = hash.duration
11b8762f 112 this.durationLabel = durationToString(hash.duration)
c910f667 113
df98563e 114 this.id = hash.id
0a6658fd 115 this.uuid = hash.uuid
c910f667 116
df98563e 117 this.isLocal = hash.isLocal
df98563e 118 this.name = hash.name
c910f667 119
df98563e 120 this.thumbnailPath = hash.thumbnailPath
c6c0fa6c
C
121 this.thumbnailUrl = this.thumbnailPath
122 ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
123 : null
c910f667 124
43f61d26 125 this.previewPath = hash.previewPath
c6c0fa6c
C
126 this.previewUrl = this.previewPath
127 ? hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
128 : null
c910f667 129
d8755eed 130 this.embedPath = hash.embedPath
72493e44 131 this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
5fb2e288
C
132
133 this.url = hash.url
c910f667 134
df98563e
C
135 this.views = hash.views
136 this.likes = hash.likes
137 this.dislikes = hash.dislikes
c910f667 138
df98563e 139 this.nsfw = hash.nsfw
c910f667 140
b64c950a 141 this.account = hash.account
52d9f792 142 this.channel = hash.channel
4fd8aa32 143
22a16e36
C
144 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
145 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
c418d483 146 this.videoChannelAvatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this.channel)
7ce44a74
C
147
148 this.category.label = peertubeTranslate(this.category.label, translations)
149 this.licence.label = peertubeTranslate(this.licence.label, translations)
150 this.language.label = peertubeTranslate(this.language.label, translations)
151 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
2186386c 152
bbe0f064 153 this.scheduledUpdate = hash.scheduledUpdate
830b4faf
C
154 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
155
2186386c 156 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
191764f3
C
157
158 this.blacklisted = hash.blacklisted
5baee5fc 159 this.blockedReason = hash.blacklistedReason
6e46de09
C
160
161 this.userHistory = hash.userHistory
c910f667
C
162
163 this.originInstanceHost = this.account.host
164 this.originInstanceUrl = 'https://' + this.originInstanceHost
7294aab0
C
165
166 this.pluginData = hash.pluginData
501bc6c2
C
167 }
168
0883b324
C
169 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
170 // Video is not NSFW, skip
171 if (this.nsfw === false) return false
172
173 // Return user setting if logged in
174 if (user) return user.nsfwPolicy !== 'display'
175
176 // Return default instance config
177 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 178 }
3a0fb65c
C
179
180 isRemovableBy (user: AuthUser) {
181 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
182 }
183
5baee5fc 184 isBlockableBy (user: AuthUser) {
3487330d 185 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
3a0fb65c
C
186 }
187
5baee5fc 188 isUnblockableBy (user: AuthUser) {
3487330d 189 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
3a0fb65c
C
190 }
191
192 isUpdatableBy (user: AuthUser) {
193 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
194 }
b764380a 195
f8c00564
C
196 isLiveInfoAvailableBy (user: AuthUser) {
197 return this.isLive &&
198 user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.GET_ANY_LIVE))
199 }
200
b764380a
C
201 canBeDuplicatedBy (user: AuthUser) {
202 return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)
203 }
4ec25ae8
C
204
205 getExactNumberOfViews () {
206 if (this.views < 1000) return ''
207
208 if (this.isLive) {
209 return $localize`${this.views} viewers`
210 }
211
212 return $localize`${this.views} views`
213 }
501bc6c2 214}