2017-12-12 10:53:50 -06:00
|
|
|
import { Activity, ActivityType } from '../../../../shared/models/activitypub'
|
|
|
|
import { logger } from '../../../helpers'
|
|
|
|
import { AccountModel } from '../../../models/account/account'
|
2017-11-22 03:29:55 -06:00
|
|
|
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'
|
2017-11-23 07:19:55 -06:00
|
|
|
import { processLikeActivity } from './process-like'
|
2017-11-22 03:29:55 -06:00
|
|
|
import { processUndoActivity } from './process-undo'
|
|
|
|
import { processUpdateActivity } from './process-update'
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccount?: AccountModel) => Promise<any> } = {
|
2017-11-22 03:29:55 -06:00
|
|
|
Create: processCreateActivity,
|
|
|
|
Add: processAddActivity,
|
|
|
|
Update: processUpdateActivity,
|
|
|
|
Delete: processDeleteActivity,
|
|
|
|
Follow: processFollowActivity,
|
|
|
|
Accept: processAcceptActivity,
|
|
|
|
Announce: processAnnounceActivity,
|
2017-11-23 07:19:55 -06:00
|
|
|
Undo: processUndoActivity,
|
|
|
|
Like: processLikeActivity
|
2017-11-22 03:29:55 -06:00
|
|
|
}
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function processActivities (activities: Activity[], signatureAccount?: AccountModel, inboxAccount?: AccountModel) {
|
2017-11-22 03:29:55 -06:00
|
|
|
for (const activity of activities) {
|
2017-11-24 07:36:28 -06:00
|
|
|
// When we fetch remote data, we don't have signature
|
|
|
|
if (signatureAccount && activity.actor !== signatureAccount.url) {
|
|
|
|
logger.warn('Signature mismatch between %s and %s.', activity.actor, signatureAccount.url)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-11-22 03:29:55 -06:00
|
|
|
const activityProcessor = processActivity[activity.type]
|
|
|
|
if (activityProcessor === undefined) {
|
|
|
|
logger.warn('Unknown activity type %s.', activity.type, { activityId: activity.id })
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:55:13 -06:00
|
|
|
try {
|
|
|
|
await activityProcessor(activity, inboxAccount)
|
|
|
|
} catch (err) {
|
|
|
|
logger.warn('Cannot process activity %s.', activity.type, err)
|
|
|
|
}
|
2017-11-22 03:29:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
processActivities
|
|
|
|
}
|