diff options
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/actor.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-accept.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-reject.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 9 | ||||
-rw-r--r-- | server/lib/activitypub/process/process.ts | 7 |
5 files changed, 21 insertions, 8 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index b7114bbee..fa31e71c7 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -5,6 +5,7 @@ import * as url from 'url' | |||
5 | import * as uuidv4 from 'uuid/v4' | 5 | import * as uuidv4 from 'uuid/v4' |
6 | import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' | 6 | import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' |
7 | import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' | 7 | import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' |
8 | import { getActorUrl } from '../../helpers/activitypub' | ||
8 | import { isActorObjectValid } from '../../helpers/custom-validators/activitypub/actor' | 9 | import { isActorObjectValid } from '../../helpers/custom-validators/activitypub/actor' |
9 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 10 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
10 | import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' | 11 | import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' |
@@ -34,7 +35,9 @@ function setAsyncActorKeys (actor: ActorModel) { | |||
34 | }) | 35 | }) |
35 | } | 36 | } |
36 | 37 | ||
37 | async function getOrCreateActorAndServerAndModel (actorUrl: string, recurseIfNeeded = true) { | 38 | async function getOrCreateActorAndServerAndModel (activityActor: string | ActivityPubActor, recurseIfNeeded = true) { |
39 | const actorUrl = getActorUrl(activityActor) | ||
40 | |||
38 | let actor = await ActorModel.loadByUrl(actorUrl) | 41 | let actor = await ActorModel.loadByUrl(actorUrl) |
39 | 42 | ||
40 | // We don't have this actor in our database, fetch it on remote | 43 | // We don't have this actor in our database, fetch it on remote |
diff --git a/server/lib/activitypub/process/process-accept.ts b/server/lib/activitypub/process/process-accept.ts index 7db2f8ff0..c55b57820 100644 --- a/server/lib/activitypub/process/process-accept.ts +++ b/server/lib/activitypub/process/process-accept.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { ActivityAccept } from '../../../../shared/models/activitypub' | 1 | import { ActivityAccept } from '../../../../shared/models/activitypub' |
2 | import { getActorUrl } from '../../../helpers/activitypub' | ||
2 | import { ActorModel } from '../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 4 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
4 | import { addFetchOutboxJob } from '../fetch' | 5 | import { addFetchOutboxJob } from '../fetch' |
@@ -6,7 +7,8 @@ import { addFetchOutboxJob } from '../fetch' | |||
6 | async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) { | 7 | async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) { |
7 | if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.') | 8 | if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.') |
8 | 9 | ||
9 | const targetActor = await ActorModel.loadByUrl(activity.actor) | 10 | const actorUrl = getActorUrl(activity.actor) |
11 | const targetActor = await ActorModel.loadByUrl(actorUrl) | ||
10 | 12 | ||
11 | return processAccept(inboxActor, targetActor) | 13 | return processAccept(inboxActor, targetActor) |
12 | } | 14 | } |
diff --git a/server/lib/activitypub/process/process-reject.ts b/server/lib/activitypub/process/process-reject.ts index b2de28d79..f06b03772 100644 --- a/server/lib/activitypub/process/process-reject.ts +++ b/server/lib/activitypub/process/process-reject.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { ActivityReject } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityReject } from '../../../../shared/models/activitypub/activity' |
2 | import { getActorUrl } from '../../../helpers/activitypub' | ||
2 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
3 | import { ActorModel } from '../../../models/activitypub/actor' | 4 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
@@ -6,7 +7,8 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |||
6 | async function processRejectActivity (activity: ActivityReject, inboxActor?: ActorModel) { | 7 | async function processRejectActivity (activity: ActivityReject, inboxActor?: ActorModel) { |
7 | if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.') | 8 | if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.') |
8 | 9 | ||
9 | const targetActor = await ActorModel.loadByUrl(activity.actor) | 10 | const actorUrl = getActorUrl(activity.actor) |
11 | const targetActor = await ActorModel.loadByUrl(actorUrl) | ||
10 | 12 | ||
11 | return processReject(inboxActor, targetActor) | 13 | return processReject(inboxActor, targetActor) |
12 | } | 14 | } |
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 5a770bb97..565e70289 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' | 2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' |
3 | import { getActorUrl } from '../../../helpers/activitypub' | ||
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
5 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
@@ -13,12 +14,14 @@ import { getOrCreateAccountAndVideoAndChannel } from '../videos' | |||
13 | async function processUndoActivity (activity: ActivityUndo) { | 14 | async function processUndoActivity (activity: ActivityUndo) { |
14 | const activityToUndo = activity.object | 15 | const activityToUndo = activity.object |
15 | 16 | ||
17 | const actorUrl = getActorUrl(activity.actor) | ||
18 | |||
16 | if (activityToUndo.type === 'Like') { | 19 | if (activityToUndo.type === 'Like') { |
17 | return processUndoLike(activity.actor, activity) | 20 | return processUndoLike(actorUrl, activity) |
18 | } else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') { | 21 | } else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') { |
19 | return processUndoDislike(activity.actor, activity) | 22 | return processUndoDislike(actorUrl, activity) |
20 | } else if (activityToUndo.type === 'Follow') { | 23 | } else if (activityToUndo.type === 'Follow') { |
21 | return processUndoFollow(activity.actor, activityToUndo) | 24 | return processUndoFollow(actorUrl, activityToUndo) |
22 | } | 25 | } |
23 | 26 | ||
24 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) | 27 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) |
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts index 094219489..10d8ba189 100644 --- a/server/lib/activitypub/process/process.ts +++ b/server/lib/activitypub/process/process.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' | 1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
2 | import { getActorUrl } from '../../../helpers/activitypub' | ||
2 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
3 | import { ActorModel } from '../../../models/activitypub/actor' | 4 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { processAcceptActivity } from './process-accept' | 5 | import { processAcceptActivity } from './process-accept' |
@@ -25,9 +26,11 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxActor? | |||
25 | 26 | ||
26 | async function processActivities (activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel) { | 27 | async function processActivities (activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel) { |
27 | for (const activity of activities) { | 28 | for (const activity of activities) { |
29 | const actorUrl = getActorUrl(activity.actor) | ||
30 | |||
28 | // When we fetch remote data, we don't have signature | 31 | // When we fetch remote data, we don't have signature |
29 | if (signatureActor && activity.actor !== signatureActor.url) { | 32 | if (signatureActor && actorUrl !== signatureActor.url) { |
30 | logger.warn('Signature mismatch between %s and %s.', activity.actor, signatureActor.url) | 33 | logger.warn('Signature mismatch between %s and %s.', actorUrl, signatureActor.url) |
31 | continue | 34 | continue |
32 | } | 35 | } |
33 | 36 | ||