aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-add.ts
blob: 3012b75333c18f6aab700f1fdafa08ed2434eecc (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
35
36
37
38
import { Transaction } from 'sequelize'
import { ActivityAdd } from '../../../../shared/models/activitypub/activity'
import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
import { AccountInstance, VideoInstance } from '../../../models'
import { broadcastToFollowers, getAudience } from './misc'

async function sendAddVideo (video: VideoInstance, t: Transaction) {
  const byAccount = video.VideoChannel.Account

  const videoObject = video.toActivityPubObject()
  const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject)

  return broadcastToFollowers(data, byAccount, [ byAccount ], t)
}

async function addActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, target: string, object: any) {
  const videoPublic = video.privacy === VideoPrivacy.PUBLIC

  const { to, cc } = await getAudience(byAccount, videoPublic)
  const activity: ActivityAdd = {
    type: 'Add',
    id: url,
    actor: byAccount.url,
    to,
    cc,
    object,
    target
  }

  return activity
}

// ---------------------------------------------------------------------------

export {
  addActivityData,
  sendAddVideo
}