From 3d3ecab2718608d9393ef934014e627520adb23d Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 6 Jan 2023 07:59:12 +0100 Subject: [PATCH] fixup: require rel and accept more of them Accept all URIs that are accepted as quote properties. --- .../src/remote/activitypub/models/tag.ts | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/backend/src/remote/activitypub/models/tag.ts b/packages/backend/src/remote/activitypub/models/tag.ts index dfac2ef98..182a23765 100644 --- a/packages/backend/src/remote/activitypub/models/tag.ts +++ b/packages/backend/src/remote/activitypub/models/tag.ts @@ -29,26 +29,21 @@ export function extractQuoteUrl(tags: IObject | IObject[] | null | undefined): s 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', 'application/activity+json' ].includes(link.mediaType?.toLowerCase()) + ) + .filter(link => + toArray(link.rel) + .some(rel => + [ + 'https://misskey-hub.net/ns#_misskey_quote', + 'http://fedibird.com/ns#quoteUri', + 'https://www.w3.org/ns/activitystreams#quoteUrl', + ].includes(rel) + ) ); - // sort quotes with the right rel first - function hasRel(link: ILink): boolean { - link.rel != null - && - toArray(link.rel) - .includes('https://misskey-hub.net/ns#_misskey_quote') - } - quotes.sort((a, b) => { - return hasRel(b) - hasRel(a); - }); - - // deduplicate by href - quotes = quotes.filter((x, i, arr) => arr.findIndex(y => x.href === y.href) === i); - if (quotes.length === 0) return null; + // Deduplicate by href. // If there is more than one quote, we just pick the first/a random one. - // Note that links with the correct `rel` were sorted to the front above - // so they will be preferred. - return quotes[0].href; + quotes.filter((x, i, arr) => arr.findIndex(y => x.href === y.href) === i)[0].href; }