mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-02 14:52:32 -08:00
remove the rest of sliding sync config
This commit is contained in:
1 parent
5855969295
commit
67cb91546f
9 files changed
+49
-80
No files matched your search
@@ -422,7 +422,7 @@ export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
||||
{syncDiagnostics.sliding ? (
|
||||
<>
|
||||
<Text size="T200">
|
||||
Proxy: {syncDiagnostics.sliding.proxyBaseUrl}
|
||||
Base URL: {syncDiagnostics.sliding.baseUrl}
|
||||
</Text>
|
||||
<Text size="T200">
|
||||
Room timeline: {syncDiagnostics.sliding.timelineLimit} | page
|
||||
|
||||
@@ -179,7 +179,7 @@ export function SyncDiagnostics() {
|
||||
</Box>
|
||||
{expandSliding && (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="T300">Sliding proxy: {diagnostics.sliding.proxyBaseUrl}</Text>
|
||||
<Text size="T300">Sliding sync base URL: {diagnostics.sliding.baseUrl}</Text>
|
||||
<Text size="T300">
|
||||
Room timeline limit: {diagnostics.sliding.timelineLimit} | page size:{' '}
|
||||
{diagnostics.sliding.listPageSize}
|
||||
|
||||
@@ -27,16 +27,6 @@ export type ClientConfig = {
|
||||
webPushAppID?: string;
|
||||
};
|
||||
|
||||
slidingSync?: {
|
||||
proxyBaseUrl?: string;
|
||||
bootstrapClassicOnColdCache?: boolean;
|
||||
listPageSize?: number;
|
||||
timelineLimit?: number;
|
||||
pollTimeoutMs?: number;
|
||||
includeInviteList?: boolean;
|
||||
probeTimeoutMs?: number;
|
||||
};
|
||||
|
||||
featuredCommunities?: {
|
||||
openAsDefault?: boolean;
|
||||
spaces?: string[];
|
||||
|
||||
@@ -2,19 +2,22 @@ import { useEffect } from 'react';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { getSlidingSyncManager } from '$client/initMatrix';
|
||||
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
||||
import { useSelectedSpace } from '$hooks/router/useSelectedSpace';
|
||||
|
||||
export const useSlidingSyncActiveRoom = (): void => {
|
||||
const mx = useMatrixClient();
|
||||
const roomId = useSelectedRoom();
|
||||
const spaceId = useSelectedSpace();
|
||||
|
||||
useEffect(() => {
|
||||
if (!roomId) return undefined;
|
||||
const manager = getSlidingSyncManager(mx);
|
||||
if (!manager) return undefined;
|
||||
|
||||
manager.subscribeToRoom(roomId);
|
||||
const activeRoomIds = [...new Set([spaceId, roomId].filter(Boolean))] as string[];
|
||||
activeRoomIds.forEach((activeRoomId) => manager.subscribeToRoom(activeRoomId));
|
||||
|
||||
return () => {
|
||||
manager.unsubscribeFromRoom(roomId);
|
||||
activeRoomIds.forEach((activeRoomId) => manager.unsubscribeFromRoom(activeRoomId));
|
||||
};
|
||||
}, [mx, roomId]);
|
||||
}, [mx, roomId, spaceId]);
|
||||
};
|
||||
@@ -43,7 +43,6 @@ import {
|
||||
} from '$utils/notificationStyle';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { startClient, stopClient } from '$client/initMatrix';
|
||||
import { useClientConfig } from '$hooks/useClientConfig';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
|
||||
const log = createLogger('BackgroundNotifications');
|
||||
@@ -55,10 +54,7 @@ const BACKGROUND_STAGGER_DELAY_MS = 5_000;
|
||||
const isClientReadyForNotifications = (state: SyncState | string | null): boolean =>
|
||||
state === SyncState.Prepared || state === SyncState.Syncing || state === SyncState.Catchup;
|
||||
|
||||
const startBackgroundClient = async (
|
||||
session: Session,
|
||||
slidingSyncConfig: ReturnType<typeof useClientConfig>['slidingSync']
|
||||
): Promise<MatrixClient> => {
|
||||
const startBackgroundClient = async (session: Session): Promise<MatrixClient> => {
|
||||
const storeName = {
|
||||
sync: `bg-sync${session.userId}`,
|
||||
crypto: `bg-crypto${session.userId}`,
|
||||
@@ -82,7 +78,6 @@ const startBackgroundClient = async (
|
||||
|
||||
const startOpts = {
|
||||
baseUrl: session.baseUrl,
|
||||
slidingSync: session.slidingSyncOptIn ? slidingSyncConfig : undefined,
|
||||
sessionSlidingSyncOptIn: session.slidingSyncOptIn,
|
||||
pollTimeoutMs: BACKGROUND_SYNC_POLL_TIMEOUT_MS,
|
||||
timelineLimit: 1,
|
||||
@@ -121,7 +116,6 @@ const waitForSync = (mx: MatrixClient): Promise<void> =>
|
||||
});
|
||||
|
||||
export function BackgroundNotifications() {
|
||||
const clientConfig = useClientConfig();
|
||||
const sessions = useAtomValue(sessionsAtom);
|
||||
const [activeSessionId, setActiveSessionId] = useAtom(activeSessionIdAtom);
|
||||
const [showNotifications] = useSetting(settingsAtom, 'useInAppNotifications');
|
||||
@@ -256,7 +250,7 @@ export function BackgroundNotifications() {
|
||||
// fresh retry referencing the latest session from inactiveSessionsRef.
|
||||
const startSession = (session: Session, attempt = 0): void => {
|
||||
let sessionMx: MatrixClient | undefined;
|
||||
startBackgroundClient(session, clientConfig.slidingSync)
|
||||
startBackgroundClient(session)
|
||||
.then(async (mx) => {
|
||||
sessionMx = mx;
|
||||
current.set(session.userId, mx);
|
||||
@@ -591,7 +585,6 @@ export function BackgroundNotifications() {
|
||||
});
|
||||
};
|
||||
}, [
|
||||
clientConfig.slidingSync,
|
||||
inactiveSessions,
|
||||
shouldRunBackgroundNotifications,
|
||||
setActiveSessionId,
|
||||
|
||||
@@ -48,7 +48,7 @@ import { useSyncNicknames } from '$hooks/useNickname';
|
||||
import { useAppVisibility } from '$hooks/useAppVisibility';
|
||||
import { composerIcon, DotsThreeOutlineVerticalIcon } from '$components/icons/phosphor';
|
||||
import { getHomePath } from '$pages/pathUtils';
|
||||
import { useClientConfig, useClientConfigLoaded } from '$hooks/useClientConfig';
|
||||
import { useClientConfigLoaded } from '$hooks/useClientConfig';
|
||||
import { pushSessionToSW } from '../../../sw-session';
|
||||
import { SyncStatus } from './SyncStatus';
|
||||
import { SpecVersions } from './SpecVersions';
|
||||
@@ -218,7 +218,6 @@ type ClientRootProps = {
|
||||
};
|
||||
export function ClientRoot({ children }: ClientRootProps) {
|
||||
const navigate = useNavigate();
|
||||
const clientConfig = useClientConfig();
|
||||
const configLoaded = useClientConfigLoaded();
|
||||
const sessions = useAtomValue(sessionsAtom);
|
||||
const [activeSessionId, setActiveSessionId] = useAtom(activeSessionIdAtom);
|
||||
@@ -274,10 +273,9 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
(m) =>
|
||||
startClient(m, {
|
||||
baseUrl: activeSession?.baseUrl,
|
||||
slidingSync: clientConfig.slidingSync,
|
||||
sessionSlidingSyncOptIn: activeSession?.slidingSyncOptIn,
|
||||
}),
|
||||
[activeSession?.baseUrl, activeSession?.slidingSyncOptIn, clientConfig.slidingSync]
|
||||
[activeSession?.baseUrl, activeSession?.slidingSyncOptIn]
|
||||
)
|
||||
);
|
||||
|
||||
@@ -359,12 +357,12 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
if (!activeSession?.baseUrl) return undefined;
|
||||
Sentry.setContext('client', {
|
||||
homeserver: activeSession.baseUrl,
|
||||
sliding_sync: clientConfig.slidingSync,
|
||||
sliding_sync: activeSession.slidingSyncOptIn === true,
|
||||
});
|
||||
return () => {
|
||||
Sentry.setContext('client', null);
|
||||
};
|
||||
}, [activeSession?.baseUrl, clientConfig.slidingSync]);
|
||||
}, [activeSession?.baseUrl, activeSession?.slidingSyncOptIn]);
|
||||
|
||||
// Set a pseudonymous hashed user ID for error grouping — never sends raw Matrix ID
|
||||
useEffect(() => {
|
||||
|
||||
+12
-15
@@ -15,7 +15,7 @@ import { createDebugLogger } from '$utils/debugLogger';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { pushSessionToSW } from '../sw-session';
|
||||
import { cryptoCallbacks } from './secretStorageKeys';
|
||||
import type { SlidingSyncConfig, SlidingSyncDiagnostics } from './slidingSync';
|
||||
import type { SlidingSyncDiagnostics } from './slidingSync';
|
||||
import { SlidingSyncManager } from './slidingSync';
|
||||
import { PresenceSyncManager } from './presenceSync';
|
||||
|
||||
@@ -58,7 +58,7 @@ const slidingSyncConnIdCleanupByClient = new WeakMap<MatrixClient, () => void>()
|
||||
|
||||
type SlidingSyncMethod = (
|
||||
reqBody: MSC3575SlidingSyncRequest,
|
||||
proxyBaseUrl?: string,
|
||||
baseUrl?: string,
|
||||
abortSignal?: AbortSignal
|
||||
) => Promise<MSC3575SlidingSyncResponse>;
|
||||
|
||||
@@ -75,13 +75,12 @@ function installSlidingSyncConnId(mx: MatrixClient): void {
|
||||
|
||||
const mxWritable = mx as MatrixClientWithWritableSlidingSync;
|
||||
const original = mx.slidingSync.bind(mx) as SlidingSyncMethod;
|
||||
|
||||
mxWritable.slidingSync = (reqBody, proxyBaseUrl, abortSignal) => {
|
||||
mxWritable.slidingSync = (reqBody, baseUrl, abortSignal) => {
|
||||
const req = reqBody as SlidingSyncRequestWithConnId;
|
||||
if (req.conn_id === undefined) {
|
||||
req.conn_id = SLIDING_SYNC_CONN_ID;
|
||||
}
|
||||
return original(reqBody, proxyBaseUrl, abortSignal);
|
||||
return original(reqBody, baseUrl, abortSignal);
|
||||
};
|
||||
|
||||
slidingSyncConnIdCleanupByClient.set(mx, () => {
|
||||
@@ -420,7 +419,6 @@ export const initClient = async (session: Session): Promise<MatrixClient> => {
|
||||
|
||||
export type StartClientConfig = {
|
||||
baseUrl?: string;
|
||||
slidingSync?: SlidingSyncConfig;
|
||||
sessionSlidingSyncOptIn?: boolean;
|
||||
pollTimeoutMs?: number;
|
||||
timelineLimit?: number;
|
||||
@@ -453,13 +451,13 @@ export const getPresenceSyncManager = (mx: MatrixClient): PresenceSyncManager |
|
||||
presenceSyncByClient.get(mx);
|
||||
|
||||
export const startClient = async (mx: MatrixClient, config?: StartClientConfig): Promise<void> => {
|
||||
debugLog.info('sync', 'Starting Matrix client', { userId: mx.getUserId() });
|
||||
disposeSlidingSync(mx);
|
||||
disposePresenceSync(mx);
|
||||
|
||||
const slidingConfig = config?.slidingSync;
|
||||
const proxyBaseUrl = slidingConfig?.proxyBaseUrl ?? config?.baseUrl ?? mx.baseUrl;
|
||||
const useSliding = config?.sessionSlidingSyncOptIn === true && !!slidingConfig;
|
||||
const baseUrl = config?.baseUrl ?? mx.baseUrl;
|
||||
const useSliding = config?.sessionSlidingSyncOptIn === true;
|
||||
|
||||
debugLog.info('sync', 'Starting Matrix client', { userId: mx.getUserId() });
|
||||
|
||||
const presenceManager = new PresenceSyncManager(mx);
|
||||
presenceSyncByClient.set(mx, presenceManager);
|
||||
@@ -469,10 +467,9 @@ export const startClient = async (mx: MatrixClient, config?: StartClientConfig):
|
||||
let manager: SlidingSyncManager | undefined;
|
||||
|
||||
if (useSliding) {
|
||||
manager = new SlidingSyncManager(mx, proxyBaseUrl, {
|
||||
...slidingConfig,
|
||||
includeInviteList: true,
|
||||
pollTimeoutMs: slidingConfig?.pollTimeoutMs ?? SLIDING_SYNC_POLL_TIMEOUT_MS,
|
||||
manager = new SlidingSyncManager(mx, baseUrl, {
|
||||
pollTimeoutMs: config?.pollTimeoutMs ?? SLIDING_SYNC_POLL_TIMEOUT_MS,
|
||||
timelineLimit: config?.timelineLimit,
|
||||
});
|
||||
|
||||
installStartupFetchRoomEventPatch(mx, manager);
|
||||
@@ -497,7 +494,7 @@ export const startClient = async (mx: MatrixClient, config?: StartClientConfig):
|
||||
debugLog.error('network', 'Failed to start client with sliding sync', {
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
userId: mx.getUserId(),
|
||||
proxyBaseUrl: useSliding ? proxyBaseUrl : undefined,
|
||||
baseUrl: useSliding ? baseUrl : undefined,
|
||||
stack: err instanceof Error ? err.stack : undefined,
|
||||
});
|
||||
disposeSlidingSync(mx);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import type { MatrixClient, MSC3575List } from '$types/matrix-sdk';
|
||||
import { SlidingSyncEvent, SlidingSyncState } from '$types/matrix-sdk';
|
||||
|
||||
import { SlidingSyncManager, type SlidingSyncConfig } from './slidingSync';
|
||||
import { SlidingSyncManager } from './slidingSync';
|
||||
|
||||
// ── vi.hoisted mocks ─────────────────────────────────────────────────────────
|
||||
// Must be defined via vi.hoisted
|
||||
@@ -69,8 +69,7 @@ function makeMockMx(overrides: Record<string, unknown> = {}) {
|
||||
}
|
||||
|
||||
function makeManager(mx: ReturnType<typeof makeMockMx>): SlidingSyncManager {
|
||||
const config: SlidingSyncConfig = {};
|
||||
return new SlidingSyncManager(mx, 'https://sliding.example.com', config);
|
||||
return new SlidingSyncManager(mx, 'https://sliding.example.com');
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
+20
-31
@@ -45,15 +45,10 @@ export type PartialSlidingSyncRequest = {
|
||||
ranges?: [number, number][];
|
||||
};
|
||||
|
||||
export type SlidingSyncConfig = {
|
||||
enabled?: boolean;
|
||||
proxyBaseUrl?: string;
|
||||
bootstrapClassicOnColdCache?: boolean;
|
||||
type SlidingSyncOptions = {
|
||||
listPageSize?: number;
|
||||
timelineLimit?: number;
|
||||
pollTimeoutMs?: number;
|
||||
includeInviteList?: boolean;
|
||||
probeTimeoutMs?: number;
|
||||
};
|
||||
|
||||
export type SlidingSyncListDiagnostics = {
|
||||
@@ -63,7 +58,7 @@ export type SlidingSyncListDiagnostics = {
|
||||
};
|
||||
|
||||
export type SlidingSyncDiagnostics = {
|
||||
proxyBaseUrl: string;
|
||||
baseUrl: string;
|
||||
timelineLimit: number;
|
||||
listPageSize: number;
|
||||
lists: SlidingSyncListDiagnostics[];
|
||||
@@ -121,7 +116,7 @@ const buildUnencryptedSubscription = (timelineLimit: number): MSC3575RoomSubscri
|
||||
required_state: ACTIVE_ROOM_REQUIRED_STATE,
|
||||
});
|
||||
|
||||
const buildLists = (pageSize: number, includeInviteList: boolean): Map<string, MSC3575List> => {
|
||||
const buildLists = (pageSize: number): Map<string, MSC3575List> => {
|
||||
const lists = new Map<string, MSC3575List>();
|
||||
const listRequiredState = buildListRequiredState();
|
||||
|
||||
@@ -135,15 +130,13 @@ const buildLists = (pageSize: number, includeInviteList: boolean): Map<string, M
|
||||
filters: { is_invite: false },
|
||||
});
|
||||
|
||||
if (includeInviteList) {
|
||||
lists.set(LIST_INVITES, {
|
||||
ranges: [[0, Math.max(0, initialRange - 1)]],
|
||||
sort: LIST_SORT_ORDER,
|
||||
timeline_limit: LIST_TIMELINE_LIMIT,
|
||||
required_state: listRequiredState,
|
||||
filters: { is_invite: true },
|
||||
});
|
||||
}
|
||||
lists.set(LIST_INVITES, {
|
||||
ranges: [[0, Math.max(0, initialRange - 1)]],
|
||||
sort: LIST_SORT_ORDER,
|
||||
timeline_limit: LIST_TIMELINE_LIMIT,
|
||||
required_state: listRequiredState,
|
||||
filters: { is_invite: true },
|
||||
});
|
||||
|
||||
return lists;
|
||||
};
|
||||
@@ -203,26 +196,22 @@ export class SlidingSyncManager {
|
||||
|
||||
public readonly slidingSync: SlidingSync;
|
||||
|
||||
public readonly probeTimeoutMs: number;
|
||||
|
||||
public constructor(
|
||||
private readonly mx: MatrixClient,
|
||||
private readonly proxyBaseUrl: string,
|
||||
config: SlidingSyncConfig
|
||||
private readonly baseUrl: string,
|
||||
options: SlidingSyncOptions = {}
|
||||
) {
|
||||
const listPageSize = clampPositive(config.listPageSize, DEFAULT_LIST_PAGE_SIZE);
|
||||
const pollTimeoutMs = clampPositive(config.pollTimeoutMs, DEFAULT_POLL_TIMEOUT_MS);
|
||||
this.probeTimeoutMs = clampPositive(config.probeTimeoutMs, 5000);
|
||||
const listPageSize = clampPositive(options.listPageSize, DEFAULT_LIST_PAGE_SIZE);
|
||||
const pollTimeoutMs = clampPositive(options.pollTimeoutMs, DEFAULT_POLL_TIMEOUT_MS);
|
||||
this.listPageSize = listPageSize;
|
||||
const includeInviteList = config.includeInviteList !== false;
|
||||
|
||||
const roomTimelineLimit = clampPositive(config.timelineLimit, ACTIVE_ROOM_TIMELINE_LIMIT);
|
||||
const roomTimelineLimit = clampPositive(options.timelineLimit, ACTIVE_ROOM_TIMELINE_LIMIT);
|
||||
this.roomTimelineLimit = roomTimelineLimit;
|
||||
|
||||
const defaultSubscription = buildEncryptedSubscription(roomTimelineLimit);
|
||||
const lists = buildLists(listPageSize, includeInviteList);
|
||||
const lists = buildLists(listPageSize);
|
||||
this.listKeys = Array.from(lists.keys());
|
||||
this.slidingSync = new SlidingSync(proxyBaseUrl, lists, defaultSubscription, mx, pollTimeoutMs);
|
||||
this.slidingSync = new SlidingSync(baseUrl, lists, defaultSubscription, mx, pollTimeoutMs);
|
||||
|
||||
this.slidingSync.addCustomSubscription(
|
||||
UNENCRYPTED_SUBSCRIPTION_KEY,
|
||||
@@ -343,7 +332,7 @@ export class SlidingSyncManager {
|
||||
|
||||
public attach(): void {
|
||||
debugLog.info('sync', 'Attaching sliding sync listeners', {
|
||||
proxyBaseUrl: this.proxyBaseUrl,
|
||||
baseUrl: this.baseUrl,
|
||||
listPageSize: this.listPageSize,
|
||||
roomTimelineLimit: this.roomTimelineLimit,
|
||||
lists: this.listKeys,
|
||||
@@ -353,7 +342,7 @@ export class SlidingSyncManager {
|
||||
this.initialSyncSpan = Sentry.startInactiveSpan({
|
||||
name: 'sync.initial',
|
||||
op: 'matrix.sync',
|
||||
attributes: { 'sync.transport': 'sliding', 'sync.proxy': this.proxyBaseUrl },
|
||||
attributes: { 'sync.transport': 'sliding', 'sync.base_url': this.baseUrl },
|
||||
});
|
||||
|
||||
this.slidingSync.on(SlidingSyncEvent.Lifecycle, this.onLifecycle);
|
||||
@@ -384,7 +373,7 @@ export class SlidingSyncManager {
|
||||
|
||||
public getDiagnostics(): SlidingSyncDiagnostics {
|
||||
return {
|
||||
proxyBaseUrl: this.proxyBaseUrl,
|
||||
baseUrl: this.baseUrl,
|
||||
timelineLimit: this.roomTimelineLimit,
|
||||
listPageSize: this.listPageSize,
|
||||
lists: this.listKeys.map((key) => {
|
||||
|
||||
Reference in new issue
Block a user