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-add.ts | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/lib/activitypub/send/send-add.ts (limited to 'server/lib/activitypub/send/send-add.ts') diff --git a/server/lib/activitypub/send/send-add.ts b/server/lib/activitypub/send/send-add.ts new file mode 100644 index 000000000..3012b7533 --- /dev/null +++ b/server/lib/activitypub/send/send-add.ts @@ -0,0 +1,38 @@ +import { Transaction } from 'sequelize' +import { ActivityAdd } from '../../../../shared/models/activitypub/activity' +import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +import { AccountInstance, VideoInstance } from '../../../models' +import { broadcastToFollowers, getAudience } from './misc' + +async function sendAddVideo (video: VideoInstance, t: Transaction) { + const byAccount = video.VideoChannel.Account + + const videoObject = video.toActivityPubObject() + const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject) + + return broadcastToFollowers(data, byAccount, [ byAccount ], t) +} + +async function addActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, target: string, object: any) { + const videoPublic = video.privacy === VideoPrivacy.PUBLIC + + const { to, cc } = await getAudience(byAccount, videoPublic) + const activity: ActivityAdd = { + type: 'Add', + id: url, + actor: byAccount.url, + to, + cc, + object, + target + } + + return activity +} + +// --------------------------------------------------------------------------- + +export { + addActivityData, + sendAddVideo +} -- cgit v1.2.3