From addddf1f26982efbdaf0ebff13f3033f084555de Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 31 May 2021 16:24:42 +0200 Subject: [PATCH] remove need for transferLocalEchoState, just add local relations again --- src/matrix/room/timeline/Timeline.js | 27 ++++++++++--------- .../room/timeline/entries/BaseEventEntry.js | 7 ----- .../timeline/entries/FragmentBoundaryEntry.js | 1 - src/observable/list/SortedArray.js | 6 +---- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index 9251c833..cced535c 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -133,24 +133,27 @@ export class Timeline { } replaceEntries(entries) { + this._addLocalRelationsToNewRemoteEntries(entries); for (const entry of entries) { - this._remoteEntries.update(entry, null, previousEntry => { - entry.transferLocalEchoState(previousEntry); - }); + this._remoteEntries.update(entry); + } + } + + _addLocalRelationsToNewRemoteEntries(entries) { + // find any local relations to this new remote event + for (const pee of this._localEntries) { + // this will work because we set relatedEventId when removing remote echos + if (pee.relatedEventId) { + const relationTarget = entries.find(e => e.id === pee.relatedEventId); + // no need to emit here as this entry is about to be added + relationTarget?.addLocalRelation(pee); + } } } /** @package */ addOrReplaceEntries(newEntries) { - // find any local relations to this new remote event - for (const pee of this._localEntries) { - // this will work because we set relatedEventId when removing remote echos - if (pee.relatedEventId) { - const relationTarget = newEntries.find(e => e.id === pee.relatedEventId); - // no need to emit here as this entry is about to be added - relationTarget?.addLocalRelation(pee); - } - } + this._addLocalRelationsToNewRemoteEntries(newEntries); this._remoteEntries.setManySorted(newEntries); } diff --git a/src/matrix/room/timeline/entries/BaseEventEntry.js b/src/matrix/room/timeline/entries/BaseEventEntry.js index a3748c8b..e474deb4 100644 --- a/src/matrix/room/timeline/entries/BaseEventEntry.js +++ b/src/matrix/room/timeline/entries/BaseEventEntry.js @@ -31,13 +31,6 @@ export class BaseEventEntry extends BaseEntry { return this.isRedacting; } - // when replacing an entry, local echo state can be transfered here - transferLocalEchoState(oldEntry) { - if (oldEntry._pendingRedactions) { - this._pendingRedactions = oldEntry._pendingRedactions; - } - } - /** aggregates local relation. @return [string] returns the name of the field that has changed, if any diff --git a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js index 081d18a2..0eb2a5b6 100644 --- a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js +++ b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js @@ -134,7 +134,6 @@ export class FragmentBoundaryEntry extends BaseEntry { return new FragmentBoundaryEntry(neighbour, !this._isFragmentStart, this._fragmentIdComparer); } - transferLocalEchoState() {} addLocalRelation() {} removeLocalRelation() {} } diff --git a/src/observable/list/SortedArray.js b/src/observable/list/SortedArray.js index cf17449b..39cfcde5 100644 --- a/src/observable/list/SortedArray.js +++ b/src/observable/list/SortedArray.js @@ -46,13 +46,9 @@ export class SortedArray extends BaseObservableList { return findAndUpdateInArray(predicate, this._items, this, updater); } - update(item, updateParams = null, previousCallback = null) { + update(item, updateParams = null) { const idx = this.indexOf(item); if (idx !== -1) { - if (previousCallback) { - const oldItem = this._items[idx]; - previousCallback(oldItem); - } this._items[idx] = item; this.emitUpdate(idx, item, updateParams); }