2018-04-06 19:35:23 +09:00
|
|
|
import Resolver from '../../resolver';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { IRemoteUser } from '../../../../models/entities/user';
|
2019-03-06 22:55:47 +09:00
|
|
|
import createNote from './note';
|
2021-05-31 13:04:13 +09:00
|
|
|
import { ICreate, getApId, isPost, getApType } from '../../type';
|
2019-02-03 18:16:57 +09:00
|
|
|
import { apLogger } from '../../logger';
|
2020-02-08 21:40:06 +09:00
|
|
|
import { toArray, concat, unique } from '../../../../prelude/array';
|
2018-04-06 19:35:23 +09:00
|
|
|
|
2019-02-03 18:16:57 +09:00
|
|
|
const logger = apLogger;
|
2018-04-06 19:35:23 +09:00
|
|
|
|
2018-04-07 16:14:35 +09:00
|
|
|
export default async (actor: IRemoteUser, activity: ICreate): Promise<void> => {
|
2019-06-28 18:54:10 +09:00
|
|
|
const uri = getApId(activity);
|
2018-04-06 19:35:23 +09:00
|
|
|
|
2019-02-03 18:16:57 +09:00
|
|
|
logger.info(`Create: ${uri}`);
|
2018-04-06 19:35:23 +09:00
|
|
|
|
2020-02-08 21:40:06 +09:00
|
|
|
// copy audiences between activity <=> object.
|
|
|
|
if (typeof activity.object === 'object') {
|
|
|
|
const to = unique(concat([toArray(activity.to), toArray(activity.object.to)]));
|
|
|
|
const cc = unique(concat([toArray(activity.cc), toArray(activity.object.cc)]));
|
|
|
|
|
|
|
|
activity.to = to;
|
|
|
|
activity.cc = cc;
|
|
|
|
activity.object.to = to;
|
|
|
|
activity.object.cc = cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no attributedTo, use Activity actor.
|
|
|
|
if (typeof activity.object === 'object' && !activity.object.attributedTo) {
|
|
|
|
activity.object.attributedTo = activity.actor;
|
|
|
|
}
|
|
|
|
|
2018-04-06 19:35:23 +09:00
|
|
|
const resolver = new Resolver();
|
|
|
|
|
2019-11-18 06:23:44 +09:00
|
|
|
const object = await resolver.resolve(activity.object).catch(e => {
|
2019-02-03 18:16:57 +09:00
|
|
|
logger.error(`Resolution failed: ${e}`);
|
2018-04-06 19:35:23 +09:00
|
|
|
throw e;
|
2019-11-18 06:23:44 +09:00
|
|
|
});
|
2018-04-06 19:35:23 +09:00
|
|
|
|
2021-05-31 13:04:13 +09:00
|
|
|
if (isPost(object)) {
|
2020-01-30 18:58:13 +09:00
|
|
|
createNote(resolver, actor, object, false, activity);
|
2019-06-28 18:54:10 +09:00
|
|
|
} else {
|
2021-05-31 13:04:13 +09:00
|
|
|
logger.warn(`Unknown type: ${getApType(object)}`);
|
2018-04-06 19:35:23 +09:00
|
|
|
}
|
|
|
|
};
|