sharkey/src/remote/activitypub/act/index.ts

33 lines
854 B
TypeScript
Raw Normal View History

2018-03-31 19:55:00 +09:00
import create from './create';
2018-04-02 19:50:40 +09:00
import follow from './follow';
2018-04-03 16:33:16 +09:00
import undo from './undo';
2018-03-31 19:55:00 +09:00
import createObject from '../create';
2018-04-03 20:09:26 +09:00
import Resolver from '../resolver';
2018-03-31 19:55:00 +09:00
export default async (parentResolver: Resolver, actor, value, distribute?: boolean) => {
const collection = await parentResolver.resolveCollection(value);
return collection.object.map(async element => {
const { resolver, object } = await collection.resolver.resolveOne(element);
const created = await (await createObject(resolver, actor, [object], distribute))[0];
2018-03-31 19:55:00 +09:00
if (created !== null) {
return created;
}
switch (object.type) {
2018-03-31 19:55:00 +09:00
case 'Create':
return create(resolver, actor, object, distribute);
2018-03-31 19:55:00 +09:00
2018-04-02 19:50:40 +09:00
case 'Follow':
return follow(resolver, actor, object, distribute);
2018-04-03 16:33:16 +09:00
case 'Undo':
return undo(resolver, actor, object);
2018-04-02 19:50:40 +09:00
2018-03-31 19:55:00 +09:00
default:
return null;
}
});
2018-04-01 21:17:46 +09:00
};