misskey/src/remote/activitypub/kernel/index.ts

52 lines
977 B
TypeScript
Raw Normal View History

2018-04-07 10:05:14 +02:00
import { Object } from '../type';
import { IRemoteUser } from '../../../models/user';
2018-03-31 12:55:00 +02:00
import create from './create';
2018-04-03 10:50:52 +02:00
import performDeleteActivity from './delete';
2018-04-02 12:50:40 +02:00
import follow from './follow';
2018-04-03 09:33:16 +02:00
import undo from './undo';
2018-04-07 10:05:14 +02:00
import like from './like';
2018-04-07 23:55:26 +02:00
import announce from './announce';
2018-04-04 16:12:35 +02:00
2018-04-07 09:36:40 +02:00
const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
2018-04-04 16:12:35 +02:00
switch (activity.type) {
case 'Create':
2018-04-04 18:22:41 +02:00
await create(actor, activity);
2018-04-04 16:12:35 +02:00
break;
case 'Delete':
2018-04-04 18:22:41 +02:00
await performDeleteActivity(actor, activity);
2018-04-04 16:12:35 +02:00
break;
case 'Follow':
2018-04-04 18:22:41 +02:00
await follow(actor, activity);
2018-04-04 16:12:35 +02:00
break;
2018-04-05 12:19:00 +02:00
case 'Accept':
// noop
break;
2018-04-07 23:55:26 +02:00
case 'Announce':
await announce(actor, activity);
break;
2018-04-07 10:05:14 +02:00
case 'Like':
await like(actor, activity);
break;
2018-04-04 16:12:35 +02:00
case 'Undo':
2018-04-04 18:22:41 +02:00
await undo(actor, activity);
2018-04-04 16:12:35 +02:00
break;
2018-04-06 17:07:30 +02:00
case 'Collection':
case 'OrderedCollection':
// TODO
break;
2018-04-04 16:12:35 +02:00
default:
2018-04-07 10:05:14 +02:00
console.warn(`unknown activity type: ${(activity as any).type}`);
2018-04-04 16:12:35 +02:00
return null;
}
2018-04-01 14:17:46 +02:00
};
2018-04-06 17:07:30 +02:00
export default self;