From e9360ac892aff8ae9147453644f30361968c403b Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sun, 15 Dec 2019 03:32:48 +0900 Subject: [PATCH] Fix AP inbox Announce (#5641) --- src/remote/activitypub/kernel/announce/index.ts | 13 +++---------- src/remote/activitypub/kernel/announce/note.ts | 10 +++++----- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/remote/activitypub/kernel/announce/index.ts b/src/remote/activitypub/kernel/announce/index.ts index dfccde3f9..28ad2fbcc 100644 --- a/src/remote/activitypub/kernel/announce/index.ts +++ b/src/remote/activitypub/kernel/announce/index.ts @@ -1,7 +1,7 @@ import Resolver from '../../resolver'; import { IRemoteUser } from '../../../../models/entities/user'; import announceNote from './note'; -import { IAnnounce, validPost, getApId } from '../../type'; +import { IAnnounce, getApId } from '../../type'; import { apLogger } from '../../logger'; const logger = apLogger; @@ -13,14 +13,7 @@ export default async (actor: IRemoteUser, activity: IAnnounce): Promise => const resolver = new Resolver(); - const object = await resolver.resolve(activity.object).catch(e => { - logger.error(`Resolution failed: ${e}`); - throw e; - }); + const targetUri = getApId(activity.object); - if (validPost.includes(object.type)) { - announceNote(resolver, actor, activity, object); - } else { - logger.warn(`Unknown announce type: ${object.type}`); - } + announceNote(resolver, actor, activity, targetUri); }; diff --git a/src/remote/activitypub/kernel/announce/note.ts b/src/remote/activitypub/kernel/announce/note.ts index a5db5b8ca..f22ed77d4 100644 --- a/src/remote/activitypub/kernel/announce/note.ts +++ b/src/remote/activitypub/kernel/announce/note.ts @@ -1,7 +1,7 @@ import Resolver from '../../resolver'; import post from '../../../../services/note/create'; import { IRemoteUser, User } from '../../../../models/entities/user'; -import { IAnnounce, IObject, getApId, getApIds } from '../../type'; +import { IAnnounce, getApId, getApIds } from '../../type'; import { fetchNote, resolveNote } from '../../models/note'; import { resolvePerson } from '../../models/person'; import { apLogger } from '../../logger'; @@ -14,7 +14,7 @@ const logger = apLogger; /** * アナウンスアクティビティを捌きます */ -export default async function(resolver: Resolver, actor: IRemoteUser, activity: IAnnounce, note: IObject): Promise { +export default async function(resolver: Resolver, actor: IRemoteUser, activity: IAnnounce, targetUri: string): Promise { const uri = getApId(activity); // アナウンサーが凍結されていたらスキップ @@ -38,14 +38,14 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity: // Announce対象をresolve let renote; try { - renote = await resolveNote(note); + renote = await resolveNote(targetUri); } catch (e) { // 対象が4xxならスキップ if (e.statusCode >= 400 && e.statusCode < 500) { - logger.warn(`Ignored announce target ${note.inReplyTo} - ${e.statusCode}`); + logger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`); return; } - logger.warn(`Error in announce target ${note.inReplyTo} - ${e.statusCode || e}`); + logger.warn(`Error in announce target ${targetUri} - ${e.statusCode || e}`); throw e; }