Skip to content

Commit daac2a5

Browse files
committed
it now uses extensible events to format the bio, as per msc4440
1 parent 6e238ef commit daac2a5

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: note
3+
---
4+
5+
new/changed bios will now also be saved in the format MSC4440 expects

src/app/features/settings/account/Profile.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ import { useCapabilities } from '$hooks/useCapabilities';
4646
import { profilesCacheAtom } from '$state/userRoomProfile';
4747
import { SequenceCardStyle } from '$features/settings/styles.css';
4848
import { useUserPresence } from '$hooks/useUserPresence';
49+
import { MSC1767Text } from '$types/matrix/common';
4950
import { TimezoneEditor } from './TimezoneEditor';
5051
import { PronounEditor } from './PronounEditor';
5152
import { BioEditor } from './BioEditor';
5253
import { NameColorEditor } from './NameColorEditor';
5354
import { StatusEditor } from './StatusEditor';
5455
import { AnimalCosmetics } from './AnimalCosmetics';
55-
import { toPlainText } from '$components/editor';
5656

5757
type PronounSet = {
5858
summary: string;
@@ -585,14 +585,21 @@ function ProfileExtended({ profile, userId }: Readonly<ProfileProps>) {
585585
onSave={(htmlBio) => {
586586
handleSaveField('moe.sable.app.bio', htmlBio);
587587

588+
const plainTextBio: string = htmlBio
589+
.replaceAll('<br>', '\n')
590+
.replaceAll('<li>', '\n- ')
591+
.replaceAll(/<[^>]*>/g, '');
588592
// MSC4440
589593
handleSaveField('gay.fomx.biography', {
590-
body: htmlBio
591-
.replaceAll('<br>', '\n')
592-
.replaceAll('<li>', '\n- ')
593-
.replaceAll(/<[^>]*>/g, ''),
594-
format: 'org.matrix.custom.html',
595-
formatted_body: htmlBio,
594+
'm.text': [
595+
{
596+
body: htmlBio,
597+
mimetype: 'text/html',
598+
} satisfies MSC1767Text,
599+
{
600+
body: plainTextBio,
601+
} satisfies MSC1767Text,
602+
],
596603
} satisfies MSC4440Bio);
597604

598605
const cleanedHtml = htmlBio.replaceAll('<br/></blockquote>', '</blockquote>');

src/app/hooks/useUserProfile.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import colorMXID from '$utils/colorMXID';
77
import { profilesCacheAtom } from '$state/userRoomProfile';
88
import { useSetting } from '$state/hooks/settings';
99
import { settingsAtom } from '$state/settings';
10+
import { MSC1767Text } from '$types/matrix/common';
1011
import { useMatrixClient } from './useMatrixClient';
1112

1213
const inFlightProfiles = new Map<string, Promise<any>>();
1314

1415
export type MSC4440Bio = {
15-
body: string;
16-
format: string;
17-
formatted_body: string;
16+
'm.text': Array<MSC1767Text>;
1817
};
1918

2019
export type UserProfile = {
@@ -62,7 +61,7 @@ const normalizeInfo = (info: any): UserProfile => {
6261
pronouns: info['io.fsky.nyx.pronouns'],
6362
timezone: info['us.cloke.msc4175.tz'] || info['m.tz'],
6463
bio:
65-
(info['gay.fomx.biography'] satisfies MSC4440Bio).formatted_body ||
64+
(info['gay.fomx.biography'] satisfies MSC4440Bio)['m.text'][0].body ||
6665
info['moe.sable.app.bio'] ||
6766
info['chat.commet.profile_bio'],
6867
status: info['chat.commet.profile_status'],

src/types/matrix/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export type IImageInfo = {
1414
[MATRIX_BLUR_HASH_PROPERTY_NAME]?: string;
1515
};
1616

17+
export type MSC1767Text = {
18+
body: string;
19+
mimetype?: string;
20+
};
21+
1722
export type IVideoInfo = {
1823
w?: number;
1924
h?: number;

0 commit comments

Comments
 (0)