Fix React crash when using a non-default homeserver on soft logout
The function used exists on the peg, not the client. This commit also fixes the name of the function in a backwards compatible way.
This commit is contained in:
parent
017fc84862
commit
1f1a5b2aac
3 changed files with 13 additions and 6 deletions
|
@ -193,7 +193,7 @@ class MatrixClientPeg {
|
||||||
* Throws an error if unable to deduce the homeserver name
|
* Throws an error if unable to deduce the homeserver name
|
||||||
* (eg. if the user is not logged in)
|
* (eg. if the user is not logged in)
|
||||||
*/
|
*/
|
||||||
getHomeServerName() {
|
getHomeserverName() {
|
||||||
const matches = /^@.+:(.+)$/.exec(this.matrixClient.credentials.userId);
|
const matches = /^@.+:(.+)$/.exec(this.matrixClient.credentials.userId);
|
||||||
if (matches === null || matches.length < 1) {
|
if (matches === null || matches.length < 1) {
|
||||||
throw new Error("Failed to derive homeserver name from user ID!");
|
throw new Error("Failed to derive homeserver name from user ID!");
|
||||||
|
@ -201,6 +201,13 @@ class MatrixClientPeg {
|
||||||
return matches[1];
|
return matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use getHomeserverName() instead (correct spelling)
|
||||||
|
*/
|
||||||
|
getHomeServerName() {
|
||||||
|
return this.getHomeserverName();
|
||||||
|
}
|
||||||
|
|
||||||
_createClient(creds: MatrixClientCreds) {
|
_createClient(creds: MatrixClientCreds) {
|
||||||
const aggregateRelations = SettingsStore.isFeatureEnabled("feature_reactions");
|
const aggregateRelations = SettingsStore.isFeatureEnabled("feature_reactions");
|
||||||
const enableEdits = SettingsStore.isFeatureEnabled("feature_message_editing");
|
const enableEdits = SettingsStore.isFeatureEnabled("feature_message_editing");
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default class SoftLogout extends React.Component {
|
||||||
const hsUrl = MatrixClientPeg.get().getHomeserverUrl();
|
const hsUrl = MatrixClientPeg.get().getHomeserverUrl();
|
||||||
const domainName = hsUrl === defaultServerConfig.hsUrl
|
const domainName = hsUrl === defaultServerConfig.hsUrl
|
||||||
? defaultServerConfig.hsName
|
? defaultServerConfig.hsName
|
||||||
: MatrixClientPeg.get().getHomeServerName();
|
: MatrixClientPeg.getHomeserverName();
|
||||||
|
|
||||||
const userId = MatrixClientPeg.get().getUserId();
|
const userId = MatrixClientPeg.get().getUserId();
|
||||||
const user = MatrixClientPeg.get().getUser(userId);
|
const user = MatrixClientPeg.get().getUser(userId);
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default class NetworkDropdown extends React.Component {
|
||||||
|
|
||||||
this.inputTextBox = null;
|
this.inputTextBox = null;
|
||||||
|
|
||||||
const server = MatrixClientPeg.getHomeServerName();
|
const server = MatrixClientPeg.getHomeserverName();
|
||||||
this.state = {
|
this.state = {
|
||||||
expanded: false,
|
expanded: false,
|
||||||
selectedServer: server,
|
selectedServer: server,
|
||||||
|
@ -138,8 +138,8 @@ export default class NetworkDropdown extends React.Component {
|
||||||
servers = servers.concat(roomDirectory.servers);
|
servers = servers.concat(roomDirectory.servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!servers.includes(MatrixClientPeg.getHomeServerName())) {
|
if (!servers.includes(MatrixClientPeg.getHomeserverName())) {
|
||||||
servers.unshift(MatrixClientPeg.getHomeServerName());
|
servers.unshift(MatrixClientPeg.getHomeserverName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// For our own HS, we can use the instance_ids given in the third party protocols
|
// For our own HS, we can use the instance_ids given in the third party protocols
|
||||||
|
@ -148,7 +148,7 @@ export default class NetworkDropdown extends React.Component {
|
||||||
// we can only show the default room list.
|
// we can only show the default room list.
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
options.push(this._makeMenuOption(server, null, true));
|
options.push(this._makeMenuOption(server, null, true));
|
||||||
if (server === MatrixClientPeg.getHomeServerName()) {
|
if (server === MatrixClientPeg.getHomeserverName()) {
|
||||||
options.push(this._makeMenuOption(server, null, false));
|
options.push(this._makeMenuOption(server, null, false));
|
||||||
if (this.props.protocols) {
|
if (this.props.protocols) {
|
||||||
for (const proto of Object.keys(this.props.protocols)) {
|
for (const proto of Object.keys(this.props.protocols)) {
|
||||||
|
|
Loading…
Reference in a new issue