From 5cf84858d49f4231cc4efec5e3132f17f65f6cf6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Sep 2018 10:22:10 +0200 Subject: Add federation to ownership change --- server/lib/activitypub/process/process-undo.ts | 10 ++++++---- server/lib/activitypub/send/send-announce.ts | 5 ++++- server/lib/activitypub/send/send-update.ts | 10 ++++++++-- server/lib/activitypub/share.ts | 2 ++ 4 files changed, 20 insertions(+), 7 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index eab9e3d61..1c1de8827 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts @@ -104,17 +104,19 @@ function processUndoFollow (actorUrl: string, followActivity: ActivityFollow) { function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { return sequelizeTypescript.transaction(async t => { - const byAccount = await AccountModel.loadByUrl(actorUrl, t) - if (!byAccount) throw new Error('Unknown account ' + actorUrl) + const byActor = await ActorModel.loadByUrl(actorUrl, t) + if (!byActor) throw new Error('Unknown actor ' + actorUrl) const share = await VideoShareModel.loadByUrl(announceActivity.id, t) - if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`) + if (!share) throw new Error(`Unknown video share ${announceActivity.id}.`) + + if (share.actorId !== byActor.id) throw new Error(`${share.url} is not shared by ${byActor.url}.`) await share.destroy({ transaction: t }) if (share.Video.isOwned()) { // Don't resend the activity to the sender - const exceptions = [ byAccount.Actor ] + const exceptions = [ byActor ] await forwardVideoRelatedActivity(announceActivity, t, exceptions, share.Video) } diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts index 1ab05ca3c..352813d73 100644 --- a/server/lib/activitypub/send/send-announce.ts +++ b/server/lib/activitypub/send/send-announce.ts @@ -20,7 +20,10 @@ async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareMod logger.info('Creating job to send announce %s.', videoShare.url) - return broadcastToFollowers(data, byActor, [ byActor ], t) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const followersException = [ byActor ] + + return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) } function announceActivityData (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce { diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 17d4f185c..6f1d80898 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -10,13 +10,19 @@ import { getUpdateActivityPubUrl } from '../url' import { broadcastToFollowers } from './utils' import { audiencify, getAudience } from '../audience' import { logger } from '../../../helpers/logger' +import { videoFeedsValidator } from '../../../middlewares/validators' +import { VideoCaptionModel } from '../../../models/video/video-caption' -async function sendUpdateVideo (video: VideoModel, t: Transaction) { +async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByActor?: ActorModel) { logger.info('Creating job to update video %s.', video.url) - const byActor = video.VideoChannel.Account.Actor + const byActor = overrodeByActor ? overrodeByActor : video.VideoChannel.Account.Actor const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) + + // Needed to build the AP object + if (!video.VideoCaptions) video.VideoCaptions = await video.$get('VideoCaptions') as VideoCaptionModel[] + const videoObject = video.toActivityPubObject() const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index fe3d73e9b..3ff60a97c 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts @@ -22,6 +22,8 @@ async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) } async function changeVideoChannelShare (video: VideoModel, oldVideoChannel: VideoChannelModel, t: Transaction) { + logger.info('Updating video channel of video %s: %s -> %s.', video.uuid, oldVideoChannel.name, video.VideoChannel.name) + await undoShareByVideoChannel(video, oldVideoChannel, t) await shareByVideoChannel(video, t) -- cgit v1.2.3