server: implement FEP-e232 style quotes #318

Manually merged
Johann150 merged 5 commits from federation-quote into main 2023-01-17 20:51:55 +00:00
Showing only changes of commit 3d3ecab271 - Show all commits

View file

@ -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
Review

i'd instead do toArray(tags).filter(hasRel) because the link relation is what is doing all the semantic heavy-lifting

i'd instead do `toArray(tags).filter(hasRel)` because the link relation is what is doing all the semantic heavy-lifting
Review

This part is to implement the FEP because it says that this media type is required.

This part is to implement the FEP because it says that this media type is required.
)
.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;
}