aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/share.ts
blob: fb01368ec8c2351c1aced31632d08b556ff58b3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Transaction } from 'sequelize'
import { getServerActor } from '../../helpers'
import { VideoModel } from '../../models/video/video'
import { VideoShareModel } from '../../models/video/video-share'
import { sendVideoAnnounceToFollowers } from './send'

async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
  const serverActor = await getServerActor()

  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 {
  shareVideoByServerAndChannel
}