aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-26 15:49:57 +0100
committerChocobozzz <me@florianbigard.com>2018-01-26 15:49:57 +0100
commit4ba3b8ea1be85d95a508ac479f26b96ceea15971 (patch)
treef76de3c6ec591cf885e5000f0e369aab883f3d95 /server/lib/activitypub
parent7859b5800c08c15f3380fb3a7e267ce1b3f2df9f (diff)
downloadPeerTube-4ba3b8ea1be85d95a508ac479f26b96ceea15971.tar.gz
PeerTube-4ba3b8ea1be85d95a508ac479f26b96ceea15971.tar.zst
PeerTube-4ba3b8ea1be85d95a508ac479f26b96ceea15971.zip
Don't rehost announced video activities
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/process/process-announce.ts7
-rw-r--r--server/lib/activitypub/send/send-announce.ts35
-rw-r--r--server/lib/activitypub/share.ts24
3 files changed, 27 insertions, 39 deletions
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
43 43
44 const share = { 44 const share = {
45 actorId: actorAnnouncer.id, 45 actorId: actorAnnouncer.id,
46 videoId: video.id 46 videoId: video.id,
47 url: activity.id
47 } 48 }
48 49
49 const [ , created ] = await VideoShareModel.findOrCreate({ 50 const [ , created ] = await VideoShareModel.findOrCreate({
50 where: share, 51 where: {
52 url: activity.id
53 },
51 defaults: share, 54 defaults: share,
52 transaction: t 55 transaction: t
53 }) 56 })
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'
2import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub' 2import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
3import { ActorModel } from '../../../models/activitypub/actor' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { getAnnounceActivityPubUrl } from '../url' 5import { VideoShareModel } from '../../../models/video/video-share'
6import { 6import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc'
7 broadcastToFollowers,
8 getActorsInvolvedInVideo,
9 getAudience,
10 getObjectFollowersAudience,
11 getOriginVideoAudience,
12 unicastTo
13} from './misc'
14import { createActivityData } from './send-create'
15 7
16async function buildVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 8async function buildVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
17 const url = getAnnounceActivityPubUrl(video.url, byActor)
18 const announcedObject = video.url 9 const announcedObject = video.url
19 10
20 const accountsToForwardView = await getActorsInvolvedInVideo(video, t) 11 const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
21 const audience = getObjectFollowersAudience(accountsToForwardView) 12 const audience = getObjectFollowersAudience(accountsToForwardView)
22 return announceActivityData(url, byActor, announcedObject, t, audience) 13 return announceActivityData(videoShare.url, byActor, announcedObject, t, audience)
23} 14}
24 15
25async function sendVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 16async function sendVideoAnnounceToFollowers (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
26 const data = await buildVideoAnnounceToFollowers(byActor, video, t) 17 const data = await buildVideoAnnounceToFollowers(byActor, videoShare, video, t)
27 18
28 return broadcastToFollowers(data, byActor, [ byActor ], t) 19 return broadcastToFollowers(data, byActor, [ byActor ], t)
29} 20}
30 21
31async function sendVideoAnnounceToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
32 const url = getAnnounceActivityPubUrl(video.url, byActor)
33
34 const videoObject = video.toActivityPubObject()
35 const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t)
36
37 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
38 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
39 const data = await createActivityData(url, byActor, announcedActivity, t, audience)
40
41 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
42}
43
44async function announceActivityData ( 22async function announceActivityData (
45 url: string, 23 url: string,
46 byActor: ActorModel, 24 byActor: ActorModel,
@@ -66,7 +44,6 @@ async function announceActivityData (
66 44
67export { 45export {
68 sendVideoAnnounceToFollowers, 46 sendVideoAnnounceToFollowers,
69 sendVideoAnnounceToOrigin,
70 announceActivityData, 47 announceActivityData,
71 buildVideoAnnounceToFollowers 48 buildVideoAnnounceToFollowers
72} 49}
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'
4import { VideoModel } from '../../models/video/video' 4import { VideoModel } from '../../models/video/video'
5import { VideoShareModel } from '../../models/video/video-share' 5import { VideoShareModel } from '../../models/video/video-share'
6import { sendVideoAnnounceToFollowers } from './send' 6import { sendVideoAnnounceToFollowers } from './send'
7import { getAnnounceActivityPubUrl } from './url'
7 8
8async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { 9async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
9 if (video.privacy === VideoPrivacy.PRIVATE) return undefined 10 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
10 11
11 const serverActor = await getServerActor() 12 const serverActor = await getServerActor()
12 13
13 const serverShare = VideoShareModel.create({ 14 const serverShareUrl = getAnnounceActivityPubUrl(video.url, serverActor)
15 const serverSharePromise = VideoShareModel.create({
14 actorId: serverActor.id, 16 actorId: serverActor.id,
15 videoId: video.id 17 videoId: video.id,
18 url: serverShareUrl
16 }, { transaction: t }) 19 }, { transaction: t })
17 20
18 const videoChannelShare = VideoShareModel.create({ 21 const videoChannelShareUrl = getAnnounceActivityPubUrl(video.url, video.VideoChannel.Actor)
22 const videoChannelSharePromise = VideoShareModel.create({
19 actorId: video.VideoChannel.actorId, 23 actorId: video.VideoChannel.actorId,
20 videoId: video.id 24 videoId: video.id,
25 url: videoChannelShareUrl
21 }, { transaction: t }) 26 }, { transaction: t })
22 27
23 await Promise.all([ 28 const [ serverShare, videoChannelShare ] = await Promise.all([
24 serverShare, 29 serverSharePromise,
25 videoChannelShare 30 videoChannelSharePromise
26 ]) 31 ])
27 32
28 return sendVideoAnnounceToFollowers(serverActor, video, t) 33 return Promise.all([
34 sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t),
35 sendVideoAnnounceToFollowers(serverActor, serverShare, video, t)
36 ])
29} 37}
30 38
31export { 39export {