Change profile pronouns to closer follow MSC4247
Fixes #23 The pronouns field is an array of pronoun sets rather than the entire array representing one set. This follows MSC4247, and aligns with the way it's displayed in gomuks and Commet. For compatibility with gomuks, the value of `language` for each is set to "en". In the future this should be set manually or use the client language. Pronoun summaries are limited to 16 characters each, and truncated to that length if it is longer. When displayed as a string, or when it is set, they are comma separated. When they are displayed next to the username in a message, they're each in an individual pill, only showing the first 3. If more than 3 are there, an extra pill showing "..." is displayed. An optional `grammatical_gender` field now exists, however it is currently unused.
This commit is contained in:
3 files changed
+23
-21
No files matched your search
@@ -63,7 +63,7 @@ function UserExtendedSection({
|
||||
const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str);
|
||||
const [showMore, setShowMore] = useState(false);
|
||||
|
||||
const pronouns = profile.pronouns?.map((p: any) => clamp(p.summary, 20)).join('/');
|
||||
const pronouns = profile.pronouns?.map((p: any) => clamp(p.summary, 16)).join(', ');
|
||||
const timezone = profile.timezone ? clamp(profile.timezone, 64) : null;
|
||||
const localTime = timezone
|
||||
? new Intl.DateTimeFormat([], {
|
||||
|
||||
@@ -249,20 +249,7 @@ function useMobileDoubleTap(callback: () => void, delay = 300) {
|
||||
);
|
||||
}
|
||||
|
||||
function PronounTag({ pronouns, tagColor }: { pronouns?: any[]; tagColor: string }) {
|
||||
if (!pronouns || pronouns.length === 0) return null;
|
||||
|
||||
const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str);
|
||||
|
||||
const display = clamp(
|
||||
pronouns
|
||||
.slice(0, 2)
|
||||
.map((p) => clamp(p.summary, 48))
|
||||
.join('/'),
|
||||
128
|
||||
);
|
||||
const hasMore = pronouns.length > 2;
|
||||
|
||||
function PronounPill({ summary, tagColor }: { summary: string; tagColor: string }) {
|
||||
return (
|
||||
<Box
|
||||
alignItems="Center"
|
||||
@@ -283,13 +270,27 @@ function PronounTag({ pronouns, tagColor }: { pronouns?: any[]; tagColor: string
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
{display}
|
||||
{hasMore ? '...' : ''}
|
||||
{summary}
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
function PronounTag({ pronouns, tagColor }: { pronouns?: any[]; tagColor: string }) {
|
||||
if (!pronouns || pronouns.length === 0) return null;
|
||||
|
||||
const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str);
|
||||
|
||||
const display = pronouns
|
||||
.slice(0, 3)
|
||||
.map((p) => <PronounPill summary={clamp(p.summary, 16)} tagColor={tagColor} />);
|
||||
|
||||
if (pronouns.length > 3) {
|
||||
display.push(<PronounPill summary="..." tagColor={tagColor} />);
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
function MessageInternal(
|
||||
{
|
||||
className,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { SettingTile } from '$components/setting-tile';
|
||||
type PronounSet = {
|
||||
summary: string;
|
||||
language?: string;
|
||||
grammatical_gender?: string;
|
||||
};
|
||||
|
||||
type PronounEditorProps = {
|
||||
@@ -13,7 +14,7 @@ type PronounEditorProps = {
|
||||
};
|
||||
|
||||
export function PronounEditor({ current, onSave }: PronounEditorProps) {
|
||||
const initialString = current.map((p) => p.summary).join('/');
|
||||
const initialString = current.map((p) => p.summary).join(', ');
|
||||
const [val, setVal] = useState(initialString);
|
||||
|
||||
useEffect(() => setVal(initialString), [initialString]);
|
||||
@@ -22,10 +23,10 @@ export function PronounEditor({ current, onSave }: PronounEditorProps) {
|
||||
if (val === initialString) return;
|
||||
const safeVal = val.slice(0, 128);
|
||||
const next = safeVal
|
||||
.split('/')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
.map((s) => ({ summary: s.slice(0, 16) }));
|
||||
.map((s) => ({ summary: s.slice(0, 16), language: "en" }));
|
||||
onSave(next);
|
||||
};
|
||||
|
||||
@@ -36,7 +37,7 @@ export function PronounEditor({ current, onSave }: PronounEditorProps) {
|
||||
return (
|
||||
<SettingTile
|
||||
title="Pronouns"
|
||||
description="Separate with slashes (e.g. they/them)."
|
||||
description="Separate sets with commas (e.g. 'they/them, it/its')."
|
||||
after={
|
||||
<Input
|
||||
value={val}
|
||||
|
||||
Reference in new issue
Block a user