1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-18 05:42:00 +03:00

Merge pull request #25 from matrix-org/initial-sync-improvements

Add support for archived=true in initial sync
This commit is contained in:
Kegsay
2015-10-19 15:31:32 +01:00

View File

@@ -1888,10 +1888,15 @@ MatrixClient.prototype.isLoggedIn = function() {
* This is an internal method. * This is an internal method.
* @param {MatrixClient} client * @param {MatrixClient} client
* @param {integer} historyLen * @param {integer} historyLen
* @param {integer} includeArchived
*/ */
function doInitialSync(client, historyLen) { function doInitialSync(client, historyLen, includeArchived) {
var qps = { limit: historyLen };
if (includeArchived) {
qps.archived = true;
}
client._http.authedRequest( client._http.authedRequest(
undefined, "GET", "/initialSync", { limit: (historyLen || 12) } undefined, "GET", "/initialSync", qps
).done(function(data) { ).done(function(data) {
var i, j; var i, j;
// intercept the results and put them into our store // intercept the results and put them into our store
@@ -1993,14 +1998,27 @@ function doInitialSync(client, historyLen) {
* and then start polling the eventStream for new events. To listen for these * and then start polling the eventStream for new events. To listen for these
* events, add a listener for {@link module:client~MatrixClient#event:"event"} * events, add a listener for {@link module:client~MatrixClient#event:"event"}
* via {@link module:client~MatrixClient#on}. * via {@link module:client~MatrixClient#on}.
* @param {Number} historyLen amount of historical timeline events to * @param {Object} opts Options to apply when syncing.
* emit during from the initial sync. Default: 12. * @param {Number} opts.initialSyncLimit The event <code>limit=</code> to apply
* to initial sync. Default: 8.
* @param {Boolean} opts.includeArchivedRooms True to put <code>archived=true</code>
* on the <code>/initialSync</code> request. Default: false.
*/ */
MatrixClient.prototype.startClient = function(historyLen) { MatrixClient.prototype.startClient = function(opts) {
if (this.clientRunning) { if (this.clientRunning) {
// client is already running. // client is already running.
return; return;
} }
// backwards compat for when 'opts' was 'historyLen'.
if (typeof opts === "number") {
opts = {
initialSyncLimit: opts
};
}
opts = opts || {};
opts.initialSyncLimit = opts.initialSyncLimit || 8;
opts.includeArchivedRooms = opts.includeArchivedRooms || false;
if (CRYPTO_ENABLED && this.sessionStore !== null) { if (CRYPTO_ENABLED && this.sessionStore !== null) {
this.uploadKeys(5); this.uploadKeys(5);
@@ -2018,7 +2036,7 @@ MatrixClient.prototype.startClient = function(historyLen) {
var self = this; var self = this;
this.pushRules().done(function(result) { this.pushRules().done(function(result) {
self.pushRules = result; self.pushRules = result;
doInitialSync(self, historyLen); doInitialSync(self, opts.initialSyncLimit, opts.includeArchivedRooms);
}, function(err) { }, function(err) {
self.emit("syncError", err); self.emit("syncError", err);
}); });