diff --git a/lib/client.js b/lib/client.js index 87476d6c8..11b75e952 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1888,10 +1888,15 @@ MatrixClient.prototype.isLoggedIn = function() { * This is an internal method. * @param {MatrixClient} client * @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( - undefined, "GET", "/initialSync", { limit: (historyLen || 12) } + undefined, "GET", "/initialSync", qps ).done(function(data) { var i, j; // 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 * events, add a listener for {@link module:client~MatrixClient#event:"event"} * via {@link module:client~MatrixClient#on}. - * @param {Number} historyLen amount of historical timeline events to - * emit during from the initial sync. Default: 12. + * @param {Object} opts Options to apply when syncing. + * @param {Number} opts.initialSyncLimit The event limit= to apply + * to initial sync. Default: 8. + * @param {Boolean} opts.includeArchivedRooms True to put archived=true + * on the /initialSync request. Default: false. */ -MatrixClient.prototype.startClient = function(historyLen) { +MatrixClient.prototype.startClient = function(opts) { if (this.clientRunning) { // client is already running. 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) { this.uploadKeys(5); @@ -2018,7 +2036,7 @@ MatrixClient.prototype.startClient = function(historyLen) { var self = this; this.pushRules().done(function(result) { self.pushRules = result; - doInitialSync(self, historyLen); + doInitialSync(self, opts.initialSyncLimit, opts.includeArchivedRooms); }, function(err) { self.emit("syncError", err); });