From 5bcf8e9b9d63d035388696e418c2531a52ce6b10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?=
 =?UTF-8?q?=E3=81=AB=E3=82=85?=
 <17376330+u1-liquid@users.noreply.github.com>
Date: Mon, 30 Oct 2023 00:42:11 +0900
Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E3=83=97=E3=83=AD=E3=83=95?=
 =?UTF-8?q?=E3=82=A3=E3=83=BC=E3=83=AB=E3=81=AE=E8=87=AA=E5=B7=B1=E7=B4=B9?=
 =?UTF-8?q?=E4=BB=8B=E6=AC=84=E3=81=AEMFM=E3=82=92=E9=80=A3=E5=90=88?=
 =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=20(misskey-dev#12?=
 =?UTF-8?q?184)=20(MisskeyIO#199)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: kakkokari-gtyih <daisho7308+f@gmail.com>
---
 .../src/core/activitypub/ApRendererService.ts |  2 ++
 .../activitypub/models/ApPersonService.ts     | 20 +++++++++++++++++--
 packages/backend/src/core/activitypub/type.ts |  1 +
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts
index 607ab293b3..928144a12b 100644
--- a/packages/backend/src/core/activitypub/ApRendererService.ts
+++ b/packages/backend/src/core/activitypub/ApRendererService.ts
@@ -496,6 +496,7 @@ export class ApRendererService {
 			preferredUsername: user.username,
 			name: user.name,
 			summary: profile.description ? this.mfmService.toHtml(mfm.parse(profile.description)) : null,
+			_misskey_summary: profile.description,
 			icon: avatar ? this.renderImage(avatar) : null,
 			image: banner ? this.renderImage(banner) : null,
 			tag,
@@ -645,6 +646,7 @@ export class ApRendererService {
 					'_misskey_quote': 'misskey:_misskey_quote',
 					'_misskey_reaction': 'misskey:_misskey_reaction',
 					'_misskey_votes': 'misskey:_misskey_votes',
+					'_misskey_summary': 'misskey:_misskey_summary',
 					'isCat': 'misskey:isCat',
 					// vcard
 					vcard: 'http://www.w3.org/2006/vcard/ns#',
diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts
index e133ce5d70..bc8c0a85ba 100644
--- a/packages/backend/src/core/activitypub/models/ApPersonService.ts
+++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts
@@ -335,9 +335,17 @@ export class ApPersonService implements OnModuleInit {
 					emojis,
 				})) as MiRemoteUser;
 
+				let _description: string | null = null;
+
+				if (person._misskey_summary) {
+					_description = truncate(person._misskey_summary, summaryLength);
+				} else if (person.summary) {
+					_description = this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag);
+				}
+
 				await transactionalEntityManager.save(new MiUserProfile({
 					userId: user.id,
-					description: person.summary ? this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag) : null,
+					description: _description,
 					url,
 					fields,
 					birthday: bday?.[0] ?? null,
@@ -503,10 +511,18 @@ export class ApPersonService implements OnModuleInit {
 			});
 		}
 
+		let _description: string | null = null;
+
+		if (person._misskey_summary) {
+			_description = truncate(person._misskey_summary, summaryLength);
+		} else if (person.summary) {
+			_description = this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag);
+		}
+
 		await this.userProfilesRepository.update({ userId: exist.id }, {
 			url,
 			fields,
-			description: person.summary ? this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag) : null,
+			description: _description,
 			birthday: bday?.[0] ?? null,
 			location: person['vcard:Address'] ?? null,
 		});
diff --git a/packages/backend/src/core/activitypub/type.ts b/packages/backend/src/core/activitypub/type.ts
index 16ff86e894..d9fcc99066 100644
--- a/packages/backend/src/core/activitypub/type.ts
+++ b/packages/backend/src/core/activitypub/type.ts
@@ -12,6 +12,7 @@ export interface IObject {
 	id?: string;
 	name?: string | null;
 	summary?: string;
+	_misskey_summary?: string;
 	published?: string;
 	cc?: ApObject;
 	to?: ApObject;