consider duplicate previews where one URL can't be resolved, but another URL resolves to a local copy of the same note

This commit is contained in:
Hazelnoot 2025-05-30 12:58:35 -04:00
parent 2536768133
commit 876ec968bd

View file

@ -35,6 +35,7 @@ import { extractUrlFromMfm } from '@/utility/extract-url-from-mfm';
import { $i } from '@/i';
import { misskeyApi } from '@/utility/misskey-api';
import MkUrlPreview from '@/components/MkUrlPreview.vue';
import { getNoteUrls } from '@/utility/getNoteUrls';
type Summary = Awaited<ReturnType<typeof summaly>> & {
haveNoteLocally?: boolean;
@ -265,6 +266,31 @@ function deduplicatePreviews(previews: Summary[]): Summary[] {
return true;
}));
// eslint-disable-next-line no-param-reassign
previews = previews
// Remove any previews where the note duplicates url
.filter((preview, index) => !previews.some((p, i) => {
// Skip the current preview (don't count self as duplicate).
if (p === preview) return false;
// Skip if we have a note
if (preview.note) return false;
// Skip if other does not have a note
if (!p.note) return false;
// Skip later previews (keep the earliest instance)
if (i > index) return false;
const noteUrls = getNoteUrls(p.note);
// Remove if other duplicates our AP URL
if (preview.activityPub && noteUrls.includes(preview.activityPub)) return true;
// Remove if other duplicates our main URL
return noteUrls.includes(preview.url);
}));
return previews;
}