transfer local echo state when replacing event entry

e.g. after decryption or remote echo of other relation comes in
This commit is contained in:
Bruno Windels 2021-05-26 13:10:19 +02:00
parent ca4d09e923
commit da02b5fe2d
3 changed files with 24 additions and 1 deletions

View File

@ -122,7 +122,9 @@ export class Timeline {
for (const entry of entries) {
// this will use the comparator and thus
// check for equality using the compare method in BaseEntry
this._remoteEntries.update(entry);
this._remoteEntries.findAndUpdate(entry, (previousEntry, entry) => {
entry.transferLocalEchoState(previousEntry);
});
}
}

View File

@ -31,6 +31,11 @@ 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;
}
}
/**

View File

@ -41,6 +41,22 @@ export class SortedArray extends BaseObservableList {
}
}
findAndUpdate(newValue, updater) {
const index = this.indexOf(newValue);
if (index !== -1) {
const oldValue = this._items[index];
// allow bailing out of sending an emit if updater determined its not needed
const params = updater(oldValue, newValue);
if (params !== false) {
this._items[index] = newValue;
this.emitUpdate(index, newValue, params);
}
// found
return true;
}
return false;
}
update(item, updateParams = null) {
const idx = this.indexOf(item);
if (idx !== -1) {