You've already forked matrix-js-sdk
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:
@@ -134,6 +134,7 @@ describe("MatrixClient", function() {
|
|||||||
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
||||||
"save", "setSyncToken", "storeEvents", "storeRoom", "storeUser",
|
"save", "setSyncToken", "storeEvents", "storeRoom", "storeUser",
|
||||||
"getFilterIdByName", "setFilterIdByName", "getFilter", "storeFilter",
|
"getFilterIdByName", "setFilterIdByName", "getFilter", "storeFilter",
|
||||||
|
"getSyncAccumulator",
|
||||||
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
||||||
client = new MatrixClient({
|
client = new MatrixClient({
|
||||||
baseUrl: "https://my.home.server",
|
baseUrl: "https://my.home.server",
|
||||||
|
@@ -1,11 +1,27 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
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";
|
"use strict";
|
||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
const sdk = require("../..");
|
import utils from "../test-utils";
|
||||||
const SyncAccumulator = sdk.SyncAccumulator;
|
import sdk from "../..";
|
||||||
const utils = require("../test-utils");
|
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
|
|
||||||
|
const SyncAccumulator = sdk.SyncAccumulator;
|
||||||
|
|
||||||
describe("SyncAccumulator", function() {
|
describe("SyncAccumulator", function() {
|
||||||
let sa;
|
let sa;
|
||||||
|
|
||||||
|
@@ -38,7 +38,6 @@ const Filter = require("./filter");
|
|||||||
const SyncApi = require("./sync");
|
const SyncApi = require("./sync");
|
||||||
const MatrixBaseApis = require("./base-apis");
|
const MatrixBaseApis = require("./base-apis");
|
||||||
const MatrixError = httpApi.MatrixError;
|
const MatrixError = httpApi.MatrixError;
|
||||||
const IndexedDBStore = require("./store/indexeddb").IndexedDBStore;
|
|
||||||
|
|
||||||
const SCROLLBACK_DELAY_MS = 3000;
|
const SCROLLBACK_DELAY_MS = 3000;
|
||||||
let CRYPTO_ENABLED = false;
|
let CRYPTO_ENABLED = false;
|
||||||
@@ -165,10 +164,7 @@ function MatrixClient(opts) {
|
|||||||
this.olmVersion = Crypto.getOlmVersion();
|
this.olmVersion = Crypto.getOlmVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up a sync accumulator if we can persist room data
|
this._syncAccumulator = this.store.getSyncAccumulator();
|
||||||
if (this.store instanceof IndexedDBStore) {
|
|
||||||
this._syncAccumulator = this.store.getSyncAccumulator();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
utils.inherits(MatrixClient, EventEmitter);
|
utils.inherits(MatrixClient, EventEmitter);
|
||||||
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);
|
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
|
Copyright 2017 Vector Creations Ltd
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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 does nothing as there is no backing data store.
|
||||||
*/
|
*/
|
||||||
save: function() {},
|
save: function() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns nothing as this store does not accumulate /sync data.
|
||||||
|
* @return {?SyncAccumulator} null
|
||||||
|
*/
|
||||||
|
getSyncAccumulator: function() {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
|
Copyright 2017 Vector Creations Ltd
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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 does nothing as there is no backing data store.
|
||||||
*/
|
*/
|
||||||
save: function() {},
|
save: function() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns nothing as this store does not accumulate /sync data.
|
||||||
|
* @return {?SyncAccumulator} null
|
||||||
|
*/
|
||||||
|
getSyncAccumulator: function() {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Stub Store class. */
|
/** Stub Store class. */
|
||||||
|
@@ -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
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an internal module. See {@link SyncAccumulator} for the public class.
|
* This is an internal module. See {@link SyncAccumulator} for the public class.
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
|
Copyright 2017 Vector Creations Ltd
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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;
|
qps.timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// normal timeout= plus buffer time
|
|
||||||
const clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
|
|
||||||
|
|
||||||
let isCachedResponse = false;
|
let isCachedResponse = false;
|
||||||
if (self.opts.syncAccumulator && !syncOptions.hasSyncedBefore) {
|
if (self.opts.syncAccumulator && !syncOptions.hasSyncedBefore) {
|
||||||
let data = self.opts.syncAccumulator.getJSON();
|
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");
|
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
|
// 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)
|
// 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({
|
this._currentSyncRequest = q.resolve({
|
||||||
next_batch: data.nextBatch,
|
next_batch: data.nextBatch,
|
||||||
rooms: data.roomsData,
|
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) {
|
if (!isCachedResponse) {
|
||||||
debuglog('Starting sync since=' + syncToken);
|
debuglog('Starting sync since=' + syncToken);
|
||||||
this._currentSyncRequest = client._http.authedRequest(
|
this._currentSyncRequest = client._http.authedRequest(
|
||||||
|
Reference in New Issue
Block a user