Skip to content

Commit 6ff3e85

Browse files
committed
WIP gappy sync handling
1 parent 83fa966 commit 6ff3e85

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/utils/matrix.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import { IndexedDBStore } from "matrix-js-sdk/src/store/indexeddb";
99
import { MemoryStore } from "matrix-js-sdk/src/store/memory";
1010
import {
1111
createClient,
12+
Filter,
1213
ICreateClientOpts,
1314
Preset,
15+
RoomEvent,
1416
Visibility,
1517
} from "matrix-js-sdk/src/matrix";
1618
import { ClientEvent } from "matrix-js-sdk/src/client";
@@ -126,6 +128,10 @@ export async function initClient(
126128
store: new MemoryStore(),
127129
});
128130

131+
client.on(RoomEvent.TimelineReset, () => {
132+
logger.warn("Received TimelineReset indicating limited sync response");
133+
});
134+
129135
// In case of logging in a new matrix account but there is still crypto local store. This is needed for:
130136
// - We lost the auth tokens and cannot restore the client resulting in registering a new user.
131137
// - We start the sign in flow but are registered with a guest user. (It should additionally log out the guest before)
@@ -165,7 +171,20 @@ export async function initClient(
165171
// Otherwise, a sync may complete before the listener gets applied,
166172
// and we will miss it.
167173
const syncPromise = waitForSync(client);
168-
await client.startClient({ clientWellKnownPollPeriod: 60 * 10 });
174+
await client.startClient({
175+
clientWellKnownPollPeriod: 60 * 10,
176+
// TODO: ask for a high limit to avoid gappy syncs
177+
filter: Filter.fromJson(undefined, "element-call", {
178+
room: {
179+
timeline: {
180+
limit: 1,
181+
},
182+
},
183+
}),
184+
// we only ask for 1 past message as we really only care about future messages
185+
// n.b. past reactions are then not visible
186+
initialSyncLimit: 1,
187+
});
169188
await syncPromise;
170189

171190
return client;

0 commit comments

Comments
 (0)