]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/share.ts
5bec61c051952520413a23be8d95b3e409aea7ab
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / share.ts
1 import { Transaction } from 'sequelize'
2 import { getServerAccount } from '../../helpers'
3 import { VideoModel } from '../../models/video/video'
4 import { VideoChannelModel } from '../../models/video/video-channel'
5 import { VideoChannelShareModel } from '../../models/video/video-channel-share'
6 import { VideoShareModel } from '../../models/video/video-share'
7 import { sendVideoAnnounceToFollowers, sendVideoChannelAnnounceToFollowers } from './send'
8
9 async function shareVideoChannelByServer (videoChannel: VideoChannelModel, t: Transaction) {
10 const serverAccount = await getServerAccount()
11
12 await VideoChannelShareModel.create({
13 accountId: serverAccount.id,
14 videoChannelId: videoChannel.id
15 }, { transaction: t })
16
17 return sendVideoChannelAnnounceToFollowers(serverAccount, videoChannel, t)
18 }
19
20 async function shareVideoByServer (video: VideoModel, t: Transaction) {
21 const serverAccount = await getServerAccount()
22
23 await VideoShareModel.create({
24 accountId: serverAccount.id,
25 videoId: video.id
26 }, { transaction: t })
27
28 return sendVideoAnnounceToFollowers(serverAccount, video, t)
29 }
30
31 export {
32 shareVideoChannelByServer,
33 shareVideoByServer
34 }