afe957015b
P1-5: Voice message playback speed toggle (0.75×/1×/1.5×/2×) in AudioContent.tsx P1-10: Private read receipts toggle in Privacy settings; wired to notifications.ts P1-3: Room filter input on Home tab and DMs tab (client-side, clears on tab switch) P1-8: Favorite rooms via m.favourite tag — Favorites section in Home sidebar, star/unstar in right-click menu P1-9: Room invite link + QR code in room settings (Share Room tile, api.qrserver.com QR) P1-6: Poll creation modal in composer (PollCreator.tsx, sends m.poll.start) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
161 lines
3.4 KiB
TypeScript
161 lines
3.4 KiB
TypeScript
import { atom } from 'jotai';
|
|
|
|
const STORAGE_KEY = 'settings';
|
|
export type DateFormat =
|
|
| 'D MMM YYYY'
|
|
| 'DD/MM/YYYY'
|
|
| 'MM/DD/YYYY'
|
|
| 'YYYY/MM/DD'
|
|
| 'YYYY-MM-DD'
|
|
| '';
|
|
export type MessageSpacing = '0' | '100' | '200' | '300' | '400' | '500';
|
|
export type ChatBackground =
|
|
| 'none'
|
|
| 'blueprint'
|
|
| 'carbon'
|
|
| 'stars'
|
|
| 'topographic'
|
|
| 'herringbone'
|
|
| 'crosshatch'
|
|
| 'chevron'
|
|
| 'polka'
|
|
| 'triangles'
|
|
| 'plaid'
|
|
| 'tactical'
|
|
| 'circuit'
|
|
| 'hexgrid'
|
|
| 'waves'
|
|
| 'neon'
|
|
| 'aurora';
|
|
export enum MessageLayout {
|
|
Modern = 0,
|
|
Compact = 1,
|
|
Bubble = 2,
|
|
}
|
|
|
|
export interface Settings {
|
|
themeId?: string;
|
|
useSystemTheme: boolean;
|
|
lightThemeId?: string;
|
|
darkThemeId?: string;
|
|
monochromeMode?: boolean;
|
|
isMarkdown: boolean;
|
|
editorToolbar: boolean;
|
|
twitterEmoji: boolean;
|
|
pageZoom: number;
|
|
hideActivity: boolean;
|
|
hidePresence: boolean;
|
|
privateReadReceipts: boolean;
|
|
presenceStatus: 'auto' | 'online' | 'idle' | 'dnd' | 'invisible';
|
|
|
|
isPeopleDrawer: boolean;
|
|
memberSortFilterIndex: number;
|
|
enterForNewline: boolean;
|
|
messageLayout: MessageLayout;
|
|
messageSpacing: MessageSpacing;
|
|
hideMembershipEvents: boolean;
|
|
hideNickAvatarEvents: boolean;
|
|
mediaAutoLoad: boolean;
|
|
urlPreview: boolean;
|
|
encUrlPreview: boolean;
|
|
showHiddenEvents: boolean;
|
|
legacyUsernameColor: boolean;
|
|
|
|
showNotifications: boolean;
|
|
isNotificationSounds: boolean;
|
|
|
|
hour24Clock: boolean;
|
|
dateFormatString: string;
|
|
|
|
developerTools: boolean;
|
|
lotusTerminal: boolean;
|
|
|
|
chatBackground: ChatBackground;
|
|
perMessageProfiles: boolean;
|
|
|
|
cameraOnJoin: boolean;
|
|
callNoiseSuppression: boolean;
|
|
pttMode: boolean;
|
|
pttKey: string;
|
|
|
|
nightLightEnabled: boolean;
|
|
nightLightOpacity: number;
|
|
}
|
|
|
|
const defaultSettings: Settings = {
|
|
themeId: undefined,
|
|
useSystemTheme: true,
|
|
lightThemeId: undefined,
|
|
darkThemeId: undefined,
|
|
monochromeMode: false,
|
|
isMarkdown: true,
|
|
editorToolbar: false,
|
|
twitterEmoji: false,
|
|
pageZoom: 100,
|
|
hideActivity: false,
|
|
hidePresence: false,
|
|
privateReadReceipts: false,
|
|
presenceStatus: 'auto',
|
|
|
|
isPeopleDrawer: true,
|
|
memberSortFilterIndex: 0,
|
|
enterForNewline: false,
|
|
messageLayout: 0,
|
|
messageSpacing: '400',
|
|
hideMembershipEvents: false,
|
|
hideNickAvatarEvents: true,
|
|
mediaAutoLoad: true,
|
|
urlPreview: true,
|
|
encUrlPreview: true,
|
|
showHiddenEvents: false,
|
|
legacyUsernameColor: false,
|
|
|
|
showNotifications: true,
|
|
isNotificationSounds: true,
|
|
|
|
hour24Clock: false,
|
|
dateFormatString: 'D MMM YYYY',
|
|
|
|
developerTools: false,
|
|
lotusTerminal: false,
|
|
|
|
chatBackground: 'none',
|
|
perMessageProfiles: false,
|
|
|
|
cameraOnJoin: false,
|
|
callNoiseSuppression: true,
|
|
pttMode: false,
|
|
pttKey: 'Space',
|
|
|
|
nightLightEnabled: false,
|
|
nightLightOpacity: 30,
|
|
};
|
|
|
|
export const getSettings = (): Settings => {
|
|
try {
|
|
const settings = localStorage.getItem(STORAGE_KEY);
|
|
if (settings === null) return defaultSettings;
|
|
return { ...defaultSettings, ...(JSON.parse(settings) as Settings) };
|
|
} catch {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
return defaultSettings;
|
|
}
|
|
};
|
|
|
|
export const setSettings = (settings: Settings) => {
|
|
try {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
|
} catch {
|
|
/* quota */
|
|
}
|
|
};
|
|
|
|
const baseSettings = atom<Settings>(getSettings());
|
|
export const settingsAtom = atom<Settings, [Settings], undefined>(
|
|
(get) => get(baseSettings),
|
|
(get, set, update) => {
|
|
set(baseSettings, update);
|
|
setSettings(update);
|
|
},
|
|
);
|