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-announce.ts | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 server/lib/activitypub/send/send-announce.ts (limited to 'server/lib/activitypub/send/send-announce.ts') diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts new file mode 100644 index 000000000..b9217e4f6 --- /dev/null +++ b/server/lib/activitypub/send/send-announce.ts @@ -0,0 +1,45 @@ +import { Transaction } from 'sequelize' +import { AccountInstance, VideoInstance } from '../../../models' +import { VideoChannelInstance } from '../../../models/video/video-channel-interface' +import { broadcastToFollowers } from './misc' +import { addActivityData } from './send-add' +import { createActivityData } from './send-create' +import { getAnnounceActivityPubUrl } from '../../../helpers/activitypub' + +async function sendVideoAnnounce (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { + const url = getAnnounceActivityPubUrl(video.url, byAccount) + + const videoChannel = video.VideoChannel + const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject()) + + const data = await announceActivityData(url, byAccount, announcedActivity) + return broadcastToFollowers(data, byAccount, [ byAccount ], t) +} + +async function sendVideoChannelAnnounce (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { + const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) + const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject()) + + const data = await announceActivityData(url, byAccount, announcedActivity) + return broadcastToFollowers(data, byAccount, [ byAccount ], t) +} + +// --------------------------------------------------------------------------- + +export { + sendVideoAnnounce, + sendVideoChannelAnnounce +} + +// --------------------------------------------------------------------------- + +async function announceActivityData (url: string, byAccount: AccountInstance, object: any) { + const activity = { + type: 'Announce', + id: url, + actor: byAccount.url, + object + } + + return activity +} -- cgit v1.2.3