diff options
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts new file mode 100644 index 000000000..66bfeee89 --- /dev/null +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { ActivityCreate } from '../../../../shared/models/activitypub/activity' | ||
3 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | ||
4 | import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' | ||
5 | import { broadcastToFollowers, getAudience, unicastTo } from './misc' | ||
6 | import { getVideoAbuseActivityPubUrl } from '../../../helpers/activitypub' | ||
7 | |||
8 | async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | ||
9 | const byAccount = videoChannel.Account | ||
10 | |||
11 | const videoChannelObject = videoChannel.toActivityPubObject() | ||
12 | const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject) | ||
13 | |||
14 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | ||
15 | } | ||
16 | |||
17 | async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) { | ||
18 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | ||
19 | const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject()) | ||
20 | |||
21 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | ||
22 | } | ||
23 | |||
24 | async function createActivityData (url: string, byAccount: AccountInstance, object: any) { | ||
25 | const { to, cc } = await getAudience(byAccount) | ||
26 | const activity: ActivityCreate = { | ||
27 | type: 'Create', | ||
28 | id: url, | ||
29 | actor: byAccount.url, | ||
30 | to, | ||
31 | cc, | ||
32 | object | ||
33 | } | ||
34 | |||
35 | return activity | ||
36 | } | ||
37 | |||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | export { | ||
41 | sendCreateVideoChannel, | ||
42 | sendVideoAbuse, | ||
43 | createActivityData | ||
44 | } | ||