From 54141398354e6e7b94aa3065a705a1251390111c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 20 Nov 2017 09:43:39 +0100 Subject: Refractor activity pub lib/helpers --- server/lib/activitypub/send/send-create.ts | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 server/lib/activitypub/send/send-create.ts (limited to 'server/lib/activitypub/send/send-create.ts') 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 @@ +import { Transaction } from 'sequelize' +import { ActivityCreate } from '../../../../shared/models/activitypub/activity' +import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' +import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' +import { broadcastToFollowers, getAudience, unicastTo } from './misc' +import { getVideoAbuseActivityPubUrl } from '../../../helpers/activitypub' + +async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { + const byAccount = videoChannel.Account + + const videoChannelObject = videoChannel.toActivityPubObject() + const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject) + + return broadcastToFollowers(data, byAccount, [ byAccount ], t) +} + +async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) { + const url = getVideoAbuseActivityPubUrl(videoAbuse) + const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject()) + + return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) +} + +async function createActivityData (url: string, byAccount: AccountInstance, object: any) { + const { to, cc } = await getAudience(byAccount) + const activity: ActivityCreate = { + type: 'Create', + id: url, + actor: byAccount.url, + to, + cc, + object + } + + return activity +} + +// --------------------------------------------------------------------------- + +export { + sendCreateVideoChannel, + sendVideoAbuse, + createActivityData +} -- cgit v1.2.3