diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-02 10:53:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-02 10:53:36 +0200 |
commit | 1198edf4bb06ce5f1668b97cf9ca8fb483fe3f41 (patch) | |
tree | 0378e6f2ec9912a80838f373ec2d09c3b805b7b6 /server/lib/activitypub/process/process.ts | |
parent | 44b88f180bc9ec692885e7db08757a43b3e2df79 (diff) | |
download | PeerTube-1198edf4bb06ce5f1668b97cf9ca8fb483fe3f41.tar.gz PeerTube-1198edf4bb06ce5f1668b97cf9ca8fb483fe3f41.tar.zst PeerTube-1198edf4bb06ce5f1668b97cf9ca8fb483fe3f41.zip |
Fix user notifications on new follow
Diffstat (limited to 'server/lib/activitypub/process/process.ts')
-rw-r--r-- | server/lib/activitypub/process/process.ts | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts index 9dd241402..f4a92e341 100644 --- a/server/lib/activitypub/process/process.ts +++ b/server/lib/activitypub/process/process.ts | |||
@@ -15,8 +15,9 @@ import { getOrCreateActorAndServerAndModel } from '../actor' | |||
15 | import { processDislikeActivity } from './process-dislike' | 15 | import { processDislikeActivity } from './process-dislike' |
16 | import { processFlagActivity } from './process-flag' | 16 | import { processFlagActivity } from './process-flag' |
17 | import { processViewActivity } from './process-view' | 17 | import { processViewActivity } from './process-view' |
18 | import { APProcessorOptions } from '../../../typings/activitypub-processor.model' | ||
18 | 19 | ||
19 | const processActivity: { [ P in ActivityType ]: (activity: Activity, byActor: ActorModel, inboxActor?: ActorModel) => Promise<any> } = { | 20 | const processActivity: { [ P in ActivityType ]: (options: APProcessorOptions<Activity>) => Promise<any> } = { |
20 | Create: processCreateActivity, | 21 | Create: processCreateActivity, |
21 | Update: processUpdateActivity, | 22 | Update: processUpdateActivity, |
22 | Delete: processDeleteActivity, | 23 | Delete: processDeleteActivity, |
@@ -37,11 +38,15 @@ async function processActivities ( | |||
37 | signatureActor?: ActorModel | 38 | signatureActor?: ActorModel |
38 | inboxActor?: ActorModel | 39 | inboxActor?: ActorModel |
39 | outboxUrl?: string | 40 | outboxUrl?: string |
40 | } = {}) { | 41 | fromFetch?: boolean |
42 | } = {} | ||
43 | ) { | ||
44 | const { outboxUrl, signatureActor, inboxActor, fromFetch = false } = options | ||
45 | |||
41 | const actorsCache: { [ url: string ]: ActorModel } = {} | 46 | const actorsCache: { [ url: string ]: ActorModel } = {} |
42 | 47 | ||
43 | for (const activity of activities) { | 48 | for (const activity of activities) { |
44 | if (!options.signatureActor && [ 'Create', 'Announce', 'Like' ].includes(activity.type) === false) { | 49 | if (!signatureActor && [ 'Create', 'Announce', 'Like' ].includes(activity.type) === false) { |
45 | logger.error('Cannot process activity %s (type: %s) without the actor signature.', activity.id, activity.type) | 50 | logger.error('Cannot process activity %s (type: %s) without the actor signature.', activity.id, activity.type) |
46 | continue | 51 | continue |
47 | } | 52 | } |
@@ -49,17 +54,17 @@ async function processActivities ( | |||
49 | const actorUrl = getAPId(activity.actor) | 54 | const actorUrl = getAPId(activity.actor) |
50 | 55 | ||
51 | // When we fetch remote data, we don't have signature | 56 | // When we fetch remote data, we don't have signature |
52 | if (options.signatureActor && actorUrl !== options.signatureActor.url) { | 57 | if (signatureActor && actorUrl !== signatureActor.url) { |
53 | logger.warn('Signature mismatch between %s and %s, skipping.', actorUrl, options.signatureActor.url) | 58 | logger.warn('Signature mismatch between %s and %s, skipping.', actorUrl, signatureActor.url) |
54 | continue | 59 | continue |
55 | } | 60 | } |
56 | 61 | ||
57 | if (options.outboxUrl && checkUrlsSameHost(options.outboxUrl, actorUrl) !== true) { | 62 | if (outboxUrl && checkUrlsSameHost(outboxUrl, actorUrl) !== true) { |
58 | logger.warn('Host mismatch between outbox URL %s and actor URL %s, skipping.', options.outboxUrl, actorUrl) | 63 | logger.warn('Host mismatch between outbox URL %s and actor URL %s, skipping.', outboxUrl, actorUrl) |
59 | continue | 64 | continue |
60 | } | 65 | } |
61 | 66 | ||
62 | const byActor = options.signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl) | 67 | const byActor = signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl) |
63 | actorsCache[actorUrl] = byActor | 68 | actorsCache[actorUrl] = byActor |
64 | 69 | ||
65 | const activityProcessor = processActivity[activity.type] | 70 | const activityProcessor = processActivity[activity.type] |
@@ -69,7 +74,7 @@ async function processActivities ( | |||
69 | } | 74 | } |
70 | 75 | ||
71 | try { | 76 | try { |
72 | await activityProcessor(activity, byActor, options.inboxActor) | 77 | await activityProcessor({ activity, byActor, inboxActor: inboxActor, fromFetch }) |
73 | } catch (err) { | 78 | } catch (err) { |
74 | logger.warn('Cannot process activity %s.', activity.type, { err }) | 79 | logger.warn('Cannot process activity %s.', activity.type, { err }) |
75 | } | 80 | } |