From 021844bf0a15cb9cb567b0f56f92d0730424b1df Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 8 Sep 2021 14:10:20 -0700 Subject: [PATCH] Allow simultaneous adds --- src/matrix/room/BaseRoom.js | 4 +--- src/matrix/room/timeline/FragmentIdComparer.js | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 2d401a65..4b6fccd7 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -300,9 +300,7 @@ export class BaseRoom extends EventEmitter { await decryptRequest.complete(); } // once txn is committed, update in-memory state & emit events - for (const fragment of gapResult.fragments) { - this._fragmentIdComparer.add(fragment); - } + this._fragmentIdComparer.add(...gapResult.fragments); if (extraGapFillChanges) { this._applyGapFill(extraGapFillChanges); } diff --git a/src/matrix/room/timeline/FragmentIdComparer.js b/src/matrix/room/timeline/FragmentIdComparer.js index fcd27edf..ec564b51 100644 --- a/src/matrix/room/timeline/FragmentIdComparer.js +++ b/src/matrix/room/timeline/FragmentIdComparer.js @@ -171,9 +171,11 @@ export class FragmentIdComparer { } /** use for fragments coming out of persistence, not newly created ones, or also fragments for a new island (like for a permalink) */ - add(fragment) { - const copy = new Fragment(fragment.id, fragment.previousId, fragment.nextId); - this._fragmentsById.set(fragment.id, copy); + add(...fragments) { + for (const fragment of fragments) { + const copy = new Fragment(fragment.id, fragment.previousId, fragment.nextId); + this._fragmentsById.set(fragment.id, copy); + } this.rebuild(this._fragmentsById.values()); }