From c986175d68a18e96fbd41537a05c7796a2c64f38 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 22 Nov 2017 10:29:55 +0100 Subject: Fetch outbox to grab old activities --- server/lib/activitypub/process/index.ts | 1 + server/lib/activitypub/process/process.ts | 38 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 server/lib/activitypub/process/process.ts (limited to 'server/lib/activitypub/process') diff --git a/server/lib/activitypub/process/index.ts b/server/lib/activitypub/process/index.ts index e80b46b6f..c68312053 100644 --- a/server/lib/activitypub/process/index.ts +++ b/server/lib/activitypub/process/index.ts @@ -1,3 +1,4 @@ +export * from './process' export * from './process-accept' export * from './process-add' export * from './process-announce' diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts new file mode 100644 index 000000000..613597341 --- /dev/null +++ b/server/lib/activitypub/process/process.ts @@ -0,0 +1,38 @@ +import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' +import { AccountInstance } from '../../../models/account/account-interface' +import { processAcceptActivity } from './process-accept' +import { processAddActivity } from './process-add' +import { processAnnounceActivity } from './process-announce' +import { processCreateActivity } from './process-create' +import { processDeleteActivity } from './process-delete' +import { processFollowActivity } from './process-follow' +import { processUndoActivity } from './process-undo' +import { processUpdateActivity } from './process-update' +import { logger } from '../../../helpers/logger' + +const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccount?: AccountInstance) => Promise } = { + Create: processCreateActivity, + Add: processAddActivity, + Update: processUpdateActivity, + Delete: processDeleteActivity, + Follow: processFollowActivity, + Accept: processAcceptActivity, + Announce: processAnnounceActivity, + Undo: processUndoActivity +} + +async function processActivities (activities: Activity[], inboxAccount?: AccountInstance) { + for (const activity of activities) { + const activityProcessor = processActivity[activity.type] + if (activityProcessor === undefined) { + logger.warn('Unknown activity type %s.', activity.type, { activityId: activity.id }) + continue + } + + await activityProcessor(activity, inboxAccount) + } +} + +export { + processActivities +} -- cgit v1.2.3