diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index 122d29eff3..7230920db2 100644 --- a/packages/frontend/src/components/MkNote.vue +++ b/packages/frontend/src/components/MkNote.vue @@ -60,7 +60,7 @@ SPDX-License-Identifier: AGPL-3.0-only
({{ i18n.ts.private }}) - +
@@ -84,7 +84,7 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ appearNote.channel.name }}
- + @@ -217,8 +217,9 @@ const clipButton = shallowRef(); let appearNote = $computed(() => isRenote ? note.renote as Misskey.entities.Note : note); const isMyRenote = $i && ($i.id === note.userId); const showContent = ref(false); -const urls = appearNote.text ? extractUrlFromMfm(mfm.parse(appearNote.text)) : null; -const isLong = shouldCollapsed(appearNote); +const parsed = appearNote.text ? mfm.parse(appearNote.text) : null; +const urls = parsed ? extractUrlFromMfm(parsed) : null; +const isLong = shouldCollapsed(appearNote, urls ?? []); const collapsed = ref(appearNote.cw == null && isLong); const isDeleted = ref(false); const muted = ref($i ? checkWordMute(appearNote, $i, $i.mutedWords) : false); diff --git a/packages/frontend/src/components/MkNoteDetailed.vue b/packages/frontend/src/components/MkNoteDetailed.vue index ce4fb79d4b..d34d35a0c3 100644 --- a/packages/frontend/src/components/MkNoteDetailed.vue +++ b/packages/frontend/src/components/MkNoteDetailed.vue @@ -73,7 +73,7 @@ SPDX-License-Identifier: AGPL-3.0-only
({{ i18n.ts.private }}) - + RN:
@@ -260,7 +260,8 @@ const isDeleted = ref(false); const muted = ref($i ? checkWordMute(appearNote, $i, $i.mutedWords) : false); const translation = ref(null); const translating = ref(false); -const urls = appearNote.text ? extractUrlFromMfm(mfm.parse(appearNote.text)) : null; +const parsed = appearNote.text ? mfm.parse(appearNote.text) : null; +const urls = parsed ? extractUrlFromMfm(parsed) : null; const showTicker = (defaultStore.state.instanceTicker === 'always') || (defaultStore.state.instanceTicker === 'remote' && appearNote.user.instance); const conversation = ref([]); const replies = ref([]); diff --git a/packages/frontend/src/components/MkSubNoteContent.vue b/packages/frontend/src/components/MkSubNoteContent.vue index 34fdd1cce4..51dabee161 100644 --- a/packages/frontend/src/components/MkSubNoteContent.vue +++ b/packages/frontend/src/components/MkSubNoteContent.vue @@ -42,7 +42,7 @@ const props = defineProps<{ note: Misskey.entities.Note; }>(); -const isLong = shouldCollapsed(props.note); +const isLong = shouldCollapsed(props.note, []); const collapsed = $ref(isLong); diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index 102aa0db34..ab8a342691 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -38,6 +38,7 @@ type MfmProps = { emojiUrls?: string[]; rootScale?: number; nyaize: boolean | 'account'; + parsedNodes?: mfm.MfmNode[] | null; }; // eslint-disable-next-line import/no-default-export @@ -48,7 +49,7 @@ export default function(props: MfmProps) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (props.text == null || props.text === '') return; - const rootAst = (props.plain ? mfm.parseSimple : mfm.parse)(props.text); + const rootAst = props.parsedNodes ?? (props.plain ? mfm.parseSimple : mfm.parse)(props.text); const validTime = (t: string | null | undefined) => { if (t == null) return null; diff --git a/packages/frontend/src/scripts/collapsed.ts b/packages/frontend/src/scripts/collapsed.ts index c3c767bcfa..57e6ecf5b5 100644 --- a/packages/frontend/src/scripts/collapsed.ts +++ b/packages/frontend/src/scripts/collapsed.ts @@ -3,12 +3,9 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import * as mfm from 'mfm-js'; import * as Misskey from 'misskey-js'; -import { extractUrlFromMfm } from './extract-url-from-mfm.js'; -export function shouldCollapsed(note: Misskey.entities.Note): boolean { - const urls = note.text ? extractUrlFromMfm(mfm.parse(note.text)) : null; +export function shouldCollapsed(note: Misskey.entities.Note, urls: string[]): boolean { const collapsed = note.cw == null && note.text != null && ( (note.text.includes('$[x2')) || (note.text.includes('$[x3')) || @@ -17,7 +14,7 @@ export function shouldCollapsed(note: Misskey.entities.Note): boolean { (note.text.split('\n').length > 9) || (note.text.length > 500) || (note.files.length >= 5) || - (!!urls && urls.length >= 4) + (urls.length >= 4) ); return collapsed;