Don't use MatrixClientPeg for temporary clients

Get rid of MatrixClientPeg.replaceUsingUrls, and instead create local,
temporary MatrixClients for the unauthed steps; we therefore only use
MatrixClientPeg for logged-in clients.
This commit is contained in:
Richard van der Hoff 2016-08-11 13:50:38 +01:00
parent 3704e2c648
commit e32c325863
4 changed files with 61 additions and 97 deletions

View file

@ -67,26 +67,12 @@ class MatrixClientPeg {
this.matrixClient = null;
}
/**
* Replace this MatrixClientPeg's client with a client instance that has
* Home Server / Identity Server URLs but no credentials
*/
replaceUsingUrls(hs_url, is_url) {
this._replaceClient(hs_url, is_url);
}
/**
* Replace this MatrixClientPeg's client with a client instance that has
* Home Server / Identity Server URLs and active credentials
*/
replaceUsingCreds(creds: MatrixClientCreds) {
this._replaceClient(
creds.homeserverUrl,
creds.identityServerUrl,
creds.userId,
creds.accessToken,
creds.guest,
);
this._createClient(creds);
}
start() {
@ -96,10 +82,6 @@ class MatrixClientPeg {
this.get().startClient(opts);
}
_replaceClient(hs_url, is_url, user_id, access_token, isGuest) {
this._createClient(hs_url, is_url, user_id, access_token, isGuest);
}
getCredentials(): MatrixClientCreds {
return {
homeserverUrl: this.matrixClient.baseUrl,
@ -110,12 +92,12 @@ class MatrixClientPeg {
};
}
_createClient(hs_url, is_url, user_id, access_token, isGuest) {
_createClient(creds: MatrixClientCreds) {
var opts = {
baseUrl: hs_url,
idBaseUrl: is_url,
accessToken: access_token,
userId: user_id,
baseUrl: creds.homeserverUrl,
idBaseUrl: creds.identityServerUrl,
accessToken: creds.accessToken,
userId: creds.userId,
timelineSupport: true,
};
@ -130,7 +112,7 @@ class MatrixClientPeg {
// potential number of event listeners is quite high.
this.matrixClient.setMaxListeners(500);
this.matrixClient.setGuest(Boolean(isGuest));
this.matrixClient.setGuest(Boolean(creds.guest));
}
}