diff --git a/CHANGELOG.md b/CHANGELOG.md
index 82da2141..5e19e84c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
- Bug fix for images/links/anything that loads after room is opened, properly shifting the scroll to the bottom.
- Client-side nicknames for other users. PR #3
- Inline editor for editing messages.
+- Pronouns and timezones.
- Pressing send on mobile no longer closes keyboard.
- Pressing enter on mobile will always provide a newline, ignores the setting for desktop.
- More reactive UI (literally just buttons shifting up and shrinking on click)
diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx
index d44bf154..a996a263 100644
--- a/src/app/components/user-profile/UserRoomProfile.tsx
+++ b/src/app/components/user-profile/UserRoomProfile.tsx
@@ -1,6 +1,7 @@
import { Box, Button, config, Icon, Icons, Text } from 'folds';
-import React from 'react';
+import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
+import { useAtomValue } from 'jotai';
import { UserHero, UserHeroName } from './UserHero';
import { getMxIdServer, mxcUrlToHttp } from '../../utils/matrix';
import { getMemberAvatarMxc, getMemberDisplayName } from '../../utils/room';
@@ -22,8 +23,84 @@ import { useMemberPowerCompare } from '../../hooks/useMemberPowerCompare';
import { CreatorChip } from './CreatorChip';
import { getDirectCreatePath, withSearchParam } from '../../pages/pathUtils';
import { DirectCreateSearchParams } from '../../pages/paths';
-import { useAtomValue } from 'jotai';
import { nicknamesAtom } from '../../state/nicknames';
+import { UserProfile, useUserProfile } from '../../hooks/useUserProfile';
+
+
+function UserExtendedSection({ profile }: { profile: UserProfile }) {
+ 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 timezone = profile.timezone ? clamp(profile.timezone, 64) : null;
+ const localTime = timezone ? new Intl.DateTimeFormat([], {
+ hour: 'numeric',
+ minute: '2-digit',
+ timeZone: timezone,
+ }).format(new Date()) : null;
+
+ const unknownFields = Object.entries(profile.extended || {}).filter(([, value]) =>
+ typeof value === 'string' || typeof value === 'number');
+
+ if (!pronouns && !localTime && unknownFields.length === 0) return null;
+
+ return (
+
+ {pronouns && (
+
+
+ {pronouns}
+
+ )}
+
+ {localTime && (
+
+
+
+ {localTime}
+ Local Time ({profile.timezone})
+
+
+ )}
+
+ {unknownFields.length > 0 && (
+
+
+
+ {showMore && (
+
+ {unknownFields.map(([key, value]) => (
+
+
+ {clamp(key, 64).split('.').pop()?.replace(/_/g, ' ')}
+
+ {String(clamp(value, 64))}
+
+ ))}
+
+ )}
+
+ )}
+
+ );
+}
+
type UserRoomProfileProps = {
userId: string;
@@ -70,6 +147,8 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) {
navigate(withSearchParam(getDirectCreatePath(), directSearchParam));
};
+ const extendedProfile = useUserProfile(userId);
+
return (
)}
+
{server && }
@@ -142,4 +222,4 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) {
);
-}
+}
\ No newline at end of file
diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx
index e982a799..5bdbc869 100644
--- a/src/app/features/settings/account/Profile.tsx
+++ b/src/app/features/settings/account/Profile.tsx
@@ -25,6 +25,7 @@ import {
Spinner,
} from 'folds';
import FocusTrap from 'focus-trap-react';
+import { MatrixClient } from 'matrix-js-sdk';
import { SequenceCard } from '../../../components/sequence-card';
import { SequenceCardStyle } from '../styles.css';
import { SettingTile } from '../../../components/setting-tile';
@@ -43,6 +44,13 @@ import { ModalWide } from '../../../styles/Modal.css';
import { createUploadAtom, UploadSuccess } from '../../../state/upload';
import { CompactUploadCardRenderer } from '../../../components/upload-card';
import { useCapabilities } from '../../../hooks/useCapabilities';
+import { TimezoneEditor } from './TimezoneEditor';
+import { PronounEditor } from './PronounEditor';
+
+type PronounSet = {
+ summary: string;
+ language?: string;
+};
type ProfileProps = {
profile: UserProfile;
@@ -303,23 +311,86 @@ function ProfileDisplayName({ profile, userId }: ProfileProps) {
);
}
+function ProfileExtended({ profile, userId }: ProfileProps) {
+ const mx = useMatrixClient();
+
+ const pronouns = (profile.pronouns as PronounSet[]) || [];
+
+ // Unknown fields / unimplemented non-matrix-spec fields
+ // Only renders them, can't edit or set
+ const extendedFields = Object.entries(profile.extended || {});
+
+ const handleSaveField = useCallback((key: string, value: any) => {
+ (mx as MatrixClient).setExtendedProfileProperty?.(key, value);
+ }, [mx]);
+
+ return (
+
+ Extended Profile
+
+ {
+ handleSaveField("us.cloke.msc4175.tz", tz);
+ }}
+ />
+
+
+ handleSaveField("io.fsky.nyx.pronouns", p)}
+ />
+
+
+ {extendedFields.length > 0 && extendedFields.map(([key, value]) => {
+ if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
+ return null;
+ }
+
+ const strVal = String(value);
+ if (
+ (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') ||
+ strVal.length > 256
+ ) {
+ return null;
+ }
+
+ return (
+
+ {strVal}}
+ />
+
+ );
+ })}
+
+ );
+}
+
+
export function Profile() {
const mx = useMatrixClient();
const userId = mx.getUserId()!;
const profile = useUserProfile(userId);
return (
-
- Profile
-
-
-
-
+
+
+ Profile
+
+
+
+
+
+
);
}
diff --git a/src/app/features/settings/account/PronounEditor.tsx b/src/app/features/settings/account/PronounEditor.tsx
new file mode 100644
index 00000000..fffc79c2
--- /dev/null
+++ b/src/app/features/settings/account/PronounEditor.tsx
@@ -0,0 +1,55 @@
+import React, { useState, useEffect, ChangeEvent } from 'react';
+import { Input } from 'folds';
+import { SettingTile } from '../../../components/setting-tile';
+
+type PronounSet = {
+ summary: string;
+ language?: string;
+};
+
+type PronounEditorProps = {
+ current: PronounSet[];
+ onSave: (p: PronounSet[]) => void;
+};
+
+export function PronounEditor({ current, onSave }: PronounEditorProps) {
+ const initialString = current.map(p => p.summary).join("/");
+ const [val, setVal] = useState(initialString);
+
+ useEffect(() => setVal(initialString), [initialString]);
+
+ const handleSave = () => {
+ if (val === initialString) return;
+ const safeVal = val.slice(0, 128);
+ const next = safeVal
+ .split('/')
+ .map(s => s.trim())
+ .filter(Boolean)
+ .map(s => ({ summary: s.slice(0, 16) }));
+ onSave(next);
+ };
+
+ const handleChange = (e: ChangeEvent) => {
+ setVal(e.currentTarget.value);
+ };
+
+ return (
+ e.key === 'Enter' && handleSave()}
+ style={{ width: '232px' }}
+ />
+ }
+ />
+ );
+}
\ No newline at end of file
diff --git a/src/app/features/settings/account/TimezoneEditor.tsx b/src/app/features/settings/account/TimezoneEditor.tsx
new file mode 100644
index 00000000..cca38e54
--- /dev/null
+++ b/src/app/features/settings/account/TimezoneEditor.tsx
@@ -0,0 +1,80 @@
+import React, { useMemo, useState, useEffect, ChangeEvent } from 'react';
+import { Box, IconButton, Icon, Icons, Input } from 'folds';
+import { SettingTile } from '../../../components/setting-tile';
+
+interface IntlWithSupportedValues {
+ supportedValuesOf(key: 'timeZone' | string): string[];
+}
+
+type TimezoneEditorProps = {
+ current?: string;
+ onSave: (tz: string) => void;
+};
+
+export function TimezoneEditor({ current, onSave }: TimezoneEditorProps) {
+ const [val, setVal] = useState(current ?? '');
+ const zones = useMemo(() => {
+ const intlPolyfill = (Intl as unknown as IntlWithSupportedValues);
+ return intlPolyfill.supportedValuesOf("timeZone");
+ }, []);
+
+ useEffect(() => setVal(current ?? ''), [current]);
+
+ const handleSync = () => {
+ const systemTz = Intl.DateTimeFormat().resolvedOptions().timeZone;
+ setVal(systemTz);
+ onSave(systemTz);
+ };
+
+ const handleManualSave = () => {
+ const trimmed = val.trim().slice(0, 64);
+ const matchedZone = zones.find(z => z.toLowerCase() === trimmed.toLowerCase());
+ if (matchedZone && matchedZone !== current) {
+ onSave(matchedZone);
+ setVal(matchedZone);
+ }
+ };
+
+ const handleChange = (e: ChangeEvent) => {
+ setVal(e.currentTarget.value);
+ };
+
+ return (
+
+ e.key === 'Enter' && handleManualSave()}
+ style={{ width: '180px' }}
+ />
+
+
+
+
+
+ }
+ />
+ );
+}
\ No newline at end of file
diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts
index c7cb7487..56848b5c 100644
--- a/src/app/hooks/useUserProfile.ts
+++ b/src/app/hooks/useUserProfile.ts
@@ -5,7 +5,12 @@ import { useMatrixClient } from './useMatrixClient';
export type UserProfile = {
avatarUrl?: string;
displayName?: string;
+
+ pronouns?: any[]; // io.fsky.nyx.pronouns
+ timezone?: string; // us.cloke.msc4175.tz
+ extended?: Record; // any other fields
};
+
export const useUserProfile = (userId: string): UserProfile => {
const mx = useMatrixClient();
@@ -32,15 +37,34 @@ export const useUserProfile = (userId: string): UserProfile => {
}));
};
- mx.getProfileInfo(userId).then((info) =>
- setProfile({
+ mx.getProfileInfo(userId).then((info: any) => {
+ const normalized: UserProfile = {
avatarUrl: info.avatar_url,
displayName: info.displayname,
- })
- );
+ pronouns: info['io.fsky.nyx.pronouns'],
+ timezone: info['us.cloke.msc4175.tz'],
+ extended: {},
+ };
+
+ const knownKeys = [
+ 'avatar_url',
+ 'displayname',
+ 'io.fsky.nyx.pronouns',
+ 'us.cloke.msc4175.tz',
+ 'm.tz'
+ ];
+ Object.keys(info).forEach((key) => {
+ if (!knownKeys.includes(key) && !key.startsWith('m.')) {
+ normalized.extended![key] = info[key];
+ }
+ });
+
+ setProfile(normalized);
+ });
user?.on(UserEvent.AvatarUrl, onAvatarChange);
user?.on(UserEvent.DisplayName, onDisplayNameChange);
+
return () => {
user?.removeListener(UserEvent.AvatarUrl, onAvatarChange);
user?.removeListener(UserEvent.DisplayName, onDisplayNameChange);