From e89d7602403718c9ec5412db14e1288857d6c9a5 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Wed, 7 Feb 2024 19:57:59 +0900 Subject: [PATCH 01/11] =?UTF-8?q?Enhance:=20=E9=80=A3=E5=90=88=E5=90=91?= =?UTF-8?q?=E3=81=91=E3=81=AE=E3=83=8E=E3=83=BC=E3=83=88=E9=85=8D=E4=BF=A1?= =?UTF-8?q?=E3=82=92=E8=BB=BD=E9=87=8F=E5=8C=96=20(#13192)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AP HTML表現をシンプルに * a * CHANGELOG * リンク --- CHANGELOG.md | 1 + packages/backend/src/core/MfmService.ts | 4 ++ .../src/core/activitypub/ApMfmService.ts | 19 ++++++-- .../src/core/activitypub/ApRendererService.ts | 23 +++++----- packages/backend/test/unit/ApMfmService.ts | 44 +++++++++++++++++++ packages/backend/test/unit/MfmService.ts | 6 +++ 6 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 packages/backend/test/unit/ApMfmService.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 63bf42c72f..cb4a17d95b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ - Fix: properly handle cc followers - Fix: ジョブに関する設定の名前を修正 relashionshipJobPerSec -> relationshipJobPerSec - Fix: コントロールパネル->モデレーション->「誰でも新規登録できるようにする」の初期値をONからOFFに変更 #13122 +- Enhance: 連合向けのノート配信を軽量化 #13192 ### Service Worker - Enhance: オフライン表示のデザインを改善・多言語対応 diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts index e74c62e1a8..b2d8382bf6 100644 --- a/packages/backend/src/core/MfmService.ts +++ b/packages/backend/src/core/MfmService.ts @@ -419,6 +419,10 @@ export class MfmService { }, text: (node) => { + if (!node.props.text.match(/[\r\n]/)) { + return doc.createTextNode(node.props.text); + } + const el = doc.createElement('span'); const nodes = node.props.text.split(/\r\n|\r|\n/).map(x => doc.createTextNode(x)); diff --git a/packages/backend/src/core/activitypub/ApMfmService.ts b/packages/backend/src/core/activitypub/ApMfmService.ts index 60868627a2..737c34f3c5 100644 --- a/packages/backend/src/core/activitypub/ApMfmService.ts +++ b/packages/backend/src/core/activitypub/ApMfmService.ts @@ -25,8 +25,21 @@ export class ApMfmService { } @bindThis - public getNoteHtml(note: MiNote): string | null { - if (!note.text) return ''; - return this.mfmService.toHtml(mfm.parse(note.text), JSON.parse(note.mentionedRemoteUsers)); + public getNoteHtml(note: MiNote, apAppend?: string) { + let noMisskeyContent = false; + const srcMfm = (note.text ?? '') + (apAppend ?? ''); + + const parsed = mfm.parse(srcMfm); + + if (!apAppend && parsed?.every(n => ['text', 'unicodeEmoji', 'emojiCode', 'mention', 'hashtag', 'url'].includes(n.type))) { + noMisskeyContent = true; + } + + const content = this.mfmService.toHtml(parsed, JSON.parse(note.mentionedRemoteUsers)); + + return { + content, + noMisskeyContent, + }; } } diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts index 530e4a3c33..211f4f4a44 100644 --- a/packages/backend/src/core/activitypub/ApRendererService.ts +++ b/packages/backend/src/core/activitypub/ApRendererService.ts @@ -389,17 +389,15 @@ export class ApRendererService { poll = await this.pollsRepository.findOneBy({ noteId: note.id }); } - let apText = text; + let apAppend = ''; if (quote) { - apText += `\n\nRE: ${quote}`; + apAppend += `\n\nRE: ${quote}`; } const summary = note.cw === '' ? String.fromCharCode(0x200B) : note.cw; - const content = this.apMfmService.getNoteHtml(Object.assign({}, note, { - text: apText, - })); + const { content, noMisskeyContent } = this.apMfmService.getNoteHtml(note, apAppend); const emojis = await this.getEmojis(note.emojis); const apemojis = emojis.filter(emoji => !emoji.localOnly).map(emoji => this.renderEmoji(emoji)); @@ -412,9 +410,6 @@ export class ApRendererService { const asPoll = poll ? { type: 'Question', - content: this.apMfmService.getNoteHtml(Object.assign({}, note, { - text: text, - })), [poll.expiresAt && poll.expiresAt < new Date() ? 'closed' : 'endTime']: poll.expiresAt, [poll.multiple ? 'anyOf' : 'oneOf']: poll.choices.map((text, i) => ({ type: 'Note', @@ -432,11 +427,13 @@ export class ApRendererService { attributedTo, summary: summary ?? undefined, content: content ?? undefined, - _misskey_content: text, - source: { - content: text, - mediaType: 'text/x.misskeymarkdown', - }, + ...(noMisskeyContent ? {} : { + _misskey_content: text, + source: { + content: text, + mediaType: 'text/x.misskeymarkdown', + }, + }), _misskey_quote: quote, quoteUrl: quote, published: this.idService.parse(note.id).date.toISOString(), diff --git a/packages/backend/test/unit/ApMfmService.ts b/packages/backend/test/unit/ApMfmService.ts new file mode 100644 index 0000000000..2b79041c86 --- /dev/null +++ b/packages/backend/test/unit/ApMfmService.ts @@ -0,0 +1,44 @@ +import * as assert from 'assert'; +import { Test } from '@nestjs/testing'; + +import { CoreModule } from '@/core/CoreModule.js'; +import { ApMfmService } from '@/core/activitypub/ApMfmService.js'; +import { GlobalModule } from '@/GlobalModule.js'; +import { MiNote } from '@/models/Note.js'; + +describe('ApMfmService', () => { + let apMfmService: ApMfmService; + + beforeAll(async () => { + const app = await Test.createTestingModule({ + imports: [GlobalModule, CoreModule], + }).compile(); + apMfmService = app.get(ApMfmService); + }); + + describe('getNoteHtml', () => { + test('Do not provide _misskey_content for simple text', () => { + const note: MiNote = { + text: 'テキスト #タグ @mention 🍊 :emoji: https://example.com', + mentionedRemoteUsers: '[]', + } as any; + + const { content, noMisskeyContent } = apMfmService.getNoteHtml(note); + + assert.equal(noMisskeyContent, true, 'noMisskeyContent'); + assert.equal(content, '

テキスト @mention 🍊 ​:emoji:​ https://example.com

', 'content'); + }); + + test('Provide _misskey_content for MFM', () => { + const note: MiNote = { + text: '$[tada foo]', + mentionedRemoteUsers: '[]', + } as any; + + const { content, noMisskeyContent } = apMfmService.getNoteHtml(note); + + assert.equal(noMisskeyContent, false, 'noMisskeyContent'); + assert.equal(content, '

foo

', 'content'); + }); + }); +}); diff --git a/packages/backend/test/unit/MfmService.ts b/packages/backend/test/unit/MfmService.ts index bb8e6981d5..c3827b20d2 100644 --- a/packages/backend/test/unit/MfmService.ts +++ b/packages/backend/test/unit/MfmService.ts @@ -33,6 +33,12 @@ describe('MfmService', () => { const output = '

foo
bar
baz

'; assert.equal(mfmService.toHtml(mfm.parse(input)), output); }); + + test('Do not generate unnecessary span', () => { + const input = 'foo $[tada bar]'; + const output = '

foo bar

'; + assert.equal(mfmService.toHtml(mfm.parse(input)), output); + }); }); describe('fromHtml', () => { From 56d7f5862683b2136976608c5f4fa21dfc6748e2 Mon Sep 17 00:00:00 2001 From: 1Step621 <86859447+1STEP621@users.noreply.github.com> Date: Wed, 7 Feb 2024 19:58:21 +0900 Subject: [PATCH 02/11] =?UTF-8?q?Fix(frontend):=20MkCodeEditor=E3=81=A7?= =?UTF-8?q?=E8=A1=8C=E3=81=8C=E3=81=9A=E3=82=8C=E3=81=A6=E3=81=84=E3=81=8F?= =?UTF-8?q?=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3=20(#13188)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MkCodeEditorで行がずれていくのを修正 * update CHANGELOG.md --- CHANGELOG.md | 1 + packages/frontend/src/components/MkCode.core.vue | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb4a17d95b..652c7ea7c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ - Fix: キャプションが空の画像をクロップするとキャプションにnullという文字列が入ってしまう問題の修正 - Fix: プロフィールを編集してもリロードするまで反映されない問題を修正 - Fix: エラー画像URLを設定した後解除すると,デフォルトの画像が表示されない問題の修正 +- Fix: MkCodeEditorで行がずれていってしまう問題の修正 ### Server - Enhance: 連合先のレートリミットに引っかかった際にリトライするようになりました diff --git a/packages/frontend/src/components/MkCode.core.vue b/packages/frontend/src/components/MkCode.core.vue index 68c50c4c69..02a0ea475e 100644 --- a/packages/frontend/src/components/MkCode.core.vue +++ b/packages/frontend/src/components/MkCode.core.vue @@ -78,6 +78,7 @@ watch(() => props.lang, (to) => { overflow: auto; border-radius: 8px; border: 1px solid var(--divider); + font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace; color: var(--shiki-fallback); background-color: var(--shiki-fallback-bg); From 313ce821926efc0e01fd815c7582d8bb30f7e935 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Wed, 7 Feb 2024 19:59:06 +0900 Subject: [PATCH 03/11] =?UTF-8?q?=E6=AD=A3=E3=81=97=E3=81=84=202024.2.0-be?= =?UTF-8?q?ta.10=20=E6=94=B9=E7=89=88=E6=89=8B=E9=A0=86=EF=BC=9F=20(#13173?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 正しい 2024.2.0-beta.10 改版手順? * run build-misskey-js-with-types --- packages/misskey-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/misskey-js/package.json b/packages/misskey-js/package.json index 03952c7ac1..0c4dd52d14 100644 --- a/packages/misskey-js/package.json +++ b/packages/misskey-js/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "misskey-js", - "version": "2024.2.0-beta.8", + "version": "2024.2.0-beta.10", "description": "Misskey SDK for JavaScript", "types": "./built/dts/index.d.ts", "exports": { From 155896a851f2a1060454ff614b5fecde4a8dd016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 7 Feb 2024 20:02:29 +0900 Subject: [PATCH 04/11] =?UTF-8?q?enhance(frontend/HorizontalSwipe):=20?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=80=A7=E3=81=AE=E6=94=B9=E5=96=84=20(#1303?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update swipe thresholds and touch-action * スワイプ中にPullToRefreshが反応しないように * 横スワイプに関与する可能性のある要素がある場合はスワイプを発火しないように * update threshold * isSwipingを外部化 * rename --------- Co-authored-by: syuilo --- .../src/components/MkHorizontalSwipe.vue | 34 ++++++++++++++++--- .../src/components/MkPullToRefresh.vue | 7 +++- packages/frontend/src/scripts/touch.ts | 4 +++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/packages/frontend/src/components/MkHorizontalSwipe.vue b/packages/frontend/src/components/MkHorizontalSwipe.vue index 67d32c505a..bf7d43fd43 100644 --- a/packages/frontend/src/components/MkHorizontalSwipe.vue +++ b/packages/frontend/src/components/MkHorizontalSwipe.vue @@ -25,11 +25,11 @@ SPDX-License-Identifier: AGPL-3.0-only -