aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/share.ts
blob: 5bec61c051952520413a23be8d95b3e409aea7ab (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
31
32
33
34
import { Transaction } from 'sequelize'
import { getServerAccount } from '../../helpers'
import { VideoModel } from '../../models/video/video'
import { VideoChannelModel } from '../../models/video/video-channel'
import { VideoChannelShareModel } from '../../models/video/video-channel-share'
import { VideoShareModel } from '../../models/video/video-share'
import { sendVideoAnnounceToFollowers, sendVideoChannelAnnounceToFollowers } from './send'

async function shareVideoChannelByServer (videoChannel: VideoChannelModel, t: Transaction) {
  const serverAccount = await getServerAccount()

  await VideoChannelShareModel.create({
    accountId: serverAccount.id,
    videoChannelId: videoChannel.id
  }, { transaction: t })

  return sendVideoChannelAnnounceToFollowers(serverAccount, videoChannel, t)
}

async function shareVideoByServer (video: VideoModel, t: Transaction) {
  const serverAccount = await getServerAccount()

  await VideoShareModel.create({
    accountId: serverAccount.id,
    videoId: video.id
  }, { transaction: t })

  return sendVideoAnnounceToFollowers(serverAccount, video, t)
}

export {
  shareVideoChannelByServer,
  shareVideoByServer
}