From 4ba3b8ea1be85d95a508ac479f26b96ceea15971 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Jan 2018 15:49:57 +0100 Subject: Don't rehost announced video activities --- server/lib/activitypub/process/process-announce.ts | 7 +++-- server/lib/activitypub/send/send-announce.ts | 35 ++++------------------ server/lib/activitypub/share.ts | 24 ++++++++++----- 3 files changed, 27 insertions(+), 39 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 7dafc0593..09f2e80f3 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts @@ -43,11 +43,14 @@ async function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounc const share = { actorId: actorAnnouncer.id, - videoId: video.id + videoId: video.id, + url: activity.id } const [ , created ] = await VideoShareModel.findOrCreate({ - where: share, + where: { + url: activity.id + }, defaults: share, transaction: t }) diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts index 76cb3f80c..ed551a2b2 100644 --- a/server/lib/activitypub/send/send-announce.ts +++ b/server/lib/activitypub/send/send-announce.ts @@ -2,45 +2,23 @@ import { Transaction } from 'sequelize' import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub' import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' -import { getAnnounceActivityPubUrl } from '../url' -import { - broadcastToFollowers, - getActorsInvolvedInVideo, - getAudience, - getObjectFollowersAudience, - getOriginVideoAudience, - unicastTo -} from './misc' -import { createActivityData } from './send-create' +import { VideoShareModel } from '../../../models/video/video-share' +import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc' -async function buildVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { - const url = getAnnounceActivityPubUrl(video.url, byActor) +async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { const announcedObject = video.url const accountsToForwardView = await getActorsInvolvedInVideo(video, t) const audience = getObjectFollowersAudience(accountsToForwardView) - return announceActivityData(url, byActor, announcedObject, t, audience) + return announceActivityData(videoShare.url, byActor, announcedObject, t, audience) } -async function sendVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { - const data = await buildVideoAnnounceToFollowers(byActor, video, t) +async function sendVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { + const data = await buildVideoAnnounceToFollowers(byActor, videoShare, video, t) return broadcastToFollowers(data, byActor, [ byActor ], t) } -async function sendVideoAnnounceToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { - const url = getAnnounceActivityPubUrl(video.url, byActor) - - const videoObject = video.toActivityPubObject() - const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t) - - const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) - const data = await createActivityData(url, byActor, announcedActivity, t, audience) - - return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) -} - async function announceActivityData ( url: string, byActor: ActorModel, @@ -66,7 +44,6 @@ async function announceActivityData ( export { sendVideoAnnounceToFollowers, - sendVideoAnnounceToOrigin, announceActivityData, buildVideoAnnounceToFollowers } diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index fd374d03d..53ecd3dab 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts @@ -4,28 +4,36 @@ import { getServerActor } from '../../helpers/utils' import { VideoModel } from '../../models/video/video' import { VideoShareModel } from '../../models/video/video-share' import { sendVideoAnnounceToFollowers } from './send' +import { getAnnounceActivityPubUrl } from './url' async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { if (video.privacy === VideoPrivacy.PRIVATE) return undefined const serverActor = await getServerActor() - const serverShare = VideoShareModel.create({ + const serverShareUrl = getAnnounceActivityPubUrl(video.url, serverActor) + const serverSharePromise = VideoShareModel.create({ actorId: serverActor.id, - videoId: video.id + videoId: video.id, + url: serverShareUrl }, { transaction: t }) - const videoChannelShare = VideoShareModel.create({ + const videoChannelShareUrl = getAnnounceActivityPubUrl(video.url, video.VideoChannel.Actor) + const videoChannelSharePromise = VideoShareModel.create({ actorId: video.VideoChannel.actorId, - videoId: video.id + videoId: video.id, + url: videoChannelShareUrl }, { transaction: t }) - await Promise.all([ - serverShare, - videoChannelShare + const [ serverShare, videoChannelShare ] = await Promise.all([ + serverSharePromise, + videoChannelSharePromise ]) - return sendVideoAnnounceToFollowers(serverActor, video, t) + return Promise.all([ + sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t), + sendVideoAnnounceToFollowers(serverActor, serverShare, video, t) + ]) } export { -- cgit v1.2.3