diff options
Diffstat (limited to 'server/lib/activitypub/send/send-update.ts')
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts new file mode 100644 index 000000000..42738f973 --- /dev/null +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -0,0 +1,55 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' | ||
3 | import { getUpdateActivityPubUrl } from '../../../helpers/activitypub' | ||
4 | import { database as db } from '../../../initializers' | ||
5 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | ||
6 | import { broadcastToFollowers, getAudience } from './misc' | ||
7 | |||
8 | async 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 | |||
21 | async 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 | |||
36 | export { | ||
37 | sendUpdateVideoChannel, | ||
38 | sendUpdateVideo | ||
39 | } | ||
40 | |||
41 | // --------------------------------------------------------------------------- | ||
42 | |||
43 | async 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 | } | ||