]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/share.ts
Fix comment creation
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / share.ts
1 import { Transaction } from 'sequelize'
2 import { VideoPrivacy } from '../../../shared/models/videos'
3 import { getServerActor } from '../../helpers/utils'
4 import { VideoModel } from '../../models/video/video'
5 import { VideoShareModel } from '../../models/video/video-share'
6 import { sendVideoAnnounceToFollowers } from './send'
7
8 async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
9 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
10
11 const serverActor = await getServerActor()
12
13 const serverShare = VideoShareModel.create({
14 actorId: serverActor.id,
15 videoId: video.id
16 }, { transaction: t })
17
18 const videoChannelShare = VideoShareModel.create({
19 actorId: video.VideoChannel.actorId,
20 videoId: video.id
21 }, { transaction: t })
22
23 await Promise.all([
24 serverShare,
25 videoChannelShare
26 ])
27
28 return sendVideoAnnounceToFollowers(serverActor, video, t)
29 }
30
31 export {
32 shareVideoByServerAndChannel
33 }