1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Fix user notifications on new follow

This commit is contained in:
Chocobozzz 2019-08-02 10:53:36 +02:00
parent 44b88f180b
commit 1198edf4bb
No known key found for this signature in database
GPG key ID: 583A612D890159BE
17 changed files with 82 additions and 36 deletions

View 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 })
}