]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-format-utils.ts
Fix videos list when page is empty
[github/Chocobozzz/PeerTube.git] / server / models / video / video-format-utils.ts
index f23dde9b874a854ac7c079f51f6ef2808808d1be..905e8444997e8306d07773213960491ad9b41261 100644 (file)
@@ -10,6 +10,7 @@ import {
   getVideoLikesActivityPubUrl,
   getVideoSharesActivityPubUrl
 } from '../../lib/activitypub'
+import { isArray } from '../../helpers/custom-validators/misc'
 
 export type VideoFormattingJSONOptions = {
   completeDescription?: boolean
@@ -24,6 +25,8 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
   const formattedAccount = video.VideoChannel.Account.toFormattedJSON()
   const formattedVideoChannel = video.VideoChannel.toFormattedJSON()
 
+  const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined
+
   const videoObject: Video = {
     id: video.id,
     uuid: video.uuid,
@@ -74,7 +77,11 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
       url: formattedVideoChannel.url,
       host: formattedVideoChannel.host,
       avatar: formattedVideoChannel.avatar
-    }
+    },
+
+    userHistory: userHistory ? {
+      currentTime: userHistory.currentTime
+    } : undefined
   }
 
   if (options) {