forked from mystiq/hydrogen-web
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:
parent
ca4d09e923
commit
da02b5fe2d
3 changed files with 24 additions and 1 deletions
|
@ -122,7 +122,9 @@ export class Timeline {
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
// this will use the comparator and thus
|
// this will use the comparator and thus
|
||||||
// check for equality using the compare method in BaseEntry
|
// check for equality using the compare method in BaseEntry
|
||||||
this._remoteEntries.update(entry);
|
this._remoteEntries.findAndUpdate(entry, (previousEntry, entry) => {
|
||||||
|
entry.transferLocalEchoState(previousEntry);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,11 @@ export class BaseEventEntry extends BaseEntry {
|
||||||
return this.isRedacting;
|
return this.isRedacting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when replacing an entry, local echo state can be transfered here
|
||||||
|
transferLocalEchoState(oldEntry) {
|
||||||
|
if (oldEntry._pendingRedactions) {
|
||||||
|
this._pendingRedactions = oldEntry._pendingRedactions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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) {
|
update(item, updateParams = null) {
|
||||||
const idx = this.indexOf(item);
|
const idx = this.indexOf(item);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
|
|
Loading…
Reference in a new issue