mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import { createContext, useContext } from 'react';
|
|
|
|
export type HashRouterConfig = {
|
|
enabled?: boolean;
|
|
basename?: string;
|
|
};
|
|
|
|
export type ClientConfig = {
|
|
defaultHomeserver?: number;
|
|
homeserverList?: string[];
|
|
allowCustomHomeservers?: boolean;
|
|
elementCallUrl?: string;
|
|
|
|
disableAccountSwitcher?: boolean;
|
|
hideUsernamePasswordFields?: boolean;
|
|
|
|
pushNotificationDetails?: {
|
|
pushNotifyUrl?: string;
|
|
vapidPublicKey?: string;
|
|
webPushAppID?: string;
|
|
};
|
|
|
|
slidingSync?: {
|
|
enabled?: boolean;
|
|
proxyBaseUrl?: string;
|
|
bootstrapClassicOnColdCache?: boolean;
|
|
listPageSize?: number;
|
|
timelineLimit?: number;
|
|
pollTimeoutMs?: number;
|
|
maxRooms?: number;
|
|
includeInviteList?: boolean;
|
|
probeTimeoutMs?: number;
|
|
};
|
|
|
|
featuredCommunities?: {
|
|
openAsDefault?: boolean;
|
|
spaces?: string[];
|
|
rooms?: string[];
|
|
servers?: string[];
|
|
};
|
|
|
|
hashRouter?: HashRouterConfig;
|
|
|
|
matrixToBaseUrl?: string;
|
|
settingsLinkBaseUrl?: string;
|
|
|
|
themeCatalogBaseUrl?: string;
|
|
themeCatalogApprovedHostPrefixes?: string[];
|
|
};
|
|
|
|
const ClientConfigContext = createContext<ClientConfig | null>(null);
|
|
|
|
export const ClientConfigProvider = ClientConfigContext.Provider;
|
|
|
|
export function useClientConfig(): ClientConfig {
|
|
const config = useContext(ClientConfigContext);
|
|
if (!config) throw new Error('Client config are not provided!');
|
|
return config;
|
|
}
|
|
|
|
export function useOptionalClientConfig(): ClientConfig | null {
|
|
return useContext(ClientConfigContext);
|
|
}
|
|
|
|
export const clientDefaultServer = (clientConfig: ClientConfig): string =>
|
|
clientConfig.homeserverList?.[clientConfig.defaultHomeserver ?? 0] ?? 'matrix.org';
|
|
|
|
export const clientAllowedServer = (clientConfig: ClientConfig, server: string): boolean => {
|
|
const { homeserverList, allowCustomHomeservers } = clientConfig;
|
|
|
|
if (allowCustomHomeservers) return true;
|
|
|
|
return homeserverList?.includes(server) === true;
|
|
};
|