From a5384d32e21ff2b32af59cb8de5968e7d844bb9e Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 16:28:37 +0100 Subject: [PATCH 1/6] Copy opts to set pendingEventOrdering --- src/Lifecycle.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 163e6e9463..d91b49ad7c 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -19,6 +19,7 @@ import Notifier from './Notifier' import UserActivity from './UserActivity'; import Presence from './Presence'; import dis from './dispatcher'; +import utils from 'matrix-js-sdk/lib/utils'; /** * Transitions to a logged-in state using the given credentials @@ -80,11 +81,9 @@ function startMatrixClient() { UserActivity.start(); Presence.start(); - // the react sdk doesn't work without this, so don't allow - // it to be overridden (and modify the global object so at - // at least the app can see we've changed it) - MatrixClientPeg.opts.pendingEventOrdering = "detached"; - MatrixClientPeg.get().startClient(MatrixClientPeg.opts); + let opts = utils.deepCopy(MatrixClientPeg.opts); + opts.pendingEventOrdering = "detached"; + MatrixClientPeg.get().startClient(opts); } function _onLoggedOut() { From b95a1c4a4b388bef4600e1593260444b11cff819 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 16:31:42 +0100 Subject: [PATCH 2/6] Just doc with the MatrixClientCreds object --- src/Lifecycle.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index d91b49ad7c..3bf52b6cf2 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -23,11 +23,7 @@ import utils from 'matrix-js-sdk/lib/utils'; /** * Transitions to a logged-in state using the given credentials - * @param {string} credentials.homeserverUrl The base HS URL - * @param {string} credentials.identityServerUrl The base IS URL - * @param {string} credentials.userId The full Matrix User ID - * @param {string} credentials.accessToken The session access token - * @param {boolean} credentials.guest True if the session is a guest session + * @param {MatrixClientCreds} credentials The credentials to use */ function setLoggedIn(credentials) { credentials.guest = Boolean(credentials.guest); From 9bf45fb556ace7fee6bd02cfb8ce12eb7e5279fb Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 16:39:47 +0100 Subject: [PATCH 3/6] Add start wrapper in MatrixClientPeg to handle the opts dictionary --- src/Lifecycle.js | 4 +--- src/MatrixClientPeg.js | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 3bf52b6cf2..f6aead4786 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -77,9 +77,7 @@ function startMatrixClient() { UserActivity.start(); Presence.start(); - let opts = utils.deepCopy(MatrixClientPeg.opts); - opts.pendingEventOrdering = "detached"; - MatrixClientPeg.get().startClient(opts); + MatrixClientPeg.start(); } function _onLoggedOut() { diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index c8b015f99f..0d5af6ccf4 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -88,6 +88,12 @@ class MatrixClientPeg { ); } + start() { + const opts = utils.deepCopy(MatrixClientPeg.opts); + opts.pendingEventOrdering = "detached"; + this.get().startClient(opts); + }, + _replaceClient(hs_url, is_url, user_id, access_token, isGuest) { if (localStorage) { try { From 009c768b72a77fc6a0564b0461d27bdc0e2a2638 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 16:41:22 +0100 Subject: [PATCH 4/6] Comma fail --- src/MatrixClientPeg.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 0d5af6ccf4..63032fb0bd 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -92,7 +92,7 @@ class MatrixClientPeg { const opts = utils.deepCopy(MatrixClientPeg.opts); opts.pendingEventOrdering = "detached"; this.get().startClient(opts); - }, + } _replaceClient(hs_url, is_url, user_id, access_token, isGuest) { if (localStorage) { From 0919e4146907ea8672d857f5d5a75e3ed8754ae8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 16:45:23 +0100 Subject: [PATCH 5/6] Fix MatrixClientPeg.start() Move import & use `this` --- src/Lifecycle.js | 1 - src/MatrixClientPeg.js | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index f6aead4786..7c507c2c50 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -19,7 +19,6 @@ import Notifier from './Notifier' import UserActivity from './UserActivity'; import Presence from './Presence'; import dis from './dispatcher'; -import utils from 'matrix-js-sdk/lib/utils'; /** * Transitions to a logged-in state using the given credentials diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 63032fb0bd..3599c55f13 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -17,6 +17,7 @@ limitations under the License. 'use strict'; import Matrix from 'matrix-js-sdk'; +import utils from 'matrix-js-sdk/lib/utils'; const localStorage = window.localStorage; @@ -89,7 +90,7 @@ class MatrixClientPeg { } start() { - const opts = utils.deepCopy(MatrixClientPeg.opts); + const opts = utils.deepCopy(this.opts); opts.pendingEventOrdering = "detached"; this.get().startClient(opts); } From b32a19a0f1828125c96e1cb3890b80374281a955 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 17:23:09 +0100 Subject: [PATCH 6/6] Comments --- src/MatrixClientPeg.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 3599c55f13..e6d0e7f3f7 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -50,10 +50,10 @@ class MatrixClientPeg { constructor() { this.matrixClient = null; - // These are the default options used when Lifecycle.js - // starts the client. These can be altered at any - // time up to after the 'will_start_client' event is - // finished processing. + // These are the default options used when when the + // client is started in 'start'. These can be altered + // at any time up to after the 'will_start_client' + // event is finished processing. this.opts = { initialSyncLimit: 20, }; @@ -91,6 +91,7 @@ class MatrixClientPeg { start() { const opts = utils.deepCopy(this.opts); + // the react sdk doesn't work without this, so don't allow opts.pendingEventOrdering = "detached"; this.get().startClient(opts); }