mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
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:
parent
2536768133
commit
876ec968bd
1 changed files with 26 additions and 0 deletions
|
@ -35,6 +35,7 @@ import { extractUrlFromMfm } from '@/utility/extract-url-from-mfm';
|
||||||
import { $i } from '@/i';
|
import { $i } from '@/i';
|
||||||
import { misskeyApi } from '@/utility/misskey-api';
|
import { misskeyApi } from '@/utility/misskey-api';
|
||||||
import MkUrlPreview from '@/components/MkUrlPreview.vue';
|
import MkUrlPreview from '@/components/MkUrlPreview.vue';
|
||||||
|
import { getNoteUrls } from '@/utility/getNoteUrls';
|
||||||
|
|
||||||
type Summary = Awaited<ReturnType<typeof summaly>> & {
|
type Summary = Awaited<ReturnType<typeof summaly>> & {
|
||||||
haveNoteLocally?: boolean;
|
haveNoteLocally?: boolean;
|
||||||
|
@ -265,6 +266,31 @@ function deduplicatePreviews(previews: Summary[]): Summary[] {
|
||||||
return true;
|
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;
|
return previews;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue