name colors + other stuff cuz i messed up branch switching lmao
This commit is contained in:
1 parent
b89ace1b75
commit
bc43bb74cf
10 files changed
+212
-30
No files matched your search
@@ -1,5 +1,10 @@
|
||||
# Sable Client Changelog
|
||||
|
||||
## Version 1.1.2
|
||||
|
||||
- Profile banners. Support's Commet's format.
|
||||
- Global name colors. Can be disabled in settings.
|
||||
|
||||
## Version 1.1.1
|
||||
|
||||
- More cache fixes and improvements.
|
||||
|
||||
@@ -38,6 +38,7 @@ const KNOWN_KEYS = [
|
||||
'io.fsky.nyx.pronouns',
|
||||
'us.cloke.msc4175.tz',
|
||||
'm.tz',
|
||||
'moe.sable.app.name_color',
|
||||
'avatar_url',
|
||||
'displayname'
|
||||
];
|
||||
|
||||
@@ -18,6 +18,7 @@ export const UserHeroCoverContainer = style({
|
||||
height: toRem(96),
|
||||
overflow: 'hidden',
|
||||
});
|
||||
|
||||
export const UserHeroCover = style({
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
|
||||
@@ -1081,6 +1081,8 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
delete cleanExtended['chat.commet.profile_bio'];
|
||||
delete cleanExtended['us.cloke.msc4175.tz'];
|
||||
delete cleanExtended['m.tz'];
|
||||
delete cleanExtended['chat.commet.profile_banner'];
|
||||
delete cleanExtended['moe.sable.app.name_color'];
|
||||
delete cleanExtended['avatar_url'];
|
||||
delete cleanExtended['displayname'];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Box, Button, config, Text, Input, IconButton, Icon, Icons } from 'folds';
|
||||
import { HexColorPicker } from 'react-colorful';
|
||||
import { SettingTile } from '../../../components/setting-tile';
|
||||
import { HexColorPickerPopOut } from '../../../components/HexColorPickerPopOut';
|
||||
|
||||
type NameColorEditorProps = {
|
||||
current?: string;
|
||||
onSave: (color: string | null) => void;
|
||||
};
|
||||
|
||||
export function NameColorEditor({ current, onSave }: NameColorEditorProps) {
|
||||
const [tempColor, setTempColor] = useState(current || '#FFFFFF');
|
||||
const [hasChanged, setHasChanged] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (current) setTempColor(current);
|
||||
else setTempColor('#FFFFFF');
|
||||
}, [current]);
|
||||
|
||||
const handleUpdate = (newColor: string) => {
|
||||
const sanitized = newColor.startsWith('#') ? newColor : `#${newColor}`;
|
||||
setTempColor(sanitized);
|
||||
setHasChanged(sanitized.toUpperCase() !== (current?.toUpperCase() || '#FFFFFF'));
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
if (/^#[0-9A-F]{6}$/i.test(tempColor)) {
|
||||
onSave(tempColor);
|
||||
setHasChanged(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
onSave(null);
|
||||
setHasChanged(false);
|
||||
setTempColor('#FFFFFF');
|
||||
};
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<SettingTile
|
||||
title="Global Name Color"
|
||||
description="Custom name color everywhere names have color!"
|
||||
/>
|
||||
<Box
|
||||
alignItems="Center"
|
||||
justifyContent="SpaceBetween"
|
||||
gap="300"
|
||||
style={{
|
||||
padding: config.space.S400,
|
||||
backgroundColor: 'var(--sable-surface-container)',
|
||||
borderRadius: config.radii.R400
|
||||
}}
|
||||
>
|
||||
<Box alignItems="Center" gap="300" grow="Yes">
|
||||
<HexColorPickerPopOut
|
||||
picker={
|
||||
<HexColorPicker
|
||||
color={tempColor}
|
||||
onChange={handleUpdate}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{(onOpen, opened) => (
|
||||
<Button
|
||||
onClick={onOpen}
|
||||
size="400"
|
||||
variant="Secondary"
|
||||
fill="None"
|
||||
radii="300"
|
||||
style={{
|
||||
padding: config.space.S100,
|
||||
border: `2px solid ${opened ? 'var(--sable-primary-main)' : 'var(--sable-border-focus)'}`
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
style={{
|
||||
width: '32px',
|
||||
height: '32px',
|
||||
borderRadius: '50%',
|
||||
backgroundColor: tempColor,
|
||||
boxShadow: 'inset 0 0 0 1px rgba(0,0,0,0.1)'
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</HexColorPickerPopOut>
|
||||
|
||||
<Box direction="Row" alignItems="Center" gap="100">
|
||||
<Input
|
||||
value={tempColor}
|
||||
onChange={(e) => handleUpdate(e.currentTarget.value)}
|
||||
placeholder="#FFFFFF"
|
||||
variant="Background"
|
||||
size="300"
|
||||
radii="300"
|
||||
style={{
|
||||
textTransform: 'uppercase',
|
||||
fontFamily: 'monospace',
|
||||
width: '100px'
|
||||
}}
|
||||
/>
|
||||
{current && (
|
||||
<IconButton
|
||||
variant="Secondary"
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={handleReset}
|
||||
title="Reset to default"
|
||||
>
|
||||
<Icon src={Icons.Cross} size="100" />
|
||||
</IconButton>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{hasChanged && (
|
||||
<Button
|
||||
variant="Primary"
|
||||
size="300"
|
||||
radii="Pill"
|
||||
onClick={handleSave}
|
||||
disabled={!/^#[0-9A-F]{6}$/i.test(tempColor)}
|
||||
>
|
||||
<Text size="B300">Save</Text>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import { useCapabilities } from '../../../hooks/useCapabilities';
|
||||
import { TimezoneEditor } from './TimezoneEditor';
|
||||
import { PronounEditor } from './PronounEditor';
|
||||
import { BioEditor } from './BioEditor';
|
||||
import { NameColorEditor } from './NameColorEditor';
|
||||
|
||||
type PronounSet = {
|
||||
summary: string;
|
||||
@@ -328,6 +329,12 @@ function ProfileExtended({ profile, userId }: ProfileProps) {
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Extended Profile</Text>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column" gap="400">
|
||||
<NameColorEditor
|
||||
current={profile.extended?.["moe.sable.app.name_color"]}
|
||||
onSave={(color) => handleSaveField("moe.sable.app.name_color", color)}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column" gap="400">
|
||||
<PronounEditor
|
||||
current={pronouns}
|
||||
|
||||
@@ -153,6 +153,7 @@ function Privacy() {
|
||||
function IdentityCosmetics() {
|
||||
const [legacyUsernameColor, setLegacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor');
|
||||
const [showPronouns, setShowPronouns] = useSetting(settingsAtom, 'showPronouns');
|
||||
const [renderGlobalColors, setRenderGlobalColors] = useSetting(settingsAtom, 'renderGlobalNameColors');
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
@@ -166,11 +167,18 @@ function IdentityCosmetics() {
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Pronouns"
|
||||
title="Show Pronoun Pills"
|
||||
description="Display user pronouns in the message timeline."
|
||||
after={<Switch variant="Primary" value={showPronouns} onChange={setShowPronouns} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Render Global Username Colors"
|
||||
description="Display the username colors anyone can set in their account settings."
|
||||
after={<Switch variant="Primary" value={renderGlobalColors} onChange={setRenderGlobalColors} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { EventTimeline, Room } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
@@ -11,6 +12,7 @@ import colorMXID from '../../util/colorMXID';
|
||||
import { useRoomCreatorsTag } from './useRoomCreatorsTag';
|
||||
import { usePowerLevelTags } from './usePowerLevelTags';
|
||||
import { useTheme } from './useTheme';
|
||||
import { profilesCacheAtom } from '../state/userRoomProfile';
|
||||
|
||||
const isValidHex = (c: string) => /^#[0-9A-F]{6}$/i.test(c);
|
||||
const sanitizeFont = (f: string) => f.replace(/[;{}<>]/g, '').slice(0, 32);
|
||||
@@ -19,7 +21,11 @@ export function useSableCosmetics(userId: string, room: Room) {
|
||||
const mx = useMatrixClient();
|
||||
const theme = useTheme();
|
||||
|
||||
const globalProfiles = useAtomValue(profilesCacheAtom);
|
||||
|
||||
const [legacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor');
|
||||
const [renderGlobalColors] = useSetting(settingsAtom, 'renderGlobalNameColors');
|
||||
|
||||
const powerLevels = usePowerLevels(room);
|
||||
const creators = useRoomCreators(room);
|
||||
|
||||
@@ -72,6 +78,15 @@ export function useSableCosmetics(userId: string, room: Room) {
|
||||
?.getContent()?.font;
|
||||
}
|
||||
|
||||
// global name color
|
||||
const cachedProfile = globalProfiles[userId];
|
||||
const hasGlobalColor = cachedProfile?.nameColor && isValidHex(cachedProfile.nameColor);
|
||||
// show if its on, or the user is you
|
||||
const isMe = userId === mx.getUserId();
|
||||
const validGlobal = (renderGlobalColors || isMe) && hasGlobalColor
|
||||
? cachedProfile.nameColor
|
||||
: undefined;
|
||||
|
||||
// resolve traditional fallbacks
|
||||
const memberPowerTag = getPowerTag(userId);
|
||||
const tagColor = memberPowerTag?.color ? accessibleTagColors?.get(memberPowerTag.color) : undefined;
|
||||
@@ -81,7 +96,8 @@ export function useSableCosmetics(userId: string, room: Room) {
|
||||
const validSpace = spaceColor && isValidHex(spaceColor) ? spaceColor : undefined;
|
||||
|
||||
// color decision hierarchy
|
||||
const resolvedColor = validLocal || validSpace || (legacyUsernameColor ? colorMXID(userId) : tagColor);
|
||||
// Room > Space > Global (if enabled) > Random Colors (if enabled) > Tag
|
||||
const resolvedColor = validLocal || validSpace || validGlobal || (legacyUsernameColor ? colorMXID(userId) : tagColor);
|
||||
|
||||
// font decision hierarchy
|
||||
const rawFont = localFont || spaceFont;
|
||||
@@ -92,5 +108,5 @@ export function useSableCosmetics(userId: string, room: Room) {
|
||||
}
|
||||
|
||||
return { color: resolvedColor, font: resolvedFont };
|
||||
}, [room, userId, mx, getPowerTag, accessibleTagColors, legacyUsernameColor]);
|
||||
}, [room, userId, mx, getPowerTag, accessibleTagColors, legacyUsernameColor, renderGlobalColors, globalProfiles]);
|
||||
}
|
||||
@@ -10,6 +10,8 @@ export type UserProfile = {
|
||||
pronouns?: any[];
|
||||
timezone?: string;
|
||||
bio?: string;
|
||||
bannerUrl?: string;
|
||||
nameColor?: string;
|
||||
extended?: Record<string, any>;
|
||||
};
|
||||
|
||||
@@ -17,33 +19,6 @@ export const useUserProfile = (userId: string, initialProfile?: Partial<UserProf
|
||||
const mx = useMatrixClient();
|
||||
const [globalProfiles, setGlobalProfiles] = useAtom(profilesCacheAtom);
|
||||
|
||||
const normalizeInfo = useCallback((info: any): UserProfile => {
|
||||
const normalized: 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'],
|
||||
extended: {},
|
||||
};
|
||||
|
||||
const knownKeys = [
|
||||
'avatar_url',
|
||||
'displayname',
|
||||
'io.fsky.nyx.pronouns',
|
||||
'us.cloke.msc4175.tz', 'm.tz',
|
||||
'moe.sable.app.bio', 'chat.commet.profile_bio'
|
||||
];
|
||||
|
||||
Object.keys(info).forEach((key) => {
|
||||
if (!knownKeys.includes(key)) {
|
||||
normalized.extended![key] = info[key];
|
||||
}
|
||||
});
|
||||
|
||||
return normalized;
|
||||
}, []);
|
||||
|
||||
const [profile, setProfile] = useState<UserProfile>(() => {
|
||||
const user = mx.getUser(userId);
|
||||
const cached = globalProfiles[userId];
|
||||
@@ -53,10 +28,43 @@ export const useUserProfile = (userId: string, initialProfile?: Partial<UserProf
|
||||
pronouns: cached?.pronouns ?? initialProfile?.pronouns,
|
||||
timezone: cached?.timezone ?? initialProfile?.timezone,
|
||||
bio: cached?.bio ?? initialProfile?.bio,
|
||||
bannerUrl: cached?.bannerUrl ?? initialProfile?.bannerUrl,
|
||||
nameColor: cached?.nameColor ?? initialProfile?.nameColor,
|
||||
extended: cached?.extended ?? initialProfile?.extended,
|
||||
};
|
||||
});
|
||||
|
||||
const normalizeInfo = useCallback((info: any): UserProfile => {
|
||||
const normalized: 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: { ...(profile?.extended || {}) },
|
||||
};
|
||||
|
||||
const knownKeys = [
|
||||
'avatar_url',
|
||||
'displayname',
|
||||
'io.fsky.nyx.pronouns',
|
||||
'us.cloke.msc4175.tz', 'm.tz',
|
||||
'moe.sable.app.bio', 'chat.commet.profile_bio',
|
||||
'moe.sable.app.name_color',
|
||||
'chat.commet.profile_banner'
|
||||
];
|
||||
|
||||
Object.keys(info).forEach((key) => {
|
||||
if (!knownKeys.includes(key)) {
|
||||
normalized.extended![key] = info[key];
|
||||
}
|
||||
});
|
||||
|
||||
return normalized;
|
||||
}, [profile?.extended]);
|
||||
|
||||
useEffect(() => {
|
||||
const user = mx.getUser(userId);
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ export interface Settings {
|
||||
privacyBlurAvatars: boolean;
|
||||
privacyBlurEmotes: boolean;
|
||||
showPronouns: boolean,
|
||||
renderGlobalNameColors: boolean;
|
||||
|
||||
// Sable features!
|
||||
mobileGestures: boolean;
|
||||
@@ -102,6 +103,7 @@ const defaultSettings: Settings = {
|
||||
privacyBlurAvatars: false,
|
||||
privacyBlurEmotes: false,
|
||||
showPronouns: true,
|
||||
renderGlobalNameColors: true,
|
||||
|
||||
// Sable features!
|
||||
mobileGestures: true,
|
||||
|
||||
Reference in new issue
Block a user