From d9a7d50a03167d6fbf820796ab2296bc468aab69 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Aug 2016 10:46:42 +0100 Subject: [PATCH] Add an interface for MatrixClientCreds and make MatrixClientPeg functions use it consistently --- src/Lifecycle.js | 5 +---- src/MatrixClientPeg.js | 20 +++++++++++++++++--- src/components/structures/MatrixChat.js | 11 +++++++---- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 24073fe7a6..163e6e9463 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -31,10 +31,7 @@ import dis from './dispatcher'; function setLoggedIn(credentials) { credentials.guest = Boolean(credentials.guest); console.log("onLoggedIn => %s (guest=%s)", credentials.userId, credentials.guest); - MatrixClientPeg.replaceUsingAccessToken( - credentials.homeserverUrl, credentials.identityServerUrl, - credentials.userId, credentials.accessToken, credentials.guest - ); + MatrixClientPeg.replaceUsingCreds(credentials); dis.dispatch({action: 'on_logged_in'}); diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 54e4cbb646..c8b015f99f 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -31,6 +31,14 @@ function deviceId() { return id; } +interface MatrixClientCreds { + homeserverUrl: string, + identityServerUrl: string, + userId: string, + accessToken: string, + guest: boolean, +} + /** * Wrapper object for handling the js-sdk Matrix Client object in the react-sdk * Handles the creation/initialisation of client objects. @@ -70,8 +78,14 @@ class MatrixClientPeg { * Replace this MatrixClientPeg's client with a client instance that has * Home Server / Identity Server URLs and active credentials */ - replaceUsingAccessToken(hs_url, is_url, user_id, access_token, isGuest) { - this._replaceClient(hs_url, is_url, user_id, access_token, isGuest); + replaceUsingCreds(creds: MatrixClientCreds) { + this._replaceClient( + creds.homeserverUrl, + creds.identityServerUrl, + creds.userId, + creds.accessToken, + creds.guest, + ); } _replaceClient(hs_url, is_url, user_id, access_token, isGuest) { @@ -103,7 +117,7 @@ class MatrixClientPeg { } } - getCredentials() { + getCredentials(): MatrixClientCreds { return { homeserverUrl: this.matrixClient.baseUrl, identityServerUrl: this.matrixClient.idBaseUrl, diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 415c736707..b712445dc2 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -340,10 +340,13 @@ module.exports = React.createClass({ var client = MatrixClientPeg.get(); client.loginWithToken(payload.params.loginToken).done(function(data) { - MatrixClientPeg.replaceUsingAccessToken( - client.getHomeserverUrl(), client.getIdentityServerUrl(), - data.user_id, data.access_token - ); + MatrixClientPeg.replaceUsingCreds({ + homeserverUrl: client.getHomeserverUrl(), + identityServerUrl: client.getIdentityServerUrl(), + userId: data.user_id, + accessToken: data.access_token, + guest: false, + }); self.setState({ screen: undefined, logged_in: true