1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Review comments

This commit is contained in:
Kegan Dougal
2017-02-16 11:28:51 +00:00
parent b02ba08abc
commit 9a9646d012
7 changed files with 45 additions and 14 deletions

View File

@@ -38,7 +38,6 @@ const Filter = require("./filter");
const SyncApi = require("./sync");
const MatrixBaseApis = require("./base-apis");
const MatrixError = httpApi.MatrixError;
const IndexedDBStore = require("./store/indexeddb").IndexedDBStore;
const SCROLLBACK_DELAY_MS = 3000;
let CRYPTO_ENABLED = false;
@@ -165,10 +164,7 @@ function MatrixClient(opts) {
this.olmVersion = Crypto.getOlmVersion();
}
// Set up a sync accumulator if we can persist room data
if (this.store instanceof IndexedDBStore) {
this._syncAccumulator = this.store.getSyncAccumulator();
}
this._syncAccumulator = this.store.getSyncAccumulator();
}
utils.inherits(MatrixClient, EventEmitter);
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);

View File

@@ -1,5 +1,6 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -279,4 +280,12 @@ module.exports.MatrixInMemoryStore.prototype = {
* Save does nothing as there is no backing data store.
*/
save: function() {},
/**
* Returns nothing as this store does not accumulate /sync data.
* @return {?SyncAccumulator} null
*/
getSyncAccumulator: function() {
return null;
},
};

View File

@@ -1,5 +1,6 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -184,6 +185,14 @@ StubStore.prototype = {
* Save does nothing as there is no backing data store.
*/
save: function() {},
/**
* Returns nothing as this store does not accumulate /sync data.
* @return {?SyncAccumulator} null
*/
getSyncAccumulator: function() {
return null;
},
};
/** Stub Store class. */

View File

@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
"use strict";
/**
* This is an internal module. See {@link SyncAccumulator} for the public class.

View File

@@ -1,5 +1,6 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -508,9 +509,6 @@ SyncApi.prototype._sync = function(syncOptions) {
qps.timeout = 0;
}
// normal timeout= plus buffer time
const clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
let isCachedResponse = false;
if (self.opts.syncAccumulator && !syncOptions.hasSyncedBefore) {
let data = self.opts.syncAccumulator.getJSON();
@@ -520,7 +518,7 @@ SyncApi.prototype._sync = function(syncOptions) {
debuglog("sync(): not doing HTTP hit, instead returning stored /sync data");
// We must deep copy the stored data so that the /sync processing code doesn't
// corrupt the internal state of the sync accumulator (it adds non-clonable keys)
data = JSON.parse(JSON.stringify(data));
data = utils.deepCopy(data);
this._currentSyncRequest = q.resolve({
next_batch: data.nextBatch,
rooms: data.roomsData,
@@ -529,6 +527,9 @@ SyncApi.prototype._sync = function(syncOptions) {
}
}
// normal timeout= plus buffer time
const clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
if (!isCachedResponse) {
debuglog('Starting sync since=' + syncToken);
this._currentSyncRequest = client._http.authedRequest(