From c9cbaf254bac5cf663755de3631090e3ef8389a1 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 23 Feb 2018 11:06:22 +0000 Subject: [PATCH 1/2] Precompute push actions for state events State events get froze now, so we can't write to the push actions cache after having done so: precompute the push actions to work around this. --- src/sync.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sync.js b/src/sync.js index 820351f8b72..8bf777fabd2 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1299,6 +1299,16 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList, const liveTimeline = room.getLiveTimeline(); const timelineWasEmpty = liveTimeline.getEvents().length == 0; if (timelineWasEmpty) { + // Passing these events into initialiseState will freeze them, so we need + // to compute and cache the push actions for them now. + // XXX: This is pretty horrible and is assuming all sorts of behaviour from + // these functions that it shouldn't be. We should probably either store the + // push actions cache elsewhere so we can freeze MatrixEvents, or otherwise + // find some solution where MatrixEvents are immutable but allow for a cache + // field. + for (const ev of stateEventList) { + this.client.getPushActionsForEvent(ev); + } liveTimeline.initialiseState(stateEventList); } From 71652043a03dd4b1b03af321f8890fe505202d55 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 23 Feb 2018 14:31:51 +0000 Subject: [PATCH 2/2] improve doc --- src/sync.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sync.js b/src/sync.js index 8bf777fabd2..3928875f2bb 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1300,7 +1300,8 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList, const timelineWasEmpty = liveTimeline.getEvents().length == 0; if (timelineWasEmpty) { // Passing these events into initialiseState will freeze them, so we need - // to compute and cache the push actions for them now. + // to compute and cache the push actions for them now, otherwise sync dies + // with an attempt to assign to read only property. // XXX: This is pretty horrible and is assuming all sorts of behaviour from // these functions that it shouldn't be. We should probably either store the // push actions cache elsewhere so we can freeze MatrixEvents, or otherwise