aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/actor.ts5
-rw-r--r--server/lib/activitypub/process/process-accept.ts4
-rw-r--r--server/lib/activitypub/process/process-reject.ts4
-rw-r--r--server/lib/activitypub/process/process-undo.ts9
-rw-r--r--server/lib/activitypub/process/process.ts7
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'
5import * as uuidv4 from 'uuid/v4' 5import * as uuidv4 from 'uuid/v4'
6import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' 6import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub'
7import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' 7import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects'
8import { getActorUrl } from '../../helpers/activitypub'
8import { isActorObjectValid } from '../../helpers/custom-validators/activitypub/actor' 9import { isActorObjectValid } from '../../helpers/custom-validators/activitypub/actor'
9import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
10import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' 11import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils'
@@ -34,7 +35,9 @@ function setAsyncActorKeys (actor: ActorModel) {
34 }) 35 })
35} 36}
36 37
37async function getOrCreateActorAndServerAndModel (actorUrl: string, recurseIfNeeded = true) { 38async 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 @@
1import { ActivityAccept } from '../../../../shared/models/activitypub' 1import { ActivityAccept } from '../../../../shared/models/activitypub'
2import { getActorUrl } from '../../../helpers/activitypub'
2import { ActorModel } from '../../../models/activitypub/actor' 3import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 4import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4import { addFetchOutboxJob } from '../fetch' 5import { addFetchOutboxJob } from '../fetch'
@@ -6,7 +7,8 @@ import { addFetchOutboxJob } from '../fetch'
6async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) { 7async 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 @@
1import { ActivityReject } from '../../../../shared/models/activitypub/activity' 1import { ActivityReject } from '../../../../shared/models/activitypub/activity'
2import { getActorUrl } from '../../../helpers/activitypub'
2import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
3import { ActorModel } from '../../../models/activitypub/actor' 4import { ActorModel } from '../../../models/activitypub/actor'
4import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
@@ -6,7 +7,8 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6async function processRejectActivity (activity: ActivityReject, inboxActor?: ActorModel) { 7async 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 @@
1import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' 1import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub'
2import { DislikeObject } from '../../../../shared/models/activitypub/objects' 2import { DislikeObject } from '../../../../shared/models/activitypub/objects'
3import { getActorUrl } from '../../../helpers/activitypub'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
5import { sequelizeTypescript } from '../../../initializers' 6import { sequelizeTypescript } from '../../../initializers'
@@ -13,12 +14,14 @@ import { getOrCreateAccountAndVideoAndChannel } from '../videos'
13async function processUndoActivity (activity: ActivityUndo) { 14async 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 @@
1import { Activity, ActivityType } from '../../../../shared/models/activitypub' 1import { Activity, ActivityType } from '../../../../shared/models/activitypub'
2import { getActorUrl } from '../../../helpers/activitypub'
2import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
3import { ActorModel } from '../../../models/activitypub/actor' 4import { ActorModel } from '../../../models/activitypub/actor'
4import { processAcceptActivity } from './process-accept' 5import { processAcceptActivity } from './process-accept'
@@ -25,9 +26,11 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxActor?
25 26
26async function processActivities (activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel) { 27async 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