2017-12-12 11:53:50 -05:00
|
|
|
import { Activity, ActivityType } from '../../../../shared/models/activitypub'
|
2017-12-28 05:16:08 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-12-14 11:38:41 -05:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-11-22 04:29:55 -05:00
|
|
|
import { processAcceptActivity } from './process-accept'
|
|
|
|
import { processAnnounceActivity } from './process-announce'
|
|
|
|
import { processCreateActivity } from './process-create'
|
|
|
|
import { processDeleteActivity } from './process-delete'
|
|
|
|
import { processFollowActivity } from './process-follow'
|
2017-11-23 08:19:55 -05:00
|
|
|
import { processLikeActivity } from './process-like'
|
2017-11-22 04:29:55 -05:00
|
|
|
import { processUndoActivity } from './process-undo'
|
|
|
|
import { processUpdateActivity } from './process-update'
|
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxActor?: ActorModel) => Promise<any> } = {
|
2017-11-22 04:29:55 -05:00
|
|
|
Create: processCreateActivity,
|
|
|
|
Update: processUpdateActivity,
|
|
|
|
Delete: processDeleteActivity,
|
|
|
|
Follow: processFollowActivity,
|
|
|
|
Accept: processAcceptActivity,
|
|
|
|
Announce: processAnnounceActivity,
|
2017-11-23 08:19:55 -05:00
|
|
|
Undo: processUndoActivity,
|
|
|
|
Like: processLikeActivity
|
2017-11-22 04:29:55 -05:00
|
|
|
}
|
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
async function processActivities (activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel) {
|
2017-11-22 04:29:55 -05:00
|
|
|
for (const activity of activities) {
|
2017-11-24 08:36:28 -05:00
|
|
|
// When we fetch remote data, we don't have signature
|
2017-12-14 11:38:41 -05:00
|
|
|
if (signatureActor && activity.actor !== signatureActor.url) {
|
|
|
|
logger.warn('Signature mismatch between %s and %s.', activity.actor, signatureActor.url)
|
2017-11-24 08:36:28 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-11-22 04:29:55 -05:00
|
|
|
const activityProcessor = processActivity[activity.type]
|
|
|
|
if (activityProcessor === undefined) {
|
|
|
|
logger.warn('Unknown activity type %s.', activity.type, { activityId: activity.id })
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-11-23 10:55:13 -05:00
|
|
|
try {
|
2017-12-14 11:38:41 -05:00
|
|
|
await activityProcessor(activity, inboxActor)
|
2017-11-23 10:55:13 -05:00
|
|
|
} catch (err) {
|
|
|
|
logger.warn('Cannot process activity %s.', activity.type, err)
|
|
|
|
}
|
2017-11-22 04:29:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
processActivities
|
|
|
|
}
|