server: implement FEP-e232 style quotes #318
|
@ -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())
|
||||
Johann150 marked this conversation as resolved
|
||||
)
|
||||
.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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue
i'd instead do
toArray(tags).filter(hasRel)
because the link relation is what is doing all the semantic heavy-liftingThis part is to implement the FEP because it says that this media type is required.