2018-04-07 21:55:26 +00:00
|
|
|
import Resolver from '../../resolver';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { IRemoteUser } from '../../../../models/entities/user';
|
2018-04-07 21:55:26 +00:00
|
|
|
import announceNote from './note';
|
2019-09-26 19:58:28 +00:00
|
|
|
import { IAnnounce, validPost, getApId } from '../../type';
|
2019-02-03 09:16:57 +00:00
|
|
|
import { apLogger } from '../../logger';
|
2018-04-07 21:55:26 +00:00
|
|
|
|
2019-02-03 09:16:57 +00:00
|
|
|
const logger = apLogger;
|
2018-04-07 21:55:26 +00:00
|
|
|
|
|
|
|
export default async (actor: IRemoteUser, activity: IAnnounce): Promise<void> => {
|
2019-06-28 09:54:10 +00:00
|
|
|
const uri = getApId(activity);
|
2018-04-07 21:55:26 +00:00
|
|
|
|
2019-02-03 09:16:57 +00:00
|
|
|
logger.info(`Announce: ${uri}`);
|
2018-04-07 21:55:26 +00:00
|
|
|
|
|
|
|
const resolver = new Resolver();
|
|
|
|
|
2019-11-17 21:23:44 +00:00
|
|
|
const object = await resolver.resolve(activity.object).catch(e => {
|
2019-02-03 09:16:57 +00:00
|
|
|
logger.error(`Resolution failed: ${e}`);
|
2018-04-07 21:55:26 +00:00
|
|
|
throw e;
|
2019-11-17 21:23:44 +00:00
|
|
|
});
|
2018-04-07 21:55:26 +00:00
|
|
|
|
2019-06-28 09:54:10 +00:00
|
|
|
if (validPost.includes(object.type)) {
|
2019-09-26 19:58:28 +00:00
|
|
|
announceNote(resolver, actor, activity, object);
|
2019-06-28 09:54:10 +00:00
|
|
|
} else {
|
2019-02-03 09:16:57 +00:00
|
|
|
logger.warn(`Unknown announce type: ${object.type}`);
|
2018-04-07 21:55:26 +00:00
|
|
|
}
|
|
|
|
};
|