mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
factor out getNoteUrls function
This commit is contained in:
parent
7a10d9b43f
commit
919b97131b
2 changed files with 49 additions and 22 deletions
|
@ -3,35 +3,18 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as config from '@@/js/config.js';
|
|
||||||
import type * as Misskey from 'misskey-js';
|
import type * as Misskey from 'misskey-js';
|
||||||
import type * as mfm from '@transfem-org/sfm-js';
|
import type * as mfm from '@transfem-org/sfm-js';
|
||||||
import { extractUrlFromMfm } from '@/utility/extract-url-from-mfm.js';
|
import { extractUrlFromMfm } from '@/utility/extract-url-from-mfm.js';
|
||||||
|
import { getNoteUrls } from '@/utility/getNoteUrls';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts all previewable URLs from a note.
|
* Extracts all previewable URLs from a note.
|
||||||
*/
|
*/
|
||||||
export function extractPreviewUrls(note: Misskey.entities.Note, contents: mfm.MfmNode[]): string[] {
|
export function extractPreviewUrls(note: Misskey.entities.Note, contents: mfm.MfmNode[]): string[] {
|
||||||
const links = extractUrlFromMfm(contents);
|
const links = extractUrlFromMfm(contents);
|
||||||
return links.filter(url =>
|
if (links.length < 0) return [];
|
||||||
// Remote note
|
|
||||||
url !== note.url &&
|
const self = getNoteUrls(note);
|
||||||
url !== note.uri &&
|
return links.filter(url => !self.includes(url));
|
||||||
// Local note
|
|
||||||
url !== `${config.url}/notes/${note.id}` &&
|
|
||||||
// Remote reply
|
|
||||||
url !== note.reply?.url &&
|
|
||||||
url !== note.reply?.uri &&
|
|
||||||
// Local reply
|
|
||||||
url !== `${config.url}/notes/${note.reply?.id}` &&
|
|
||||||
// Remote renote or quote
|
|
||||||
url !== note.renote?.url &&
|
|
||||||
url !== note.renote?.uri &&
|
|
||||||
// Local renote or quote
|
|
||||||
url !== `${config.url}/notes/${note.renote?.id}` &&
|
|
||||||
// Remote renote *of* a quote
|
|
||||||
url !== note.renote?.renote?.url &&
|
|
||||||
url !== note.renote?.renote?.uri &&
|
|
||||||
// Local renote *of* a quote
|
|
||||||
url !== `${config.url}/notes/${note.renote?.renote?.id}`);
|
|
||||||
}
|
}
|
||||||
|
|
44
packages/frontend/src/utility/getNoteUrls.ts
Normal file
44
packages/frontend/src/utility/getNoteUrls.ts
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as config from '@@/js/config.js';
|
||||||
|
import type * as Misskey from 'misskey-js';
|
||||||
|
|
||||||
|
export function getNoteUrls(note: Misskey.entities.Note): string[] {
|
||||||
|
const urls: string[] = [
|
||||||
|
// Any note
|
||||||
|
`${config.url}/notes/${note.id}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Remote note
|
||||||
|
if (note.url) urls.push(note.url);
|
||||||
|
if (note.uri) urls.push(note.uri);
|
||||||
|
|
||||||
|
if (note.reply) {
|
||||||
|
// Any Reply
|
||||||
|
urls.push(`${config.url}/notes/${note.reply.id}`);
|
||||||
|
// Remote Reply
|
||||||
|
if (note.reply.url) urls.push(note.reply.url);
|
||||||
|
if (note.reply.uri) urls.push(note.reply.uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (note.renote) {
|
||||||
|
// Any Renote
|
||||||
|
urls.push(`${config.url}/notes/${note.renote.id}`);
|
||||||
|
// Remote Renote
|
||||||
|
if (note.renote.url) urls.push(note.renote.url);
|
||||||
|
if (note.renote.uri) urls.push(note.renote.uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (note.renote?.renote) {
|
||||||
|
// Any Quote
|
||||||
|
urls.push(`${config.url}/notes/${note.renote.renote.id}`);
|
||||||
|
// Remote Quote
|
||||||
|
if (note.renote.renote.url) urls.push(note.renote.renote.url);
|
||||||
|
if (note.renote.renote.uri) urls.push(note.renote.renote.uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
return urls;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue