]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-update.ts
Refractor activity pub lib/helpers
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-update.ts
CommitLineData
54141398
C
1import { Transaction } from 'sequelize'
2import { ActivityUpdate } from '../../../../shared/models/activitypub/activity'
3import { getUpdateActivityPubUrl } from '../../../helpers/activitypub'
4import { database as db } from '../../../initializers'
5import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
6import { broadcastToFollowers, getAudience } from './misc'
7
8async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
9 const byAccount = videoChannel.Account
10
11 const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
12 const videoChannelObject = videoChannel.toActivityPubObject()
13 const data = await updateActivityData(url, byAccount, videoChannelObject)
14
15 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
16 accountsInvolved.push(byAccount)
17
18 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
19}
20
21async function sendUpdateVideo (video: VideoInstance, t: Transaction) {
22 const byAccount = video.VideoChannel.Account
23
24 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
25 const videoObject = video.toActivityPubObject()
26 const data = await updateActivityData(url, byAccount, videoObject)
27
28 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
29 accountsInvolved.push(byAccount)
30
31 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
32}
33
34// ---------------------------------------------------------------------------
35
36export {
37 sendUpdateVideoChannel,
38 sendUpdateVideo
39}
40
41// ---------------------------------------------------------------------------
42
43async function updateActivityData (url: string, byAccount: AccountInstance, object: any) {
44 const { to, cc } = await getAudience(byAccount)
45 const activity: ActivityUpdate = {
46 type: 'Update',
47 id: url,
48 actor: byAccount.url,
49 to,
50 cc,
51 object
52 }
53
54 return activity
55}