Skip to content

Commit

Permalink
Merge pull request #388 from vector-im/bwindels/dontassumelocalentrie…
Browse files Browse the repository at this point in the history
…sexists

Prevent 2 more small races between room sync and openTimeline
  • Loading branch information
bwindels authored Jun 4, 2021
2 parents 23321b4 + 7691b28 commit 65eb1f7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/matrix/room/timeline/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class Timeline {
this._disposables = new Disposables();
this._pendingEvents = pendingEvents;
this._clock = clock;
this._remoteEntries = null;
// constructing this early avoid some problem while sync and openTimeline race
this._remoteEntries = new SortedArray((a, b) => a.compare(b));
this._ownMember = null;
this._timelineReader = new TimelineReader({
roomId: this._roomId,
Expand Down Expand Up @@ -96,7 +97,6 @@ export class Timeline {
}

_setupEntries(timelineEntries) {
this._remoteEntries = new SortedArray((a, b) => a.compare(b));
this._remoteEntries.setManySorted(timelineEntries);
if (this._pendingEvents) {
this._localEntries = new MappedList(this._pendingEvents, pe => {
Expand Down Expand Up @@ -159,7 +159,9 @@ export class Timeline {
// Once the subscription is setup, MappedList will set up the local
// relations as needed with _applyAndEmitLocalRelationChange,
// so we're not missing anything by bailing out.
if (!this._localEntries.hasSubscriptions) {
//
// _localEntries can also not yet exist
if (!this._localEntries?.hasSubscriptions) {
return;
}
// find any local relations to this new remote event
Expand Down Expand Up @@ -301,4 +303,4 @@ export function tests() {
assert.equal(Array.from(timeline.entries)[0].isRedacting, true);
}
}
}
}

0 comments on commit 65eb1f7

Please sign in to comment.