summaryrefslogtreecommitdiff
path: root/packages/frontend
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-30 12:58:35 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-04 10:48:24 -0400
commit876ec968bd6883dccec2a0a3fb839fd06cdd4063 (patch)
tree2e6e118f22b9e6d0e2792cdebd82d33441715cf0 /packages/frontend
parentcheck for note in initial de-duplication pass (diff)
downloadsharkey-876ec968bd6883dccec2a0a3fb839fd06cdd4063.tar.gz
sharkey-876ec968bd6883dccec2a0a3fb839fd06cdd4063.tar.bz2
sharkey-876ec968bd6883dccec2a0a3fb839fd06cdd4063.zip
consider duplicate previews where one URL can't be resolved, but another URL resolves to a local copy of the same note
Diffstat (limited to 'packages/frontend')
-rw-r--r--packages/frontend/src/components/SkUrlPreviewGroup.vue26
1 files changed, 26 insertions, 0 deletions
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<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;
}