diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-20 09:43:39 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 54141398354e6e7b94aa3065a705a1251390111c (patch) | |
tree | 8d30d1b9ea8acbe04f6d404125b04fc0c9897b70 /server/lib/activitypub/send/send-create.ts | |
parent | eb8b27c93e61a896a08923dc1ca3c87ba8cf4948 (diff) | |
download | PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.gz PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.zst PeerTube-54141398354e6e7b94aa3065a705a1251390111c.zip |
Refractor activity pub lib/helpers
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 | } | ||