diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-31 10:23:56 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-31 10:23:56 +0200 |
commit | 9588d4f49b7183631ddb97fa9c3cd79f9bfe2945 (patch) | |
tree | cbd0353ddc0129afa2c8827f27c0665c5c127225 /server/lib/activitypub | |
parent | 3f9b33b02bed9e02af5520394e09805c46716101 (diff) | |
download | PeerTube-9588d4f49b7183631ddb97fa9c3cd79f9bfe2945.tar.gz PeerTube-9588d4f49b7183631ddb97fa9c3cd79f9bfe2945.tar.zst PeerTube-9588d4f49b7183631ddb97fa9c3cd79f9bfe2945.zip |
Correctly forward video related activities
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-announce.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 12 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 6 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 18 | ||||
-rw-r--r-- | server/lib/activitypub/send/utils.ts | 18 |
5 files changed, 42 insertions, 17 deletions
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index a6e1e2d47..4e50da8d2 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts | |||
@@ -5,7 +5,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
5 | import { VideoModel } from '../../../models/video/video' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
7 | import { getOrCreateActorAndServerAndModel } from '../actor' | 7 | import { getOrCreateActorAndServerAndModel } from '../actor' |
8 | import { forwardActivity } from '../send/utils' | 8 | import { forwardVideoRelatedActivity } from '../send/utils' |
9 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 9 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
10 | 10 | ||
11 | async function processAnnounceActivity (activity: ActivityAnnounce) { | 11 | async function processAnnounceActivity (activity: ActivityAnnounce) { |
@@ -58,7 +58,8 @@ async function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounc | |||
58 | if (video.isOwned() && created === true) { | 58 | if (video.isOwned() && created === true) { |
59 | // Don't resend the activity to the sender | 59 | // Don't resend the activity to the sender |
60 | const exceptions = [ actorAnnouncer ] | 60 | const exceptions = [ actorAnnouncer ] |
61 | await forwardActivity(activity, t, exceptions) | 61 | |
62 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | ||
62 | } | 63 | } |
63 | 64 | ||
64 | return undefined | 65 | return undefined |
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 99a5f6f9c..38dacf772 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -9,10 +9,9 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
9 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 9 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
10 | import { VideoCommentModel } from '../../../models/video/video-comment' | 10 | import { VideoCommentModel } from '../../../models/video/video-comment' |
11 | import { getOrCreateActorAndServerAndModel } from '../actor' | 11 | import { getOrCreateActorAndServerAndModel } from '../actor' |
12 | import { getActorsInvolvedInVideo } from '../audience' | ||
13 | import { resolveThread } from '../video-comments' | 12 | import { resolveThread } from '../video-comments' |
14 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 13 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
15 | import { forwardActivity } from '../send/utils' | 14 | import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' |
16 | 15 | ||
17 | async function processCreateActivity (activity: ActivityCreate) { | 16 | async function processCreateActivity (activity: ActivityCreate) { |
18 | const activityObject = activity.object | 17 | const activityObject = activity.object |
@@ -87,7 +86,8 @@ async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate | |||
87 | if (video.isOwned() && created === true) { | 86 | if (video.isOwned() && created === true) { |
88 | // Don't resend the activity to the sender | 87 | // Don't resend the activity to the sender |
89 | const exceptions = [ byActor ] | 88 | const exceptions = [ byActor ] |
90 | await forwardActivity(activity, t, exceptions) | 89 | |
90 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | ||
91 | } | 91 | } |
92 | }) | 92 | }) |
93 | } | 93 | } |
@@ -190,11 +190,7 @@ async function createVideoComment (byActor: ActorModel, activity: ActivityCreate | |||
190 | // Don't resend the activity to the sender | 190 | // Don't resend the activity to the sender |
191 | const exceptions = [ byActor ] | 191 | const exceptions = [ byActor ] |
192 | 192 | ||
193 | // Mastodon does not add our announces in audience, so we forward to them manually | 193 | await forwardVideoRelatedActivity(activity, t, exceptions, video) |
194 | const additionalActors = await getActorsInvolvedInVideo(video, t) | ||
195 | const additionalFollowerUrls = additionalActors.map(a => a.followersUrl) | ||
196 | |||
197 | await forwardActivity(activity, t, exceptions, additionalFollowerUrls) | ||
198 | } | 194 | } |
199 | }) | 195 | }) |
200 | } | 196 | } |
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index d219e76eb..f1642f038 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -4,8 +4,9 @@ import { sequelizeTypescript } from '../../../initializers' | |||
4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { getOrCreateActorAndServerAndModel } from '../actor' | 6 | import { getOrCreateActorAndServerAndModel } from '../actor' |
7 | import { forwardActivity } from '../send/utils' | 7 | import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' |
8 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 8 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
9 | import { getActorsInvolvedInVideo } from '../audience' | ||
9 | 10 | ||
10 | async function processLikeActivity (activity: ActivityLike) { | 11 | async function processLikeActivity (activity: ActivityLike) { |
11 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | 12 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) |
@@ -54,7 +55,8 @@ async function createVideoLike (byActor: ActorModel, activity: ActivityLike) { | |||
54 | if (video.isOwned() && created === true) { | 55 | if (video.isOwned() && created === true) { |
55 | // Don't resend the activity to the sender | 56 | // Don't resend the activity to the sender |
56 | const exceptions = [ byActor ] | 57 | const exceptions = [ byActor ] |
57 | await forwardActivity(activity, t, exceptions) | 58 | |
59 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | ||
58 | } | 60 | } |
59 | }) | 61 | }) |
60 | } | 62 | } |
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index d023f7029..37db58e1a 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -8,7 +8,7 @@ import { AccountModel } from '../../../models/account/account' | |||
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { ActorModel } from '../../../models/activitypub/actor' | 9 | import { ActorModel } from '../../../models/activitypub/actor' |
10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
11 | import { forwardActivity } from '../send/utils' | 11 | import { forwardVideoRelatedActivity } from '../send/utils' |
12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
13 | import { VideoShareModel } from '../../../models/video/video-share' | 13 | import { VideoShareModel } from '../../../models/video/video-share' |
14 | 14 | ||
@@ -67,7 +67,8 @@ async function undoLike (actorUrl: string, activity: ActivityUndo) { | |||
67 | if (video.isOwned()) { | 67 | if (video.isOwned()) { |
68 | // Don't resend the activity to the sender | 68 | // Don't resend the activity to the sender |
69 | const exceptions = [ byAccount.Actor ] | 69 | const exceptions = [ byAccount.Actor ] |
70 | await forwardActivity(activity, t, exceptions) | 70 | |
71 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | ||
71 | } | 72 | } |
72 | }) | 73 | }) |
73 | } | 74 | } |
@@ -99,7 +100,8 @@ async function undoDislike (actorUrl: string, activity: ActivityUndo) { | |||
99 | if (video.isOwned()) { | 100 | if (video.isOwned()) { |
100 | // Don't resend the activity to the sender | 101 | // Don't resend the activity to the sender |
101 | const exceptions = [ byAccount.Actor ] | 102 | const exceptions = [ byAccount.Actor ] |
102 | await forwardActivity(activity, t, exceptions) | 103 | |
104 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | ||
103 | } | 105 | } |
104 | }) | 106 | }) |
105 | } | 107 | } |
@@ -138,11 +140,19 @@ function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnoun | |||
138 | 140 | ||
139 | function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { | 141 | function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { |
140 | return sequelizeTypescript.transaction(async t => { | 142 | return sequelizeTypescript.transaction(async t => { |
143 | const byAccount = await AccountModel.loadByUrl(actorUrl, t) | ||
144 | if (!byAccount) throw new Error('Unknown account ' + actorUrl) | ||
145 | |||
141 | const share = await VideoShareModel.loadByUrl(announceActivity.id, t) | 146 | const share = await VideoShareModel.loadByUrl(announceActivity.id, t) |
142 | if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`) | 147 | if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`) |
143 | 148 | ||
144 | await share.destroy({ transaction: t }) | 149 | await share.destroy({ transaction: t }) |
145 | 150 | ||
146 | return undefined | 151 | if (share.Video.isOwned()) { |
152 | // Don't resend the activity to the sender | ||
153 | const exceptions = [ byAccount.Actor ] | ||
154 | |||
155 | await forwardVideoRelatedActivity(announceActivity, t, exceptions, share.Video) | ||
156 | } | ||
147 | }) | 157 | }) |
148 | } | 158 | } |
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index 80d4463ff..241db6c8c 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts | |||
@@ -4,6 +4,21 @@ import { logger } from '../../../helpers/logger' | |||
4 | import { ActorModel } from '../../../models/activitypub/actor' | 4 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
6 | import { JobQueue } from '../../job-queue' | 6 | import { JobQueue } from '../../job-queue' |
7 | import { VideoModel } from '../../../models/video/video' | ||
8 | import { getActorsInvolvedInVideo } from '../audience' | ||
9 | |||
10 | async function forwardVideoRelatedActivity ( | ||
11 | activity: Activity, | ||
12 | t: Transaction, | ||
13 | followersException: ActorModel[] = [], | ||
14 | video: VideoModel | ||
15 | ) { | ||
16 | // Mastodon does not add our announces in audience, so we forward to them manually | ||
17 | const additionalActors = await getActorsInvolvedInVideo(video, t) | ||
18 | const additionalFollowerUrls = additionalActors.map(a => a.followersUrl) | ||
19 | |||
20 | return forwardActivity(activity, t, followersException, additionalFollowerUrls) | ||
21 | } | ||
7 | 22 | ||
8 | async function forwardActivity ( | 23 | async function forwardActivity ( |
9 | activity: Activity, | 24 | activity: Activity, |
@@ -91,7 +106,8 @@ export { | |||
91 | broadcastToFollowers, | 106 | broadcastToFollowers, |
92 | unicastTo, | 107 | unicastTo, |
93 | forwardActivity, | 108 | forwardActivity, |
94 | broadcastToActors | 109 | broadcastToActors, |
110 | forwardVideoRelatedActivity | ||
95 | } | 111 | } |
96 | 112 | ||
97 | // --------------------------------------------------------------------------- | 113 | // --------------------------------------------------------------------------- |