From bac39db74ba8a8f4681ee5c37d2f8fc86d8f4cf4 Mon Sep 17 00:00:00 2001 From: Essem Date: Thu, 21 Sep 2023 21:13:09 +0000 Subject: [PATCH] Add contentMap to outgoing posts via language detection --- packages/backend/src/remote/activitypub/renderer/note.ts | 7 +++++++ packages/backend/src/remote/activitypub/type.ts | 1 + 2 files changed, 8 insertions(+) diff --git a/packages/backend/src/remote/activitypub/renderer/note.ts b/packages/backend/src/remote/activitypub/renderer/note.ts index b29246edf0..edeeb4222b 100644 --- a/packages/backend/src/remote/activitypub/renderer/note.ts +++ b/packages/backend/src/remote/activitypub/renderer/note.ts @@ -1,4 +1,5 @@ import { In, IsNull } from "typeorm"; +import { detect as detectLanguage } from "tinyld"; import config from "@/config/index.js"; import type { Note, IMentionedRemoteUsers } from "@/models/entities/note.js"; import type { DriveFile } from "@/models/entities/drive-file.js"; @@ -114,6 +115,11 @@ export default async function renderNote( }), ); + const lang = detectLanguage(text); + const contentMap = lang ? { + [lang]: content + } : null; + const emojis = await getEmojis(note.emojis); const apemojis = emojis.map((emoji) => renderEmoji(emoji)); @@ -152,6 +158,7 @@ export default async function renderNote( attributedTo, summary, content, + contentMap, source: { content: text, mediaType: "text/x.misskeymarkdown", diff --git a/packages/backend/src/remote/activitypub/type.ts b/packages/backend/src/remote/activitypub/type.ts index 2258241b65..0e63f3ed55 100644 --- a/packages/backend/src/remote/activitypub/type.ts +++ b/packages/backend/src/remote/activitypub/type.ts @@ -14,6 +14,7 @@ export interface IObject { inReplyTo?: any; replies?: ICollection; content?: string; + contentMap?: obj; name?: string; startTime?: Date; endTime?: Date;