aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/share.ts
blob: e14b0f50c0f5d290ac04befca30ac8a9ac28e94f (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
import { Transaction } from 'sequelize'
import { getServerAccount } from '../../helpers/utils'
import { database as db } from '../../initializers'
import { VideoChannelInstance } from '../../models/index'
import { VideoInstance } from '../../models/video/video-interface'
import { sendVideoAnnounceToFollowers, sendVideoChannelAnnounceToFollowers } from './send/send-announce'

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

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

  return sendVideoChannelAnnounceToFollowers(serverAccount, videoChannel, t)
}

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

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

  return sendVideoAnnounceToFollowers(serverAccount, video, t)
}

export {
  shareVideoChannelByServer,
  shareVideoByServer
}