From 20494f122186bb1bfd82f4c598c4744acea27b0c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Nov 2017 15:22:39 +0100 Subject: Server shares user videos --- server/lib/activitypub/send-request.ts | 40 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'server/lib/activitypub/send-request.ts') diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts index 664b9d826..f9b72f2a8 100644 --- a/server/lib/activitypub/send-request.ts +++ b/server/lib/activitypub/send-request.ts @@ -59,24 +59,21 @@ async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transac return broadcastToFollowers(data, [ account ], t) } -async function sendAnnounce (byAccount: AccountInstance, instance: VideoInstance | VideoChannelInstance, t: Sequelize.Transaction) { - const object = instance.toActivityPubObject() - - let url = '' - let objectActorUrl: string - if ((instance as any).VideoChannel !== undefined) { - objectActorUrl = (instance as VideoInstance).VideoChannel.Account.url - url = getActivityPubUrl('video', instance.uuid) + '#announce' - } else { - objectActorUrl = (instance as VideoChannelInstance).Account.url - url = getActivityPubUrl('videoChannel', instance.uuid) + '#announce' - } +async function sendVideoChannelAnnounce (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { + const url = getActivityPubUrl('videoChannel', videoChannel.uuid) + '#announce' + const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), true) + + const data = await announceActivityData(url, byAccount, announcedActivity) + return broadcastToFollowers(data, [ byAccount ], t) +} - const objectWithActor = Object.assign(object, { - actor: objectActorUrl - }) +async function sendVideoAnnounce (byAccount: AccountInstance, video: VideoInstance, t: Sequelize.Transaction) { + const url = getActivityPubUrl('video', video.uuid) + '#announce' - const data = await announceActivityData(url, byAccount, objectWithActor) + const videoChannel = video.VideoChannel + const announcedActivity = await addActivityData(url, videoChannel.Account, videoChannel.url, video.toActivityPubObject(), true) + + const data = await announceActivityData(url, byAccount, announcedActivity) return broadcastToFollowers(data, [ byAccount ], t) } @@ -117,7 +114,8 @@ export { sendAccept, sendFollow, sendVideoAbuse, - sendAnnounce + sendVideoChannelAnnounce, + sendVideoAnnounce } // --------------------------------------------------------------------------- @@ -159,7 +157,7 @@ async function getPublicActivityTo (account: AccountInstance) { return inboxUrls.concat('https://www.w3.org/ns/activitystreams#Public') } -async function createActivityData (url: string, byAccount: AccountInstance, object: any) { +async function createActivityData (url: string, byAccount: AccountInstance, object: any, raw = false) { const to = await getPublicActivityTo(byAccount) const base = { type: 'Create', @@ -169,6 +167,8 @@ async function createActivityData (url: string, byAccount: AccountInstance, obje object } + if (raw === true) return base + return buildSignedActivity(byAccount, base) } @@ -195,7 +195,7 @@ async function deleteActivityData (url: string, byAccount: AccountInstance) { return buildSignedActivity(byAccount, base) } -async function addActivityData (url: string, byAccount: AccountInstance, target: string, object: any) { +async function addActivityData (url: string, byAccount: AccountInstance, target: string, object: any, raw = false) { const to = await getPublicActivityTo(byAccount) const base = { type: 'Add', @@ -206,6 +206,8 @@ async function addActivityData (url: string, byAccount: AccountInstance, target: target } + if (raw === true) return base + return buildSignedActivity(byAccount, base) } -- cgit v1.2.3