From 550df5efc38385a5ae9fe7dd4c46bb2f26fbeae1 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sat, 28 Feb 2026 15:47:43 -0600 Subject: [PATCH] fix/update unknown extended profile keys rendering --- .../user-profile/UserRoomProfile.tsx | 19 +++++--- src/app/hooks/useUserProfile.ts | 43 ++++++++++++++----- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 5a32b5a97..6a9682bc2 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -60,9 +60,19 @@ function UserExtendedSection({ htmlReactParserOptions, linkifyOpts, }: UserExtendedSectionProps) { - const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str); + const clamp = (str: any, len: number) => { + const stringified = String(str ?? ''); + return stringified.length > len ? `${stringified.slice(0, len)}...` : stringified; + }; const [showMore, setShowMore] = useState(false); + const renderValue = (val: any) => { + if (val === null || val === undefined) return 'n/a'; + if (typeof val === 'boolean') return val ? 'Yes' : 'No'; + if (typeof val === 'object') return JSON.stringify(val); + return String(val); + }; + const pronouns = profile.pronouns?.map((p: any) => clamp(p.summary, 16)).join(', '); const timezone = profile.timezone ? clamp(profile.timezone, 64) : null; const localTime = timezone @@ -102,8 +112,7 @@ function UserExtendedSection({ }, [profile]); const unknownFields = Object.entries(profile.extended || {}).filter( - ([key, value]) => - !KNOWN_KEYS.includes(key) && (typeof value === 'string' || typeof value === 'number') + ([key]) => !KNOWN_KEYS.includes(key) ); return ( @@ -182,10 +191,10 @@ function UserExtendedSection({ {unknownFields.map(([key, value]) => ( - {clamp(key, 64).split('.').pop()?.replace(/_/g, ' ')} + {key} - {String(clamp(value, 64))} + {clamp(renderValue(value), 128)} ))} diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 393fb0033..9a419c842 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -23,17 +23,38 @@ export type UserProfile = { _fetched?: boolean; }; -const normalizeInfo = (info: any): UserProfile => ({ - avatarUrl: info.avatar_url, - displayName: info.displayname, - pronouns: info['io.fsky.nyx.pronouns'], - timezone: info['us.cloke.msc4175.tz'] || info['m.tz'], - bio: info['moe.sable.app.bio'] || info['chat.commet.profile_bio'], - bannerUrl: info['chat.commet.profile_banner'], - nameColor: info['moe.sable.app.name_color'], - extended: {}, - _fetched: true, -}); +const normalizeInfo = (info: any): UserProfile => { + const knownKeys = [ + 'avatar_url', + 'displayname', + 'io.fsky.nyx.pronouns', + 'us.cloke.msc4175.tz', + 'm.tz', + 'moe.sable.app.bio', + 'chat.commet.profile_bio', + 'chat.commet.profile_banner', + 'moe.sable.app.name_color', + ]; + + const extended: Record = {}; + Object.entries(info).forEach(([key, value]) => { + if (!knownKeys.includes(key)) { + extended[key] = value; + } + }); + + return { + avatarUrl: info.avatar_url, + displayName: info.displayname, + pronouns: info['io.fsky.nyx.pronouns'], + timezone: info['us.cloke.msc4175.tz'] || info['m.tz'], + bio: info['moe.sable.app.bio'] || info['chat.commet.profile_bio'], + bannerUrl: info['chat.commet.profile_banner'], + nameColor: info['moe.sable.app.name_color'], + extended, + _fetched: true, + }; +}; const isValidHex = (c: string) => /^#[0-9A-F]{6}$/i.test(c); const sanitizeFont = (f: string) => f.replace(/[;{}<>]/g, '').slice(0, 32);