Skip to content

Commit 0c62e75

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

5 files changed

Lines changed: 26 additions & 14 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/BioEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type BioEditorProps = {
4444
value?: string | any;
4545
isSaving?: boolean;
4646
imagePackRooms?: any[];
47-
onSave: (htmlContent: string) => void;
47+
onSave: (htmlContent: string, plainText: string) => void;
4848
};
4949

5050
const BIO_LIMIT = 1024;
@@ -81,7 +81,7 @@ export function BioEditor({ value, isSaving, imagePackRooms, onSave }: BioEditor
8181
})
8282
);
8383

84-
onSave(customHtml || plainText);
84+
onSave(customHtml || plainText, plainText);
8585
setHasChanged(false);
8686
}, [editor, isMarkdown, onSave]);
8787

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

Lines changed: 11 additions & 8 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;
@@ -582,17 +582,20 @@ function ProfileExtended({ profile, userId }: Readonly<ProfileProps>) {
582582
profile.extended?.['chat.commet.profile_bio'] ||
583583
profile.bio
584584
}
585-
onSave={(htmlBio) => {
585+
onSave={(htmlBio, plainTextBio) => {
586586
handleSaveField('moe.sable.app.bio', htmlBio);
587587

588588
// MSC4440
589589
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,
590+
'm.text': [
591+
{
592+
body: htmlBio,
593+
mimetype: 'text/html',
594+
} satisfies MSC1767Text,
595+
{
596+
body: plainTextBio,
597+
} satisfies MSC1767Text,
598+
],
596599
} satisfies MSC4440Bio);
597600

598601
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)