Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #501 from matrix-org/dbkr/get_hs_name
Browse files Browse the repository at this point in the history
Add 'getHomeServerName' util to client peg
  • Loading branch information
dbkr authored Sep 28, 2016
2 parents b366973 + 4942f4f commit 66ef1e8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/MatrixClientPeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ class MatrixClientPeg {
};
}

/**
* Return the server name of the user's home server
* Throws an error if unable to deduce the home server name
* (eg. if the user is not logged in)
*/
getHomeServerName() {
const matches = /^@.+:(.+)$/.exec(this.matrixClient.credentials.userId);
if (matches === null || matches.length < 1) {
throw new Error("Failed to derive home server name from user ID!");
}
return matches[1];
}

_createClient(creds: MatrixClientCreds) {
var opts = {
baseUrl: creds.homeserverUrl,
Expand Down

0 comments on commit 66ef1e8

Please # to comment.