1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Don't calculate notifEvents until ready

We were previously computing notifEvents at the point where we
processed them but before the room they belong to was stored.
This was problematic because some push conditions try to get the
room and therefore failed. Since the push actions are cached, this
spurious calculation also got cached.

This moves the calculation out to a separate function that gets
called only after the room has been stored.
This commit is contained in:
David Baker
2017-10-25 11:51:30 +01:00
parent b42a13cc3b
commit e8fc857dbc

View File

@@ -231,6 +231,8 @@ SyncApi.prototype.syncLeftRooms = function() {
room.recalculate(client.credentials.userId); room.recalculate(client.credentials.userId);
client.store.storeRoom(room); client.store.storeRoom(room);
client.emit("Room", room); client.emit("Room", room);
self._processEventForNotifs(room, timelineEvents);
}); });
return rooms; return rooms;
}); });
@@ -961,6 +963,8 @@ SyncApi.prototype._processSyncResponse = async function(syncToken, data) {
client.emit("Room", room); client.emit("Room", room);
} }
self._processEventForNotifs(room, timelineEvents);
async function processRoomEvent(e) { async function processRoomEvent(e) {
client.emit("event", e); client.emit("event", e);
if (e.isState() && e.getType() == "m.room.encryption" && self.opts.crypto) { if (e.isState() && e.getType() == "m.room.encryption" && self.opts.crypto) {
@@ -997,6 +1001,8 @@ SyncApi.prototype._processSyncResponse = async function(syncToken, data) {
client.emit("Room", room); client.emit("Room", room);
} }
self._processEventForNotifs(room, timelineEvents);
stateEvents.forEach(function(e) { stateEvents.forEach(function(e) {
client.emit("event", e); client.emit("event", e);
}); });
@@ -1282,9 +1288,20 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList,
// This also needs to be done before running push rules on the events as they need // This also needs to be done before running push rules on the events as they need
// to be decorated with sender etc. // to be decorated with sender etc.
room.addLiveEvents(timelineEventList); room.addLiveEvents(timelineEventList);
};
/**
* Takes a list of timelineEvents and adds and adds to _notifEvents
* as appropriate.
* This must be called after the room the events belong to has been stored.
*
* @param {Room} room
* @param {MatrixEvent[]} [timelineEventList] A list of timeline events. Lower index
* is earlier in time. Higher index is later.
*/
SyncApi.prototype._processEventForNotifs = function(room, timelineEventList) {
// gather our notifications into this._notifEvents // gather our notifications into this._notifEvents
if (client.getNotifTimelineSet()) { if (this.client.getNotifTimelineSet()) {
for (let i = 0; i < timelineEventList.length; i++) { for (let i = 0; i < timelineEventList.length; i++) {
const pushActions = client.getPushActionsForEvent(timelineEventList[i]); const pushActions = client.getPushActionsForEvent(timelineEventList[i]);
if (pushActions && pushActions.notify && if (pushActions && pushActions.notify &&