From a76acdf8191a819864c4840cf08d3a5fee370dca Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sun, 19 Jul 2026 16:40:16 -0500 Subject: [PATCH] fix: populate versions cache and refresh thread support --- src/client/initMatrix.ts | 3 ++- src/client/versionsCache.ts | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/client/initMatrix.ts b/src/client/initMatrix.ts index 5da97032e..317b534ea 100644 --- a/src/client/initMatrix.ts +++ b/src/client/initMatrix.ts @@ -33,6 +33,7 @@ import { primeVersionsFromCache, revalidateVersionsCache, clearCachedVersions, + cacheVersionsFromClient, } from './versionsCache'; const log = createLogger('initMatrix'); @@ -281,7 +282,7 @@ const initializeClient = async ( void primeVersionsFromCache(mx, session.baseUrl, session.userId).then((primed) => { if (primed) void revalidateVersionsCache(mx, session.baseUrl, session.userId); - else void mx.getVersions().catch(() => undefined); + else void cacheVersionsFromClient(mx, session.baseUrl, session.userId); }); const syncStorePromise = measureStartupPhase('sync_store', () => indexedDBStore.startup()); diff --git a/src/client/versionsCache.ts b/src/client/versionsCache.ts index da8c2d211..0953a682e 100644 --- a/src/client/versionsCache.ts +++ b/src/client/versionsCache.ts @@ -1,5 +1,5 @@ import type { MatrixClient } from '$types/matrix-sdk'; -import { buildFeatureSupportMap, Method } from '$types/matrix-sdk'; +import { buildFeatureSupportMap, Method, Thread } from '$types/matrix-sdk'; const TTL_MS = 24 * 60 * 60 * 1000; // 24 hours const keyFor = (baseUrl: string, userId: string): string => @@ -37,6 +37,23 @@ const writeCache = ( } }; +/** Fetch /versions through the SDK and persist the response for the next startup. */ +export const cacheVersionsFromClient = async ( + mx: MatrixClient, + baseUrl: string, + userId: string +): Promise => { + try { + const data = await mx.getVersions(); + writeCache(baseUrl, userId, { + versions: data.versions, + unstable_features: data.unstable_features, + }); + } catch { + // startup can continue without a cache entry. + } +}; + /** * Seed mx.serverVersionsPromise AND mx.canSupport from a cached /versions payload. * Seeding the promise alone leaves canSupport empty → semantic drift in @@ -87,6 +104,10 @@ export const revalidateVersionsCache = async ( ).serverVersionsPromise = Promise.resolve(data); (mx as unknown as { canSupport: Map }).canSupport = await buildFeatureSupportMap(data as Parameters[0]); + const { threads, list, fwdPagination } = await mx.doesServerSupportThread(); + Thread.setServerSideSupport(threads); + Thread.setServerSideListSupport(list); + Thread.setServerSideFwdPaginationSupport(fwdPagination); } catch { // Revalidation failed — cached values remain in effect. Non-fatal. }