From 876ec968bd6883dccec2a0a3fb839fd06cdd4063 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Fri, 30 May 2025 12:58:35 -0400 Subject: [PATCH] consider duplicate previews where one URL can't be resolved, but another URL resolves to a local copy of the same note --- .../src/components/SkUrlPreviewGroup.vue | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/frontend/src/components/SkUrlPreviewGroup.vue b/packages/frontend/src/components/SkUrlPreviewGroup.vue index beba20f783..5175e16cfc 100644 --- a/packages/frontend/src/components/SkUrlPreviewGroup.vue +++ b/packages/frontend/src/components/SkUrlPreviewGroup.vue @@ -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> & { 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; }