From d6fe89792350d699ff1ad5dcf639fef19dffa91d Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2023 10:23:20 +0900 Subject: [PATCH] =?UTF-8?q?perf(frontend):=20=E3=83=8E=E3=83=BC=E3=83=88?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E6=99=82=E3=81=AEMFM=E3=83=91=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E5=87=A6=E7=90=86=E3=82=92=E6=B8=9B=E3=82=89=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/components/MkNote.vue | 7 ++++--- packages/frontend/src/components/MkNoteDetailed.vue | 5 +++-- packages/frontend/src/components/MkSubNoteContent.vue | 2 +- .../src/components/global/MkMisskeyFlavoredMarkdown.ts | 3 ++- packages/frontend/src/scripts/collapsed.ts | 7 ++----- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index f2329ff320..b31ee78532 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 }}) - +
@@ -209,8 +209,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;