mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 00:51:17 -08:00
scope extensions
doesn't work on c10y :(
This commit is contained in:
1 parent
b5e0ec8143
commit
56bfccccc2
3 files changed
+78
-10
No files matched your search
@@ -23,7 +23,7 @@ import { pushSessionToSW } from '../sw-session';
|
||||
import { SessionOidcTokenRefresher } from './oidcTokenRefresher';
|
||||
import { cryptoCallbacks } from './secretStorageKeys';
|
||||
import type { SlidingSyncDiagnostics } from './slidingSync';
|
||||
import { SlidingSyncManager } from './slidingSync';
|
||||
import { scopeEphemeralExtensions, SlidingSyncManager } from './slidingSync';
|
||||
import { PresenceSyncManager } from './presenceSync';
|
||||
import { SlidingSyncSidebarCache } from './slidingSyncSidebarCache';
|
||||
|
||||
@@ -106,7 +106,7 @@ type MatrixClientWithWritableFetchRoomEvent = MatrixClient & {
|
||||
|
||||
const fetchRoomEventStartupCleanupByClient = new WeakMap<MatrixClient, () => void>();
|
||||
|
||||
const slidingSyncConnIdCleanupByClient = new WeakMap<MatrixClient, () => void>();
|
||||
const slidingSyncRequestCleanupByClient = new WeakMap<MatrixClient, () => void>();
|
||||
|
||||
type SlidingSyncMethod = (
|
||||
reqBody: MSC3575SlidingSyncRequest,
|
||||
@@ -124,8 +124,8 @@ type SlidingSyncRequestWithConnId = MSC3575SlidingSyncRequest & {
|
||||
|
||||
const SLIDING_SYNC_CONN_ID = 'sable-main';
|
||||
|
||||
function installSlidingSyncConnId(mx: MatrixClient): void {
|
||||
slidingSyncConnIdCleanupByClient.get(mx)?.();
|
||||
function installSlidingSyncRequestPatch(mx: MatrixClient, manager: SlidingSyncManager): void {
|
||||
slidingSyncRequestCleanupByClient.get(mx)?.();
|
||||
|
||||
const mxWritable = mx as MatrixClientWithWritableSlidingSync;
|
||||
const original = mx.slidingSync.bind(mx) as SlidingSyncMethod;
|
||||
@@ -135,11 +135,14 @@ function installSlidingSyncConnId(mx: MatrixClient): void {
|
||||
req.conn_id = SLIDING_SYNC_CONN_ID;
|
||||
}
|
||||
|
||||
const roomIds = manager.getActiveRoomSubscriptionIds();
|
||||
scopeEphemeralExtensions(req.extensions, roomIds);
|
||||
|
||||
return original(reqBody, baseUrl, abortSignal);
|
||||
};
|
||||
|
||||
slidingSyncConnIdCleanupByClient.set(mx, () => {
|
||||
slidingSyncConnIdCleanupByClient.delete(mx);
|
||||
slidingSyncRequestCleanupByClient.set(mx, () => {
|
||||
slidingSyncRequestCleanupByClient.delete(mx);
|
||||
mxWritable.slidingSync = original;
|
||||
});
|
||||
}
|
||||
@@ -456,7 +459,7 @@ export const startClient = async (mx: MatrixClient, config?: StartClientConfig):
|
||||
});
|
||||
|
||||
installStartupFetchRoomEventPatch(mx, manager);
|
||||
installSlidingSyncConnId(mx);
|
||||
installSlidingSyncRequestPatch(mx, manager);
|
||||
|
||||
manager.attach();
|
||||
manager.prepareSidebarCacheHydration();
|
||||
@@ -486,7 +489,7 @@ export const startClient = async (mx: MatrixClient, config?: StartClientConfig):
|
||||
stack: err instanceof Error ? err.stack : undefined,
|
||||
});
|
||||
fetchRoomEventStartupCleanupByClient.get(mx)?.();
|
||||
slidingSyncConnIdCleanupByClient.get(mx)?.();
|
||||
slidingSyncRequestCleanupByClient.get(mx)?.();
|
||||
membershipActionCleanupByClient.get(mx)?.();
|
||||
disposeSlidingSync(mx);
|
||||
disposePresenceSync(mx);
|
||||
@@ -498,7 +501,7 @@ export const stopClient = (mx: MatrixClient): void => {
|
||||
log.log('stopClient', mx.getUserId());
|
||||
debugLog.info('sync', 'Stopping client', { userId: mx.getUserId() });
|
||||
fetchRoomEventStartupCleanupByClient.get(mx)?.();
|
||||
slidingSyncConnIdCleanupByClient.get(mx)?.();
|
||||
slidingSyncRequestCleanupByClient.get(mx)?.();
|
||||
disposeSlidingSync(mx);
|
||||
disposePresenceSync(mx);
|
||||
mx.stopClient();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import type { MatrixClient, MSC3575List } from '$types/matrix-sdk';
|
||||
import { EventType, KnownMembership, SlidingSyncEvent, SlidingSyncState } from '$types/matrix-sdk';
|
||||
|
||||
import { SlidingSyncManager } from './slidingSync';
|
||||
import { scopeEphemeralExtensions, SlidingSyncManager } from './slidingSync';
|
||||
|
||||
// ── vi.hoisted mocks ─────────────────────────────────────────────────────────
|
||||
// Must be defined via vi.hoisted
|
||||
@@ -407,6 +407,44 @@ describe('SlidingSyncManager room subscription coordination', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('scopeEphemeralExtensions', () => {
|
||||
it('limits typing and receipts to active rooms without changing other extensions', () => {
|
||||
const extensions = {
|
||||
typing: { enabled: true },
|
||||
receipts: { enabled: true },
|
||||
account_data: { enabled: true },
|
||||
};
|
||||
|
||||
scopeEphemeralExtensions(extensions, ['!space:example.com', '!room:example.com']);
|
||||
|
||||
expect(extensions).toEqual({
|
||||
typing: {
|
||||
enabled: true,
|
||||
lists: [],
|
||||
rooms: ['!space:example.com', '!room:example.com'],
|
||||
},
|
||||
receipts: {
|
||||
enabled: true,
|
||||
lists: [],
|
||||
rooms: ['!space:example.com', '!room:example.com'],
|
||||
},
|
||||
account_data: { enabled: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('uses an empty room scope when no timeline is open', () => {
|
||||
const extensions = {
|
||||
typing: { enabled: true, lists: ['joined'], rooms: ['!old:example.com'] },
|
||||
receipts: { enabled: true, lists: ['joined'], rooms: ['!old:example.com'] },
|
||||
};
|
||||
|
||||
scopeEphemeralExtensions(extensions, []);
|
||||
|
||||
expect(extensions.typing).toMatchObject({ lists: [], rooms: [] });
|
||||
expect(extensions.receipts).toMatchObject({ lists: [], rooms: [] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('SlidingSyncManager local membership reconciliation', () => {
|
||||
it('updates an existing invite immediately after a successful join', () => {
|
||||
const updateMyMembership = vi.fn<() => void>();
|
||||
|
||||
@@ -190,6 +190,29 @@ const getListEndIndex = (list: MSC3575List | null): number => {
|
||||
return list.ranges.reduce((max, range) => Math.max(max, range[1] ?? -1), -1);
|
||||
};
|
||||
|
||||
type RoomScopedExtension = {
|
||||
enabled?: boolean;
|
||||
lists?: string[];
|
||||
rooms?: string[];
|
||||
};
|
||||
|
||||
export const scopeEphemeralExtensions = (
|
||||
extensions: object | undefined,
|
||||
roomIds: readonly string[]
|
||||
): void => {
|
||||
if (!extensions) return;
|
||||
const extensionMap = extensions as Record<string, unknown>;
|
||||
|
||||
['typing', 'receipts'].forEach((name) => {
|
||||
const extension = extensionMap[name];
|
||||
if (!extension || typeof extension !== 'object') return;
|
||||
|
||||
const scopedExtension = extension as RoomScopedExtension;
|
||||
scopedExtension.lists = [];
|
||||
scopedExtension.rooms = [...roomIds];
|
||||
});
|
||||
};
|
||||
|
||||
export class SlidingSyncManager {
|
||||
private disposed = false;
|
||||
|
||||
@@ -1120,6 +1143,10 @@ export class SlidingSyncManager {
|
||||
this.reportActiveSubscriptionCount();
|
||||
}
|
||||
|
||||
public getActiveRoomSubscriptionIds(): string[] {
|
||||
return [...this.activeRoomSubscriptions];
|
||||
}
|
||||
|
||||
public subscribeToRoom(roomId: string): void {
|
||||
if (this.disposed || !this.addActiveRoomSubscription(roomId)) return;
|
||||
this.syncRoomSubscriptions();
|
||||
|
||||
Reference in new issue
Block a user