mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-21 09:31:17 -08:00
fix thread patch
This commit is contained in:
1 parent
752e23eeb7
commit
8b8833cd9f
2 files changed
+8
-13
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import type { CryptoCallbacks, MatrixClient } from '$types/matrix-sdk';
|
||||
import { createClient, IndexedDBStore, IndexedDBCryptoStore, SlidingSyncEvent, SlidingSyncState } from '$types/matrix-sdk';
|
||||
import { createClient, IndexedDBStore, IndexedDBCryptoStore } from '$types/matrix-sdk';
|
||||
|
||||
import { clearNavToActivePathStore } from '$state/navToActivePath';
|
||||
import type { Session, Sessions, SessionStoreName } from '$state/sessions';
|
||||
@@ -30,24 +30,16 @@ function installStartupFetchRoomEventPatch(mx: MatrixClient, slidingSyncManager:
|
||||
|
||||
const mxWritable = mx as MatrixClientWithWritableFetchRoomEvent;
|
||||
const origFetchRoomEvent = mx.fetchRoomEvent.bind(mx);
|
||||
let restored = false;
|
||||
|
||||
const restore = () => {
|
||||
if (restored) return;
|
||||
restored = true;
|
||||
fetchRoomEventStartupCleanupByClient.delete(mx);
|
||||
mxWritable.fetchRoomEvent = origFetchRoomEvent;
|
||||
slidingSyncManager.slidingSync.removeListener(SlidingSyncEvent.Lifecycle, onLifecycle);
|
||||
};
|
||||
|
||||
const onLifecycle = (state: SlidingSyncState) => {
|
||||
if (state === SlidingSyncState.Complete) {
|
||||
restore();
|
||||
}
|
||||
};
|
||||
|
||||
mxWritable.fetchRoomEvent = (roomId: string, eventId: string) => {
|
||||
if (restored) return origFetchRoomEvent(roomId, eventId);
|
||||
if (slidingSyncManager.isRoomActive(roomId)) {
|
||||
return origFetchRoomEvent(roomId, eventId);
|
||||
}
|
||||
const cachedEvent = mx.getRoom(roomId)?.findEventById(eventId);
|
||||
const payload: FetchRoomEventResult = cachedEvent?.event ?? {
|
||||
event_id: eventId,
|
||||
@@ -56,7 +48,6 @@ function installStartupFetchRoomEventPatch(mx: MatrixClient, slidingSyncManager:
|
||||
return Promise.resolve(payload);
|
||||
};
|
||||
|
||||
slidingSyncManager.slidingSync.on(SlidingSyncEvent.Lifecycle, onLifecycle);
|
||||
fetchRoomEventStartupCleanupByClient.set(mx, restore);
|
||||
}
|
||||
|
||||
|
||||
@@ -592,6 +592,10 @@ export class SlidingSyncManager {
|
||||
});
|
||||
}
|
||||
|
||||
public isRoomActive(roomId: string): boolean {
|
||||
return this.activeRoomSubscriptions.has(roomId);
|
||||
}
|
||||
|
||||
public subscribeToRoom(roomId: string): void {
|
||||
if (this.disposed) return;
|
||||
const room = this.mx.getRoom(roomId);
|
||||
|
||||
Reference in new issue
Block a user