Merge pull request #9726 from vector-im/travis/wk/mobileguide

Show resolved homeserver configuration on the mobile guide
pull/9779/head
Travis Ralston 2019-05-17 11:01:42 -06:00 committed by GitHub
commit 7a65dc96cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 109 additions and 7 deletions

View File

@ -4,6 +4,11 @@
<style type="text/css"> <style type="text/css">
/* By default, hide the custom IS stuff - enabled in JS */
#custom_is, #is_url {
display: none;
}
body { body {
background: #c5e0f7; background: #c5e0f7;
background: -moz-linear-gradient(top, #c5e0f7 0%, #ffffff 100%); background: -moz-linear-gradient(top, #c5e0f7 0%, #ffffff 100%);
@ -109,6 +114,14 @@ body {
margin: 20px; margin: 20px;
} }
.mx_HomePage_errorContainer {
display: none; /* shown in JS if needed */
margin: 20px;
border: 1px solid red;
background-color: #ffb9b9;
padding: 5px;
}
.mx_HomePage_container h1, .mx_HomePage_container h1,
.mx_HomePage_container h2, .mx_HomePage_container h2,
.mx_HomePage_container h3, .mx_HomePage_container h3,
@ -152,6 +165,10 @@ body {
<body> <body>
<div class="mx_HomePage_errorContainer">
<!-- populated by JS if needed -->
</div>
<div class="mx_HomePage_container"> <div class="mx_HomePage_container">
<div class="mx_HomePage_col mx_HomePage_header"> <div class="mx_HomePage_col mx_HomePage_header">
<a href="https://riot.im"> <a href="https://riot.im">
@ -365,7 +382,9 @@ body {
<p>Launch the app, and enable <strong>Use custom server options (advanced)</strong>.</p> <p>Launch the app, and enable <strong>Use custom server options (advanced)</strong>.</p>
<p class="mx_Spacer">In the homeserver field, enter:</p> <p class="mx_Spacer">In the homeserver field, enter:</p>
<p><strong id="hs_url"></strong></p> <p><strong id="hs_url"></strong></p>
<p class="mx_Spacer"><em>Note: You shouldn&apos;t need to modify the identity server field, which by default is set to https://vector.im.</em></p> <p class="mx_Spacer" id="default_is"><em>Note: You shouldn&apos;t need to modify the identity server field, which by default is set to https://vector.im.</em></p>
<p class="mx_Spacer" id="custom_is">In the identity server field, enter:</p>
<p><strong id="is_url"></strong></p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -6,19 +6,102 @@ function onBackToRiotClick() {
window.location.href = '../'; window.location.href = '../';
} }
// NEVER pass user-controlled content to this function! Hardcoded strings only please.
function renderConfigError(message) {
const contactMsg = "If this is unexpected, please contact your system administrator " +
"or technical support representative.";
message = `<h2>Error loading Riot</h2><p>${message}</p><p>${contactMsg}</p>`;
const toHide = document.getElementsByClassName("mx_HomePage_container");
const errorContainers = document.getElementsByClassName("mx_HomePage_errorContainer");
for (const e of toHide) {
// We have to clear the content because .style.display='none'; doesn't work
// due to an !important in the CSS.
e.innerHTML = '';
}
for (const e of errorContainers) {
e.style.display = 'block';
e.innerHTML = message;
}
}
async function initPage() { async function initPage() {
document.getElementById('back_to_riot_button').onclick = onBackToRiotClick; document.getElementById('back_to_riot_button').onclick = onBackToRiotClick;
const config = await getVectorConfig('..'); let config = await getVectorConfig('..');
let hsUrl;
if (config && config['default_hs_url']) { // We manually parse the config similar to how validateServerConfig works because
hsUrl = config['default_hs_url']; // calling that function pulls in roughly 4mb of JS we don't use.
const wkConfig = config['default_server_config']; // overwritten later under some conditions
const serverName = config['default_server_name'];
const defaultHsUrl = config['default_hs_url'];
const defaultIsUrl = config['default_is_url'];
const incompatibleOptions = [wkConfig, serverName, defaultHsUrl].filter(i => !!i);
if (incompatibleOptions.length > 1) {
return renderConfigError(
"Invalid configuration: can only specify one of default_server_config, default_server_name, " +
"or default_hs_url.",
);
} }
if (incompatibleOptions.length < 1) {
return renderConfigError("Invalid configuration: no default server specified.");
}
let hsUrl = '';
let isUrl = '';
if (wkConfig && wkConfig['m.homeserver']) {
hsUrl = wkConfig['m.homeserver']['base_url'];
if (wkConfig['m.identity_server']) {
isUrl = wkConfig['m.identity_server']['base_url'];
}
}
if (serverName) {
// We also do our own minimal .well-known validation to avoid pulling in the js-sdk
try {
const result = await fetch(`https://${serverName}/.well-known/matrix/client`);
const wkConfig = await result.json();
if (wkConfig && wkConfig['m.homeserver']) {
hsUrl = wkConfig['m.homeserver']['base_url'];
if (wkConfig['m.identity_server']) {
isUrl = wkConfig['m.identity_server']['base_url'];
}
}
} catch (e) {
console.error(e);
return renderConfigError("Unable to fetch homeserver configuration");
}
}
if (defaultHsUrl) {
hsUrl = defaultHsUrl;
isUrl = defaultIsUrl;
}
if (!hsUrl) {
return renderConfigError("Unable to locate homeserver");
}
if (hsUrl && !hsUrl.endsWith('/')) hsUrl += '/'; if (hsUrl && !hsUrl.endsWith('/')) hsUrl += '/';
if (hsUrl && hsUrl !== 'https://matrix.org/') { if (isUrl && !isUrl.endsWith('/')) isUrl += '/';
if (hsUrl !== 'https://matrix.org/') {
document.getElementById('step2_container').style.display = 'block'; document.getElementById('step2_container').style.display = 'block';
document.getElementById('hs_url').innerHTML = hsUrl; document.getElementById('hs_url').innerText = hsUrl;
document.getElementById('step_login_header').innerHTML= 'Step 3: Register or Log in'; document.getElementById('step_login_header').innerHTML= 'Step 3: Register or Log in';
if (isUrl && isUrl !== "https://vector.im/") {
document.getElementById('default_is').style.display = 'none';
document.getElementById('custom_is').style.display = 'block';
document.getElementById('is_url').style.display = 'block';
document.getElementById('is_url').innerText = isUrl;
}
} }
} }