mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
fix/update unknown extended profile keys rendering
This commit is contained in:
1 parent
9184dc7060
commit
550df5efc3
2 files changed
+46
-16
No files matched your search
@@ -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]) => (
|
||||
<Box key={key} direction="Column" style={{ marginBottom: config.space.S100 }}>
|
||||
<Text size="T200" priority="400" style={{ letterSpacing: '0.05em' }}>
|
||||
{clamp(key, 64).split('.').pop()?.replace(/_/g, ' ')}
|
||||
{key}
|
||||
</Text>
|
||||
<Text size="T200" priority="300">
|
||||
{String(clamp(value, 64))}
|
||||
{clamp(renderValue(value), 128)}
|
||||
</Text>
|
||||
</Box>
|
||||
))}
|
||||
|
||||
@@ -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<string, any> = {};
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user