X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Fvideo%2Fvideo.model.ts;h=b7720c8d21da3617869c159a391f2d1be60a5f6a;hb=ff4de38385049bf8f6e1d76d8511854fcfabc71c;hp=0dca3da0d5544c9d4244045214772c4cb9479fac;hpb=7294aab0c879ef96c0fde15c389a2c4c1463d3c7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts index 0dca3da0d..b7720c8d2 100644 --- a/client/src/app/shared/shared-main/video/video.model.ts +++ b/client/src/app/shared/shared-main/video/video.model.ts @@ -1,10 +1,12 @@ import { AuthUser } from '@app/core' import { User } from '@app/core/users/user.model' import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' +import { Actor } from '@app/shared/shared-main/account/actor.model' +import { buildVideoWatchPath } from '@shared/core-utils' import { peertubeTranslate } from '@shared/core-utils/i18n' import { - Avatar, - ServerConfig, + ActorImage, + HTMLServerConfig, UserRight, Video as VideoServerModel, VideoConstant, @@ -12,15 +14,11 @@ import { VideoScheduleUpdate, VideoState } from '@shared/models' -import { Actor } from '../account/actor.model' export class Video implements VideoServerModel { byVideoChannel: string byAccount: string - accountAvatarUrl: string - videoChannelAvatarUrl: string - createdAt: Date updatedAt: Date publishedAt: Date @@ -29,17 +27,25 @@ export class Video implements VideoServerModel { licence: VideoConstant language: VideoConstant privacy: VideoConstant + description: string + duration: number durationLabel: string + id: number uuid: string + shortUUID: string + isLocal: boolean + name: string serverHost: string thumbnailPath: string thumbnailUrl: string + isLive: boolean + previewPath: string previewUrl: string @@ -68,7 +74,7 @@ export class Video implements VideoServerModel { displayName: string url: string host: string - avatar?: Avatar + avatar?: ActorImage } channel: { @@ -77,7 +83,7 @@ export class Video implements VideoServerModel { displayName: string url: string host: string - avatar?: Avatar + avatar?: ActorImage } userHistory?: { @@ -86,8 +92,12 @@ export class Video implements VideoServerModel { pluginData?: any - static buildClientUrl (videoUUID: string) { - return '/videos/watch/' + videoUUID + static buildWatchUrl (video: Partial>) { + return buildVideoWatchPath({ shortUUID: video.shortUUID || video.uuid }) + } + + static buildUpdateUrl (video: Pick) { + return '/videos/update/' + video.uuid } constructor (hash: VideoServerModel, translations = {}) { @@ -103,20 +113,27 @@ export class Video implements VideoServerModel { this.state = hash.state this.description = hash.description + this.isLive = hash.isLive + this.duration = hash.duration this.durationLabel = durationToString(hash.duration) this.id = hash.id this.uuid = hash.uuid + this.shortUUID = hash.shortUUID this.isLocal = hash.isLocal this.name = hash.name this.thumbnailPath = hash.thumbnailPath - this.thumbnailUrl = hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath) + this.thumbnailUrl = this.thumbnailPath + ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath) + : null this.previewPath = hash.previewPath - this.previewUrl = hash.previewUrl || (absoluteAPIUrl + hash.previewPath) + this.previewUrl = this.previewPath + ? hash.previewUrl || (absoluteAPIUrl + hash.previewPath) + : null this.embedPath = hash.embedPath this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath) @@ -134,8 +151,6 @@ export class Video implements VideoServerModel { this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host) - this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) - this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) this.category.label = peertubeTranslate(this.category.label, translations) this.licence.label = peertubeTranslate(this.licence.label, translations) @@ -158,7 +173,7 @@ export class Video implements VideoServerModel { this.pluginData = hash.pluginData } - isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { + isVideoNSFWForUser (user: User, serverConfig: HTMLServerConfig) { // Video is not NSFW, skip if (this.nsfw === false) return false @@ -185,7 +200,22 @@ export class Video implements VideoServerModel { return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) } + isLiveInfoAvailableBy (user: AuthUser) { + return this.isLive && + user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.GET_ANY_LIVE)) + } + canBeDuplicatedBy (user: AuthUser) { return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES) } + + getExactNumberOfViews () { + if (this.views < 1000) return '' + + if (this.isLive) { + return $localize`${this.views} viewers` + } + + return $localize`${this.views} views` + } }