]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/video/video.model.ts
Fix notification scrollbar color
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video.model.ts
index 73f0198e20e8c7c9eecfa97c9db1db3e40522377..adb6e884f16c2066a2c6f9a9b31408807334b578 100644 (file)
@@ -1,6 +1,9 @@
 import { AuthUser } from '@app/core'
 import { User } from '@app/core/users/user.model'
 import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
+import { Account } from '@app/shared/shared-main/account/account.model'
+import { Actor } from '@app/shared/shared-main/account/actor.model'
+import { VideoChannel } from '@app/shared/shared-main/video-channel/video-channel.model'
 import { peertubeTranslate } from '@shared/core-utils/i18n'
 import {
   Avatar,
@@ -12,7 +15,6 @@ import {
   VideoScheduleUpdate,
   VideoState
 } from '@shared/models'
-import { Actor } from '../account/actor.model'
 
 export class Video implements VideoServerModel {
   byVideoChannel: string
@@ -40,6 +42,8 @@ export class Video implements VideoServerModel {
   thumbnailPath: string
   thumbnailUrl: string
 
+  isLive: boolean
+
   previewPath: string
   previewUrl: string
 
@@ -84,6 +88,8 @@ export class Video implements VideoServerModel {
     currentTime: number
   }
 
+  pluginData?: any
+
   static buildClientUrl (videoUUID: string) {
     return '/videos/watch/' + videoUUID
   }
@@ -101,6 +107,8 @@ 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)
 
@@ -111,10 +119,14 @@ export class Video implements VideoServerModel {
     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)
@@ -132,8 +144,8 @@ 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.accountAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.account)
+    this.videoChannelAvatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this.channel)
 
     this.category.label = peertubeTranslate(this.category.label, translations)
     this.licence.label = peertubeTranslate(this.licence.label, translations)
@@ -152,6 +164,8 @@ export class Video implements VideoServerModel {
 
     this.originInstanceHost = this.account.host
     this.originInstanceUrl = 'https://' + this.originInstanceHost
+
+    this.pluginData = hash.pluginData
   }
 
   isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
@@ -181,7 +195,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`
+  }
 }