From 3df1bc71067e5dd693674faf233ed83237099947 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Thu, 14 Sep 2023 15:37:26 +0200 Subject: [PATCH] feat: better support both Person and Note data --- src/claim.js | 2 +- src/serviceProviders/activitypub.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/claim.js b/src/claim.js index 8765a94..2d464ba 100644 --- a/src/claim.js +++ b/src/claim.js @@ -270,7 +270,7 @@ export class Claim { const def = _data[claimData.about.id] if (def.functions?.postprocess) { try { - ({ claimData, proofData } = def.functions.postprocess(claimData, proofData)) + ({ claimData, proofData } = await def.functions.postprocess(claimData, proofData, opts)) } catch (_) {} } } else { diff --git a/src/serviceProviders/activitypub.js b/src/serviceProviders/activitypub.js index 21394db..e7a471f 100644 --- a/src/serviceProviders/activitypub.js +++ b/src/serviceProviders/activitypub.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { activitypub } from '../fetcher/index.js' import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)\/?/ @@ -76,8 +77,23 @@ export function processURI (uri) { } export const functions = { - postprocess: (claimData, proofData) => { - claimData.profile.display = `@${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}` + postprocess: async (/** @type {ServiceProvider} */ claimData, proofData, opts) => { + switch (proofData.result.type) { + case 'Note': { + claimData.profile.uri = proofData.result.attributedTo + const personData = await activitypub.fn({ url: proofData.result.attributedTo }, opts) + claimData.profile.display = `@${personData.preferredUsername}@${new URL(proofData.result.url).hostname}` + break + } + + case 'Person': + claimData.profile.display = `@${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}` + break + + default: + break + } + return { claimData, proofData } } }