From 6752594578e64a26c0cd1c5a9fd2d83313134466 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Fri, 6 Apr 2018 12:20:11 +0900 Subject: [PATCH] Resolve local Person ID --- src/remote/activitypub/resolve-person.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/remote/activitypub/resolve-person.ts b/src/remote/activitypub/resolve-person.ts index a7c0020dd..84746169f 100644 --- a/src/remote/activitypub/resolve-person.ts +++ b/src/remote/activitypub/resolve-person.ts @@ -1,5 +1,7 @@ import { JSDOM } from 'jsdom'; import { toUnicode } from 'punycode'; +import parseAcct from '../../acct/parse'; +import config from '../../config'; import User, { validateUsername, isValidName, isValidDescription } from '../../models/user'; import { createHttp } from '../../queue'; import webFinger from '../webfinger'; @@ -10,10 +12,18 @@ async function isCollection(collection) { } export default async (parentResolver, value, verifier?: string) => { + const id = value.id || value; + const localPrefix = config.url + '/@'; + + if (id.startsWith(localPrefix)) { + return User.findOne(parseAcct(id.slice(localPrefix))); + } + const { resolver, object } = await parentResolver.resolveOne(value); if ( object === null || + object.id !== id || object.type !== 'Person' || typeof object.preferredUsername !== 'string' || !validateUsername(object.preferredUsername) || @@ -36,7 +46,7 @@ export default async (parentResolver, value, verifier?: string) => { resolved => isCollection(resolved.object) ? resolved.object : null, () => null ), - webFinger(object.id, verifier), + webFinger(id, verifier), ]); const host = toUnicode(finger.subject.replace(/^.*?@/, '')); @@ -64,7 +74,7 @@ export default async (parentResolver, value, verifier?: string) => { publicKeyPem: object.publicKey.publicKeyPem }, inbox: object.inbox, - uri: object.id, + uri: id, }, });