Add an interface for MatrixClientCreds

and make MatrixClientPeg functions use it consistently
pull/21833/head
David Baker 2016-08-03 10:46:42 +01:00
parent cf7e7d65c8
commit d9a7d50a03
3 changed files with 25 additions and 11 deletions

View File

@ -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'});

View File

@ -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,

View File

@ -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