aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/share.ts
blob: 689e200a6c4cce00074b2db63e72e7d1a8169a8c (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 { sendVideoAnnounce, sendVideoChannelAnnounce } 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 sendVideoChannelAnnounce(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 sendVideoAnnounce(serverAccount, video, t)
}

export {
  shareVideoChannelByServer,
  shareVideoByServer
}