summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/update/index.ts
blob: b8dff733952f47fe233efbcb96dfaed947c63b5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { IRemoteUser } from '../../../../models/entities/user';
import { IUpdate, IObject } from '../../type';
import { apLogger } from '../../logger';
import { updateQuestion } from '../../models/question';

/**
 * Updateアクティビティを捌きます
 */
export default async (actor: IRemoteUser, activity: IUpdate): Promise<void> => {
	if ('actor' in activity && actor.uri !== activity.actor) {
		throw new Error('invalid actor');
	}

	apLogger.debug('Update');

	const object = activity.object as IObject;

	switch (object.type) {
		case 'Question':
			apLogger.debug('Question');
			await updateQuestion(object).catch(e => console.log(e));
			break;

		default:
			apLogger.warn(`Unknown type: ${object.type}`);
			break;
	}
};