remove need for transferLocalEchoState, just add local relations again

This commit is contained in:
Bruno Windels 2021-05-31 16:24:42 +02:00
parent 13a4a0169c
commit addddf1f26
4 changed files with 16 additions and 25 deletions

View File

@ -133,24 +133,27 @@ export class Timeline {
} }
replaceEntries(entries) { replaceEntries(entries) {
this._addLocalRelationsToNewRemoteEntries(entries);
for (const entry of entries) { for (const entry of entries) {
this._remoteEntries.update(entry, null, previousEntry => { this._remoteEntries.update(entry);
entry.transferLocalEchoState(previousEntry); }
}); }
_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 */ /** @package */
addOrReplaceEntries(newEntries) { addOrReplaceEntries(newEntries) {
// find any local relations to this new remote event this._addLocalRelationsToNewRemoteEntries(newEntries);
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._remoteEntries.setManySorted(newEntries); this._remoteEntries.setManySorted(newEntries);
} }

View File

@ -31,13 +31,6 @@ 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;
}
}
/** /**
aggregates local relation. aggregates local relation.
@return [string] returns the name of the field that has changed, if any @return [string] returns the name of the field that has changed, if any

View File

@ -134,7 +134,6 @@ export class FragmentBoundaryEntry extends BaseEntry {
return new FragmentBoundaryEntry(neighbour, !this._isFragmentStart, this._fragmentIdComparer); return new FragmentBoundaryEntry(neighbour, !this._isFragmentStart, this._fragmentIdComparer);
} }
transferLocalEchoState() {}
addLocalRelation() {} addLocalRelation() {}
removeLocalRelation() {} removeLocalRelation() {}
} }

View File

@ -46,13 +46,9 @@ export class SortedArray extends BaseObservableList {
return findAndUpdateInArray(predicate, this._items, this, updater); return findAndUpdateInArray(predicate, this._items, this, updater);
} }
update(item, updateParams = null, previousCallback = null) { update(item, updateParams = null) {
const idx = this.indexOf(item); const idx = this.indexOf(item);
if (idx !== -1) { if (idx !== -1) {
if (previousCallback) {
const oldItem = this._items[idx];
previousCallback(oldItem);
}
this._items[idx] = item; this._items[idx] = item;
this.emitUpdate(idx, item, updateParams); this.emitUpdate(idx, item, updateParams);
} }