diff --git a/.changeset/feat-msc4440-bio-compat.md b/.changeset/feat-msc4440-bio-compat.md new file mode 100644 index 00000000..0fc8f976 --- /dev/null +++ b/.changeset/feat-msc4440-bio-compat.md @@ -0,0 +1,5 @@ +--- +default: note +--- + +new/changed bios will now also be saved in the format MSC4440 expects diff --git a/src/app/features/settings/account/BioEditor.tsx b/src/app/features/settings/account/BioEditor.tsx index 49b47d7b..b5670a22 100644 --- a/src/app/features/settings/account/BioEditor.tsx +++ b/src/app/features/settings/account/BioEditor.tsx @@ -44,7 +44,7 @@ type BioEditorProps = { value?: string | any; isSaving?: boolean; imagePackRooms?: any[]; - onSave: (htmlContent: string) => void; + onSave: (htmlContent: string, plainText: string) => void; }; const BIO_LIMIT = 1024; @@ -81,7 +81,7 @@ export function BioEditor({ value, isSaving, imagePackRooms, onSave }: BioEditor }) ); - onSave(customHtml || plainText); + onSave(customHtml || plainText, plainText); setHasChanged(false); }, [editor, isMarkdown, onSave]); diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index 935e076f..5702c029 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -46,13 +46,13 @@ import { useCapabilities } from '$hooks/useCapabilities'; import { profilesCacheAtom } from '$state/userRoomProfile'; import { SequenceCardStyle } from '$features/settings/styles.css'; import { useUserPresence } from '$hooks/useUserPresence'; +import { MSC1767Text } from '$types/matrix/common'; import { TimezoneEditor } from './TimezoneEditor'; import { PronounEditor } from './PronounEditor'; import { BioEditor } from './BioEditor'; import { NameColorEditor } from './NameColorEditor'; import { StatusEditor } from './StatusEditor'; import { AnimalCosmetics } from './AnimalCosmetics'; -import { toPlainText } from '$components/editor'; type PronounSet = { summary: string; @@ -582,17 +582,20 @@ function ProfileExtended({ profile, userId }: Readonly) { profile.extended?.['chat.commet.profile_bio'] || profile.bio } - onSave={(htmlBio) => { + onSave={(htmlBio, plainTextBio) => { handleSaveField('moe.sable.app.bio', htmlBio); // MSC4440 handleSaveField('gay.fomx.biography', { - body: htmlBio - .replaceAll('
', '\n') - .replaceAll('
  • ', '\n- ') - .replaceAll(/<[^>]*>/g, ''), - format: 'org.matrix.custom.html', - formatted_body: htmlBio, + 'm.text': [ + { + body: htmlBio, + mimetype: 'text/html', + } satisfies MSC1767Text, + { + body: plainTextBio, + } satisfies MSC1767Text, + ], } satisfies MSC4440Bio); const cleanedHtml = htmlBio.replaceAll('
    ', ''); diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 21f87b81..d1de6e89 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -7,14 +7,13 @@ import colorMXID from '$utils/colorMXID'; import { profilesCacheAtom } from '$state/userRoomProfile'; import { useSetting } from '$state/hooks/settings'; import { settingsAtom } from '$state/settings'; +import { MSC1767Text } from '$types/matrix/common'; import { useMatrixClient } from './useMatrixClient'; const inFlightProfiles = new Map>(); export type MSC4440Bio = { - body: string; - format: string; - formatted_body: string; + 'm.text': Array; }; export type UserProfile = { @@ -62,7 +61,7 @@ const normalizeInfo = (info: any): UserProfile => { pronouns: info['io.fsky.nyx.pronouns'], timezone: info['us.cloke.msc4175.tz'] || info['m.tz'], bio: - (info['gay.fomx.biography'] satisfies MSC4440Bio).formatted_body || + (info['gay.fomx.biography'] satisfies MSC4440Bio)['m.text'][0].body || info['moe.sable.app.bio'] || info['chat.commet.profile_bio'], status: info['chat.commet.profile_status'], diff --git a/src/types/matrix/common.ts b/src/types/matrix/common.ts index 8cc96d7d..e9199357 100644 --- a/src/types/matrix/common.ts +++ b/src/types/matrix/common.ts @@ -14,6 +14,11 @@ export type IImageInfo = { [MATRIX_BLUR_HASH_PROPERTY_NAME]?: string; }; +export type MSC1767Text = { + body: string; + mimetype?: string; +}; + export type IVideoInfo = { w?: number; h?: number;