diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-accept.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-follow.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/send/utils.ts | 21 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-follow.ts | 13 |
7 files changed, 41 insertions, 8 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index b67d9f08b..d84b465b2 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -352,7 +352,7 @@ async function refreshActorIfNeeded (actor: ActorModel): Promise<ActorModel> { | |||
352 | if (!actor.isOutdated()) return actor | 352 | if (!actor.isOutdated()) return actor |
353 | 353 | ||
354 | try { | 354 | try { |
355 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername, actor.getHost()) | 355 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername + '@' + actor.getHost()) |
356 | const result = await fetchRemoteActor(actorUrl) | 356 | const result = await fetchRemoteActor(actorUrl) |
357 | if (result === undefined) { | 357 | if (result === undefined) { |
358 | logger.warn('Cannot fetch remote actor in refresh actor.') | 358 | logger.warn('Cannot fetch remote actor in refresh actor.') |
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts index dfee1ec3e..ef679707b 100644 --- a/server/lib/activitypub/send/send-accept.ts +++ b/server/lib/activitypub/send/send-accept.ts | |||
@@ -10,6 +10,11 @@ async function sendAccept (actorFollow: ActorFollowModel) { | |||
10 | const follower = actorFollow.ActorFollower | 10 | const follower = actorFollow.ActorFollower |
11 | const me = actorFollow.ActorFollowing | 11 | const me = actorFollow.ActorFollowing |
12 | 12 | ||
13 | if (!follower.serverId) { // This should never happen | ||
14 | logger.warn('Do not sending accept to local follower.') | ||
15 | return | ||
16 | } | ||
17 | |||
13 | logger.info('Creating job to accept follower %s.', follower.url) | 18 | logger.info('Creating job to accept follower %s.', follower.url) |
14 | 19 | ||
15 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 20 | const followUrl = getActorFollowActivityPubUrl(actorFollow) |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index f7a8cf0b3..fc76cdd8a 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -33,6 +33,8 @@ async function sendCreateVideo (video: VideoModel, t: Transaction) { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { | 35 | async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { |
36 | if (!video.VideoChannel.Account.Actor.serverId) return // Local | ||
37 | |||
36 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | 38 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
37 | 39 | ||
38 | logger.info('Creating job to send video abuse %s.', url) | 40 | logger.info('Creating job to send video abuse %s.', url) |
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 2faffe6e7..46d08c17b 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts | |||
@@ -9,6 +9,9 @@ function sendFollow (actorFollow: ActorFollowModel) { | |||
9 | const me = actorFollow.ActorFollower | 9 | const me = actorFollow.ActorFollower |
10 | const following = actorFollow.ActorFollowing | 10 | const following = actorFollow.ActorFollowing |
11 | 11 | ||
12 | // Same server as ours | ||
13 | if (!following.serverId) return | ||
14 | |||
12 | logger.info('Creating job to send follow request to %s.', following.url) | 15 | logger.info('Creating job to send follow request to %s.', following.url) |
13 | 16 | ||
14 | const url = getActorFollowActivityPubUrl(actorFollow) | 17 | const url = getActorFollowActivityPubUrl(actorFollow) |
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 4e5dd3973..30d0fd98b 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -24,6 +24,9 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
24 | const me = actorFollow.ActorFollower | 24 | const me = actorFollow.ActorFollower |
25 | const following = actorFollow.ActorFollowing | 25 | const following = actorFollow.ActorFollowing |
26 | 26 | ||
27 | // Same server as ours | ||
28 | if (!following.serverId) return | ||
29 | |||
27 | logger.info('Creating job to send an unfollow request to %s.', following.url) | 30 | logger.info('Creating job to send an unfollow request to %s.', following.url) |
28 | 31 | ||
29 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 32 | const followUrl = getActorFollowActivityPubUrl(actorFollow) |
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index 0d28444ec..da437292e 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts | |||
@@ -6,6 +6,7 @@ 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' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { getActorsInvolvedInVideo } from '../audience' | 8 | import { getActorsInvolvedInVideo } from '../audience' |
9 | import { getServerActor } from '../../../helpers/utils' | ||
9 | 10 | ||
10 | async function forwardVideoRelatedActivity ( | 11 | async function forwardVideoRelatedActivity ( |
11 | activity: Activity, | 12 | activity: Activity, |
@@ -118,14 +119,28 @@ async function computeFollowerUris (toActorFollower: ActorModel[], actorsExcepti | |||
118 | const toActorFollowerIds = toActorFollower.map(a => a.id) | 119 | const toActorFollowerIds = toActorFollower.map(a => a.id) |
119 | 120 | ||
120 | const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t) | 121 | const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t) |
121 | const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl || f.inboxUrl) | 122 | const sharedInboxesException = await buildSharedInboxesException(actorsException) |
123 | |||
122 | return result.data.filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) | 124 | return result.data.filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) |
123 | } | 125 | } |
124 | 126 | ||
125 | async function computeUris (toActors: ActorModel[], actorsException: ActorModel[] = []) { | 127 | async function computeUris (toActors: ActorModel[], actorsException: ActorModel[] = []) { |
126 | const toActorSharedInboxesSet = new Set(toActors.map(a => a.sharedInboxUrl || a.inboxUrl)) | 128 | const serverActor = await getServerActor() |
129 | const targetUrls = toActors | ||
130 | .filter(a => a.id !== serverActor.id) // Don't send to ourselves | ||
131 | .map(a => a.sharedInboxUrl || a.inboxUrl) | ||
132 | |||
133 | const toActorSharedInboxesSet = new Set(targetUrls) | ||
127 | 134 | ||
128 | const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl || f.inboxUrl) | 135 | const sharedInboxesException = await buildSharedInboxesException(actorsException) |
129 | return Array.from(toActorSharedInboxesSet) | 136 | return Array.from(toActorSharedInboxesSet) |
130 | .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) | 137 | .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) |
131 | } | 138 | } |
139 | |||
140 | async function buildSharedInboxesException (actorsException: ActorModel[]) { | ||
141 | const serverActor = await getServerActor() | ||
142 | |||
143 | return actorsException | ||
144 | .map(f => f.sharedInboxUrl || f.inboxUrl) | ||
145 | .concat([ serverActor.sharedInboxUrl ]) | ||
146 | } | ||
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts index 393c6936c..282dde268 100644 --- a/server/lib/job-queue/handlers/activitypub-follow.ts +++ b/server/lib/job-queue/handlers/activitypub-follow.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { getServerActor } from '../../../helpers/utils' | 3 | import { getServerActor } from '../../../helpers/utils' |
4 | import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' | 4 | import { REMOTE_SCHEME, sequelizeTypescript } from '../../../initializers' |
5 | import { sendFollow } from '../../activitypub/send' | 5 | import { sendFollow } from '../../activitypub/send' |
6 | import { sanitizeHost } from '../../../helpers/core-utils' | 6 | import { sanitizeHost } from '../../../helpers/core-utils' |
7 | import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' | 7 | import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' |
@@ -11,6 +11,8 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |||
11 | import { ActorModel } from '../../../models/activitypub/actor' | 11 | import { ActorModel } from '../../../models/activitypub/actor' |
12 | 12 | ||
13 | export type ActivitypubFollowPayload = { | 13 | export type ActivitypubFollowPayload = { |
14 | followerActorId: number | ||
15 | name: string | ||
14 | host: string | 16 | host: string |
15 | } | 17 | } |
16 | 18 | ||
@@ -22,10 +24,10 @@ async function processActivityPubFollow (job: Bull.Job) { | |||
22 | 24 | ||
23 | const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP) | 25 | const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP) |
24 | 26 | ||
25 | const actorUrl = await loadActorUrlOrGetFromWebfinger(SERVER_ACTOR_NAME, sanitizedHost) | 27 | const actorUrl = await loadActorUrlOrGetFromWebfinger(payload.name + '@' + sanitizedHost) |
26 | const targetActor = await getOrCreateActorAndServerAndModel(actorUrl) | 28 | const targetActor = await getOrCreateActorAndServerAndModel(actorUrl) |
27 | 29 | ||
28 | const fromActor = await getServerActor() | 30 | const fromActor = await ActorModel.load(payload.followerActorId) |
29 | 31 | ||
30 | return retryTransactionWrapper(follow, fromActor, targetActor) | 32 | return retryTransactionWrapper(follow, fromActor, targetActor) |
31 | } | 33 | } |
@@ -42,6 +44,9 @@ function follow (fromActor: ActorModel, targetActor: ActorModel) { | |||
42 | throw new Error('Follower is the same than target actor.') | 44 | throw new Error('Follower is the same than target actor.') |
43 | } | 45 | } |
44 | 46 | ||
47 | // Same server, direct accept | ||
48 | const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending' | ||
49 | |||
45 | return sequelizeTypescript.transaction(async t => { | 50 | return sequelizeTypescript.transaction(async t => { |
46 | const [ actorFollow ] = await ActorFollowModel.findOrCreate({ | 51 | const [ actorFollow ] = await ActorFollowModel.findOrCreate({ |
47 | where: { | 52 | where: { |
@@ -49,7 +54,7 @@ function follow (fromActor: ActorModel, targetActor: ActorModel) { | |||
49 | targetActorId: targetActor.id | 54 | targetActorId: targetActor.id |
50 | }, | 55 | }, |
51 | defaults: { | 56 | defaults: { |
52 | state: 'pending', | 57 | state, |
53 | actorId: fromActor.id, | 58 | actorId: fromActor.id, |
54 | targetActorId: targetActor.id | 59 | targetActorId: targetActor.id |
55 | }, | 60 | }, |