Skip to content

Commit 6e238ef

Browse files
committed
first implementation of MSC4440 Bios (will have to be changed later)
1 parent 0fcc38c commit 6e238ef

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { useSetAtom } from 'jotai';
2929
import { SequenceCard } from '$components/sequence-card';
3030
import { SettingTile } from '$components/setting-tile';
3131
import { useMatrixClient } from '$hooks/useMatrixClient';
32-
import { UserProfile, useUserProfile } from '$hooks/useUserProfile';
32+
import { UserProfile, useUserProfile, MSC4440Bio } from '$hooks/useUserProfile';
3333
import { getMxIdLocalPart, mxcUrlToHttp } from '$utils/matrix';
3434
import { UserAvatar } from '$components/user-avatar';
3535
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
@@ -52,6 +52,7 @@ import { BioEditor } from './BioEditor';
5252
import { NameColorEditor } from './NameColorEditor';
5353
import { StatusEditor } from './StatusEditor';
5454
import { AnimalCosmetics } from './AnimalCosmetics';
55+
import { toPlainText } from '$components/editor';
5556

5657
type PronounSet = {
5758
summary: string;
@@ -576,13 +577,24 @@ function ProfileExtended({ profile, userId }: Readonly<ProfileProps>) {
576577
>
577578
<BioEditor
578579
value={
580+
(profile.extended?.['gay.fomx.biography'] satisfies MSC4440Bio)?.formatted_body ||
579581
profile.extended?.['moe.sable.app.bio'] ||
580582
profile.extended?.['chat.commet.profile_bio'] ||
581583
profile.bio
582584
}
583585
onSave={(htmlBio) => {
584586
handleSaveField('moe.sable.app.bio', htmlBio);
585587

588+
// MSC4440
589+
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,
596+
} satisfies MSC4440Bio);
597+
586598
const cleanedHtml = htmlBio.replaceAll('<br/></blockquote>', '</blockquote>');
587599
handleSaveField('chat.commet.profile_bio', {
588600
format: 'org.matrix.custom.html',

src/app/hooks/useUserProfile.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import { useMatrixClient } from './useMatrixClient';
1111

1212
const inFlightProfiles = new Map<string, Promise<any>>();
1313

14+
export type MSC4440Bio = {
15+
body: string;
16+
format: string;
17+
formatted_body: string;
18+
};
19+
1420
export type UserProfile = {
1521
avatarUrl?: string;
1622
displayName?: string;
@@ -35,6 +41,7 @@ const normalizeInfo = (info: any): UserProfile => {
3541
'm.tz',
3642
'moe.sable.app.bio',
3743
'chat.commet.profile_bio',
44+
'gay.fomx.biography',
3845
'chat.commet.profile_banner',
3946
'chat.commet.profile_status',
4047
'moe.sable.app.name_color',
@@ -54,7 +61,10 @@ const normalizeInfo = (info: any): UserProfile => {
5461
displayName: info.displayname,
5562
pronouns: info['io.fsky.nyx.pronouns'],
5663
timezone: info['us.cloke.msc4175.tz'] || info['m.tz'],
57-
bio: info['moe.sable.app.bio'] || info['chat.commet.profile_bio'],
64+
bio:
65+
(info['gay.fomx.biography'] satisfies MSC4440Bio).formatted_body ||
66+
info['moe.sable.app.bio'] ||
67+
info['chat.commet.profile_bio'],
5868
status: info['chat.commet.profile_status'],
5969
bannerUrl: info['chat.commet.profile_banner'],
6070
nameColor: info['moe.sable.app.name_color'],

0 commit comments

Comments
 (0)