Fix lint
[oweals/peertube.git] / server / lib / activitypub / share.ts
index f79c4e532af10d1da5b4578680b1e752ed4a3e46..fd374d03d178a3e1e33c6cc8aaecc6edeac7177f 100644 (file)
@@ -1,20 +1,33 @@
 import { Transaction } from 'sequelize'
-import { getServerActor } from '../../helpers'
+import { VideoPrivacy } from '../../../shared/models/videos'
+import { getServerActor } from '../../helpers/utils'
 import { VideoModel } from '../../models/video/video'
 import { VideoShareModel } from '../../models/video/video-share'
 import { sendVideoAnnounceToFollowers } from './send'
 
-async function shareVideoByServer (video: VideoModel, t: Transaction) {
+async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
+  if (video.privacy === VideoPrivacy.PRIVATE) return undefined
+
   const serverActor = await getServerActor()
 
-  await VideoShareModel.create({
+  const serverShare = VideoShareModel.create({
     actorId: serverActor.id,
     videoId: video.id
   }, { transaction: t })
 
+  const videoChannelShare = VideoShareModel.create({
+    actorId: video.VideoChannel.actorId,
+    videoId: video.id
+  }, { transaction: t })
+
+  await Promise.all([
+    serverShare,
+    videoChannelShare
+  ])
+
   return sendVideoAnnounceToFollowers(serverActor, video, t)
 }
 
 export {
-  shareVideoByServer
+  shareVideoByServerAndChannel
 }