You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-09-01 21:21:58 +03:00
Add more webstore unit tests.
This commit is contained in:
@@ -178,6 +178,7 @@ WebStorageStore.prototype.getRoom = function(roomId) {
|
||||
}
|
||||
var timelineKeys = getTimelineIndices(this.store, roomId);
|
||||
if (timelineKeys.indexOf("live") !== -1) {
|
||||
console.log("Syncing live");
|
||||
this._syncTimeline(roomId, timelineKeys);
|
||||
}
|
||||
return loadRoom(this.store, roomId, this.batchSize);
|
||||
@@ -240,7 +241,8 @@ WebStorageStore.prototype._syncTimeline = function(roomId, timelineIndices) {
|
||||
var lowestIndex = getLowestIndex(timelineIndices);
|
||||
var lowKey = keyName(roomId, "timeline", lowestIndex);
|
||||
var lowestBatch = this.store.getItem(lowKey) || [];
|
||||
|
||||
console.log("Live Events = %s, Low batch = %s (i=%s;b=%s)", liveEvents.length,
|
||||
lowestBatch.length, lowestIndex, this.batchSize);
|
||||
// fill up the existing batch first.
|
||||
while (lowestBatch.length < this.batchSize && liveEvents.length > 0) {
|
||||
lowestBatch.unshift(liveEvents.shift());
|
||||
@@ -251,7 +253,7 @@ WebStorageStore.prototype._syncTimeline = function(roomId, timelineIndices) {
|
||||
var batch = [];
|
||||
while (liveEvents.length > 0) {
|
||||
batch.unshift(liveEvents.shift());
|
||||
if (batch.length === this.batchSize) {
|
||||
if (batch.length === this.batchSize || liveEvents.length === 0) {
|
||||
// persist the full batch and make another
|
||||
lowestIndex--;
|
||||
lowKey = keyName(roomId, "timeline", lowestIndex);
|
||||
@@ -325,7 +327,7 @@ function loadRoom(store, roomId, numEvents) {
|
||||
var stateEvents = [];
|
||||
utils.forEach(utils.keys(currentStateMap.events), function(eventType) {
|
||||
utils.forEach(utils.keys(currentStateMap.events[eventType]), function(skey) {
|
||||
stateEvents.push(currentStateMap[eventType][skey]);
|
||||
stateEvents.push(currentStateMap.events[eventType][skey]);
|
||||
});
|
||||
});
|
||||
// TODO: Fix logic dupe with MatrixClient._processRoomEvents
|
||||
@@ -354,7 +356,11 @@ function loadRoom(store, roomId, numEvents) {
|
||||
}
|
||||
for (i = 0; i < batch.length; i++) {
|
||||
recentEvents.unshift(new MatrixEvent(batch[i]));
|
||||
if (recentEvents.length === numEvents) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
room.addEventsToTimeline(recentEvents.reverse(), true);
|
||||
room.oldState.paginationToken = currentStateMap.pagination_token;
|
||||
|
Reference in New Issue
Block a user