From 201b70ee4f1087c0fe2fc1b47f3b993b80b2ac67 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Sat, 12 Oct 2019 22:18:36 +0200 Subject: [PATCH] fix failing to sync new rooms --- .../room/timeline/persistence/SyncWriter.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/matrix/room/timeline/persistence/SyncWriter.js b/src/matrix/room/timeline/persistence/SyncWriter.js index 550df584..6e5701f2 100644 --- a/src/matrix/room/timeline/persistence/SyncWriter.js +++ b/src/matrix/room/timeline/persistence/SyncWriter.js @@ -3,6 +3,20 @@ import EventEntry from "../entries/EventEntry.js"; import FragmentBoundaryEntry from "../entries/FragmentBoundaryEntry.js"; import {createEventEntry} from "./common.js"; +// Synapse bug? where the m.room.create event appears twice in sync response +// when first syncing the room +function deduplicateEvents(events) { + const eventIds = new Set(); + return events.filter(e => { + if (eventIds.has(e.event_id)) { + return false; + } else { + eventIds.add(e.event_id); + return true; + } + }); +} + export default class SyncWriter { constructor({roomId, storage, fragmentIdComparer}) { this._roomId = roomId; @@ -89,7 +103,8 @@ export default class SyncWriter { } let currentKey = this._lastLiveKey; if (timeline.events) { - for(const event of timeline.events) { + const events = deduplicateEvents(timeline.events); + for(const event of events) { currentKey = currentKey.nextKey(); const entry = createEventEntry(currentKey, this._roomId, event); txn.timelineEvents.insert(entry);