From c37d64c26b27c5942e1b21043bbd4c11031d3f44 Mon Sep 17 00:00:00 2001 From: Tsuyumi <40047364+SnowAgar25@users.noreply.github.com> Date: Thu, 14 Nov 2024 00:12:26 +0800 Subject: [PATCH] fix: Use renote ID for cross-instance notes (#17572) --- lib/routes/misskey/utils.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/routes/misskey/utils.ts b/lib/routes/misskey/utils.ts index bc2eb823c..0d852b80f 100644 --- a/lib/routes/misskey/utils.ts +++ b/lib/routes/misskey/utils.ts @@ -38,7 +38,25 @@ const parseNotes = (data: MisskeyNote[], site: string) => title = `${author}: "${noteToUse.text ?? ''}"`; } - const link = `https://${host}/notes/${noteToUse.id}`; + /** + * For renotes from non-Misskey instances (e.g. Mastodon, Pleroma), + * we can't use noteToUse.id to link to the original note since: + * 1. The URL format differs from Misskey's /notes/{id} pattern + * 2. Direct access to the original note may not be possible + * Therefore, we link to the renote itself in such cases + */ + let noteId = noteToUse.id; + + if (isRenote) { + const renoteHost = item.user.host ?? site; + const noteHost = noteToUse.user.host ?? site; + + // Use renote's ID if the note is from a different host or not in allowSiteList + if (renoteHost !== noteHost || !allowSiteList.includes(noteHost)) { + noteId = item.id; + } + } + const link = `https://${host}/notes/${noteId}`; const pubDate = parseDate(noteToUse.createdAt); return {