diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index df72b9a7..232bdb0b 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -27,7 +27,7 @@ import { stopPropagation } from '../../utils/keyboard'; import { LINKIFY_OPTS } from '../../plugins/react-custom-html-parser'; import { useSetting } from '../../state/hooks/settings'; import { settingsAtom } from '../../state/settings'; -import { UserPronoun } from '../../hooks/useUserProfile'; +import { UserBiography, UserPronoun } from '../../hooks/useUserProfile'; export function UserHero({ children }: { children: ReactNode }) { return ( @@ -165,7 +165,7 @@ export function UserTimezone({ timezone }: { timezone: string }) { return ( - + {time} local time{offset ? ` · ${offset}` : ` · ${timezone}`} @@ -198,7 +198,9 @@ export function UserHeroName({ displayName, userId, pronouns }: UserHeroNameProp {pronouns?.map((pronoun) => pronoun.summary ? ( - {pronoun.summary} + + {pronoun.summary} + ) : undefined )} @@ -206,3 +208,11 @@ export function UserHeroName({ displayName, userId, pronouns }: UserHeroNameProp ); } + +export function UserHeroBiography({ bio }: { bio: UserBiography }) { + return ( + + {bio.body} + + ); +} diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 9b4fc755..74453653 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -2,7 +2,14 @@ import { Box, Button, config, Icon, Icons, Text } from 'folds'; import React from 'react'; import { useNavigate } from 'react-router-dom'; import { ObjectReader } from 'neurone/lib/utils'; -import { UserHero, UserHeroAvatar, UserHeroCover, UserHeroName, UserTimezone } from './UserHero'; +import { + UserHero, + UserHeroAvatar, + UserHeroBiography, + UserHeroCover, + UserHeroName, + UserTimezone, +} from './UserHero'; import { getMxIdServer } from '../../utils/matrix'; import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { @@ -123,11 +130,8 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) { /> )} + {profile?.biography ? : null} {profile?.timezone && } - - now hierarchy does not have room summary info we need to load it when we will be - rendering it - {server && } diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 97948e63..22de76fb 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -5,24 +5,24 @@ import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { ObjectReader } from 'neurone/lib/utils'; import { useClient } from './useClient'; -type PronounResponse = { - grammatical_gender?: string; - language?: string; - summary?: string; -}; - export type UserPronoun = { grammaticalGender?: string; language?: string; summary?: string; }; +export type UserBiography = { + body: string; + formattedBody?: string; +}; + export type UserProfile = { avatarUrl?: string; displayName?: string; bannerUrl?: string; timezone?: string; pronouns?: UserPronoun[]; + biography?: UserBiography; }; export const useUserProfile = (userId: string): UserProfile | undefined => { const ct = useClient(); @@ -36,15 +36,23 @@ export const useUserProfile = (userId: string): UserProfile | undefined => { const [, profile] = await parseMatrixResp< GetProfileOK & { - 'chat.commet.profile_banner'?: string; - 'm.banner_url'?: string; - 'm.tz'?: string; - 'io.fsky.nyx.pronouns': PronounResponse[]; - 'm.pronouns': PronounResponse[]; + 'chat.commet.profile_banner'?: unknown; + 'm.banner_url'?: unknown; + 'm.tz'?: unknown; + 'io.fsky.nyx.pronouns': unknown; + 'm.pronouns': unknown; + 'm.biography': unknown; + 'gay.fomx.biography': unknown; } >(response); const pronouns = profile?.['m.pronouns'] ?? profile?.['io.fsky.nyx.pronouns']; + const bio = profile?.['m.biography'] ?? profile?.['gay.fomx.biography']; + const bioText = ObjectReader.array(bio, 'm.text'); + + const plainBio = bioText?.find((i) => ObjectReader.string(i, 'mimetype') !== 'text/html'); + const htmlBio = bioText?.find((i) => ObjectReader.string(i, 'mimetype') === 'text/html'); + const bioBody = ObjectReader.string(plainBio, 'body') ?? ObjectReader.string(htmlBio, 'body'); return { avatarUrl: profile?.avatar_url || undefined, @@ -53,11 +61,19 @@ export const useUserProfile = (userId: string): UserProfile | undefined => { ObjectReader.string(profile, 'm.banner_url') ?? ObjectReader.string(profile, 'chat.commet.profile_banner'), timezone: ObjectReader.string(profile, 'm.tz'), - pronouns: pronouns?.map((p) => ({ - grammaticalGender: ObjectReader.string(p, 'grammatical_gender'), - language: ObjectReader.string(p, 'language'), - summary: ObjectReader.string(p, 'summary'), - })), + pronouns: Array.isArray(pronouns) + ? pronouns?.map((p) => ({ + grammaticalGender: ObjectReader.string(p, 'grammatical_gender'), + language: ObjectReader.string(p, 'language'), + summary: ObjectReader.string(p, 'summary'), + })) + : undefined, + biography: bioBody + ? { + body: bioBody, + formattedBody: ObjectReader.string(htmlBio, 'body'), + } + : undefined, }; }, [ct, userId]);