You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Refactor the addition of events to rooms
... and add some sanity checks Two things here: 1. Clean up the Room API for adding new events to the timeline. Where before we had addEvents and addEventsToTimeline, whose purposes were unclear, we now have addLiveEvents which must be used for adding events to the end of the live timeline, and addEventsToTimeline which should be used for pagination (either back-pagination of the live timeline, or pagination of an old timeline). 2. Add some sanity checks for the live timeline. Today we have seen problems where somehow the live timeline had gained a forward pagination token, or the live timeline had got joined to another timeline, leading to much confusion - and I would like to notice these sooner.
This commit is contained in:
@@ -262,7 +262,8 @@ SyncApi.prototype.peek = function(roomId) {
|
||||
// will overwrite the pagination token, so make sure it overwrites
|
||||
// it with the right thing.
|
||||
peekRoom.addEventsToTimeline(messages.reverse(), true,
|
||||
undefined, response.messages.start);
|
||||
peekRoom.getLiveTimeline(),
|
||||
response.messages.start);
|
||||
|
||||
client.store.storeRoom(peekRoom);
|
||||
client.emit("Room", peekRoom);
|
||||
@@ -328,7 +329,7 @@ SyncApi.prototype._peekPoll = function(roomId, token) {
|
||||
return e.room_id === roomId;
|
||||
}).map(self.client.getEventMapper());
|
||||
var room = self.client.getRoom(roomId);
|
||||
room.addEvents(events);
|
||||
room.addLiveEvents(events);
|
||||
self._peekPoll(roomId, res.end);
|
||||
}, function(err) {
|
||||
console.error("[%s] Peek poll failed: %s", roomId, err);
|
||||
@@ -717,7 +718,7 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
|
||||
// XXX: should we be adding ephemeralEvents to the timeline?
|
||||
// It feels like that for symmetry with room.addAccountData()
|
||||
// there should be a room.addEphemeralEvents() or similar.
|
||||
room.addEvents(ephemeralEvents);
|
||||
room.addLiveEvents(ephemeralEvents);
|
||||
|
||||
// we deliberately don't add accountData to the timeline
|
||||
room.addAccountData(accountDataEvents);
|
||||
@@ -993,7 +994,7 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList,
|
||||
|
||||
// execute the timeline events, this will begin to diverge the current state
|
||||
// if the timeline has any state events in it.
|
||||
room.addEventsToTimeline(timelineEventList);
|
||||
room.addLiveEvents(timelineEventList);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user