]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process.ts
Fix user notifications on new follow
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process.ts
index 9dd241402dfd1a0bc227792d7e61cf1044c0534d..f4a92e341dc022f3846bd1de0759b8586e23a955 100644 (file)
@@ -15,8 +15,9 @@ import { getOrCreateActorAndServerAndModel } from '../actor'
 import { processDislikeActivity } from './process-dislike'
 import { processFlagActivity } from './process-flag'
 import { processViewActivity } from './process-view'
+import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
 
-const processActivity: { [ P in ActivityType ]: (activity: Activity, byActor: ActorModel, inboxActor?: ActorModel) => Promise<any> } = {
+const processActivity: { [ P in ActivityType ]: (options: APProcessorOptions<Activity>) => Promise<any> } = {
   Create: processCreateActivity,
   Update: processUpdateActivity,
   Delete: processDeleteActivity,
@@ -37,11 +38,15 @@ async function processActivities (
     signatureActor?: ActorModel
     inboxActor?: ActorModel
     outboxUrl?: string
-  } = {}) {
+    fromFetch?: boolean
+  } = {}
+) {
+  const { outboxUrl, signatureActor, inboxActor, fromFetch = false } = options
+
   const actorsCache: { [ url: string ]: ActorModel } = {}
 
   for (const activity of activities) {
-    if (!options.signatureActor && [ 'Create', 'Announce', 'Like' ].includes(activity.type) === false) {
+    if (!signatureActor && [ 'Create', 'Announce', 'Like' ].includes(activity.type) === false) {
       logger.error('Cannot process activity %s (type: %s) without the actor signature.', activity.id, activity.type)
       continue
     }
@@ -49,17 +54,17 @@ async function processActivities (
     const actorUrl = getAPId(activity.actor)
 
     // When we fetch remote data, we don't have signature
-    if (options.signatureActor && actorUrl !== options.signatureActor.url) {
-      logger.warn('Signature mismatch between %s and %s, skipping.', actorUrl, options.signatureActor.url)
+    if (signatureActor && actorUrl !== signatureActor.url) {
+      logger.warn('Signature mismatch between %s and %s, skipping.', actorUrl, signatureActor.url)
       continue
     }
 
-    if (options.outboxUrl && checkUrlsSameHost(options.outboxUrl, actorUrl) !== true) {
-      logger.warn('Host mismatch between outbox URL %s and actor URL %s, skipping.', options.outboxUrl, actorUrl)
+    if (outboxUrl && checkUrlsSameHost(outboxUrl, actorUrl) !== true) {
+      logger.warn('Host mismatch between outbox URL %s and actor URL %s, skipping.', outboxUrl, actorUrl)
       continue
     }
 
-    const byActor = options.signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl)
+    const byActor = signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl)
     actorsCache[actorUrl] = byActor
 
     const activityProcessor = processActivity[activity.type]
@@ -69,7 +74,7 @@ async function processActivities (
     }
 
     try {
-      await activityProcessor(activity, byActor, options.inboxActor)
+      await activityProcessor({ activity, byActor, inboxActor: inboxActor, fromFetch })
     } catch (err) {
       logger.warn('Cannot process activity %s.', activity.type, { err })
     }