diff --git a/src/useReactions.tsx b/src/useReactions.tsx index 8824f103..c6426a06 100644 --- a/src/useReactions.tsx +++ b/src/useReactions.tsx @@ -184,6 +184,10 @@ export const ReactionsProvider = ({ // This effect handles any *live* reaction/redactions in the room. useEffect(() => { const reactionTimeouts = new Set(); + // TODO: this should be somewhere more sensible + const handleTimelineReset = (): void => { + logger.warn("Received TimelineReset indicating limited sync response"); + }; const handleReactionEvent = (event: MatrixEvent): void => { // Decrypted events might come from a different room if (event.getRoomId() !== room.roomId) return; @@ -297,6 +301,7 @@ export const ReactionsProvider = ({ } }; + room.on(MatrixRoomEvent.TimelineReset, handleTimelineReset); room.on(MatrixRoomEvent.Timeline, handleReactionEvent); room.on(MatrixRoomEvent.Redaction, handleReactionEvent); room.client.on(MatrixEventEvent.Decrypted, handleReactionEvent); @@ -306,6 +311,7 @@ export const ReactionsProvider = ({ room.on(MatrixRoomEvent.LocalEchoUpdated, handleReactionEvent); return (): void => { + room.off(MatrixRoomEvent.TimelineReset, handleTimelineReset); room.off(MatrixRoomEvent.Timeline, handleReactionEvent); room.off(MatrixRoomEvent.Redaction, handleReactionEvent); room.client.off(MatrixEventEvent.Decrypted, handleReactionEvent); diff --git a/src/utils/matrix.ts b/src/utils/matrix.ts index 4b966429..88e1d1cd 100644 --- a/src/utils/matrix.ts +++ b/src/utils/matrix.ts @@ -9,8 +9,10 @@ import { IndexedDBStore } from "matrix-js-sdk/src/store/indexeddb"; import { MemoryStore } from "matrix-js-sdk/src/store/memory"; import { createClient, + Filter, ICreateClientOpts, Preset, + RoomEvent, Visibility, } from "matrix-js-sdk/src/matrix"; import { ClientEvent } from "matrix-js-sdk/src/client"; @@ -165,7 +167,20 @@ export async function initClient( // Otherwise, a sync may complete before the listener gets applied, // and we will miss it. const syncPromise = waitForSync(client); - await client.startClient({ clientWellKnownPollPeriod: 60 * 10 }); + await client.startClient({ + clientWellKnownPollPeriod: 60 * 10, + // ask for a high limit to try and avoid gappy syncs + filter: Filter.fromJson(undefined, "element-call", { + room: { + timeline: { + limit: 1000, + }, + }, + }), + // we ask for 20 past message to try and get some recent context + // n.b. past reactions are not guaranteed to be visible + initialSyncLimit: 20, + }); await syncPromise; return client;