Skip to content

Commit 559416d

Browse files
committed
Show most homeserver options on the mobile guide
This doesn't cover default_server_name because that pulls in a questionable amount of JS. See element-hq#9290
1 parent 886828c commit 559416d

2 files changed

Lines changed: 90 additions & 6 deletions

File tree

‎src/vector/mobile_guide/index.html‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
<style type="text/css">
66

7+
/* By default, hide the custom IS stuff - enabled in JS */
8+
#custom_is, #is_url {
9+
display: none;
10+
}
11+
712
body {
813
background: #c5e0f7;
914
background: -moz-linear-gradient(top, #c5e0f7 0%, #ffffff 100%);
@@ -109,6 +114,14 @@
109114
margin: 20px;
110115
}
111116

117+
.mx_HomePage_errorContainer {
118+
display: none; /* shown in JS if needed */
119+
margin: 20px;
120+
border: 1px solid red;
121+
background-color: #ffb9b9;
122+
padding: 5px;
123+
}
124+
112125
.mx_HomePage_container h1,
113126
.mx_HomePage_container h2,
114127
.mx_HomePage_container h3,
@@ -152,6 +165,10 @@
152165

153166
<body>
154167

168+
<div class="mx_HomePage_errorContainer">
169+
<!-- populated by JS if needed -->
170+
</div>
171+
155172
<div class="mx_HomePage_container">
156173
<div class="mx_HomePage_col mx_HomePage_header">
157174
<a href="https://riot.im">
@@ -365,7 +382,9 @@ <h2>Step 2: Use a custom server</h2>
365382
<p>Launch the app, and enable <strong>Use custom server options (advanced)</strong>.</p>
366383
<p class="mx_Spacer">In the homeserver field, enter:</p>
367384
<p><strong id="hs_url"></strong></p>
368-
<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>
385+
<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>
386+
<p class="mx_Spacer" id="custom_is">In the identity server field, enter:</p>
387+
<p><strong id="is_url"></strong></p>
369388
</div>
370389
</div>
371390
</div>

‎src/vector/mobile_guide/index.js‎

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,84 @@ function onBackToRiotClick() {
66
window.location.href = '../';
77
}
88

9+
// NEVER pass user-controlled content to this function! Hardcoded strings only please.
10+
function renderConfigError(message) {
11+
const contactMsg = "If this is unexpected, please contact your system administrator " +
12+
"or technical support representative.";
13+
message = `<h2>Error loading Riot</h2><p>${message}</p><p>${contactMsg}</p>`;
14+
15+
const toHide = document.getElementsByClassName("mx_HomePage_container");
16+
const errorContainers = document.getElementsByClassName("mx_HomePage_errorContainer");
17+
18+
for (const e of toHide) {
19+
// We have to clear the content because .style.display='none'; doesn't work
20+
// due to an !important in the CSS.
21+
e.innerHTML = '';
22+
}
23+
for (const e of errorContainers) {
24+
e.style.display = 'block';
25+
e.innerHTML = message;
26+
}
27+
}
28+
929
async function initPage() {
1030
document.getElementById('back_to_riot_button').onclick = onBackToRiotClick;
1131

12-
const config = await getVectorConfig('..');
13-
let hsUrl;
14-
if (config && config['default_hs_url']) {
15-
hsUrl = config['default_hs_url'];
32+
let config = await getVectorConfig('..');
33+
34+
// We manually parse the config similar to how validateServerConfig works because
35+
// calling that function pulls in roughly 4mb of JS we don't use.
36+
37+
const wkConfig = config['default_server_config']; // overwritten later under some conditions
38+
const serverName = config['default_server_name'];
39+
const defaultHsUrl = config['default_hs_url'];
40+
const defaultIsUrl = config['default_is_url'];
41+
42+
const incompatibleOptions = [wkConfig, serverName, defaultHsUrl].filter(i => !!i);
43+
if (incompatibleOptions.length > 1) {
44+
return renderConfigError(
45+
"Invalid configuration: can only specify one of default_server_config, default_server_name, " +
46+
"or default_hs_url.",
47+
);
1648
}
49+
if (incompatibleOptions.length < 1) {
50+
return renderConfigError("Invalid configuration: no default server specified.");
51+
}
52+
53+
let hsUrl = '';
54+
let isUrl = '';
55+
56+
if (wkConfig && wkConfig['m.homeserver']) {
57+
hsUrl = wkConfig['m.homeserver']['base_url'];
58+
59+
if (wkConfig['m.identity_server']) {
60+
isUrl = wkConfig['m.identity_server']['base_url'];
61+
}
62+
}
63+
64+
if (serverName) {
65+
// TODO: TravisR .well-known lookup
66+
}
67+
68+
if (defaultHsUrl) {
69+
hsUrl = defaultHsUrl;
70+
isUrl = defaultIsUrl;
71+
}
72+
1773
if (hsUrl && !hsUrl.endsWith('/')) hsUrl += '/';
74+
if (isUrl && !isUrl.endsWith('/')) isUrl += '/';
75+
1876
if (hsUrl && hsUrl !== 'https://matrix.org/') {
1977
document.getElementById('step2_container').style.display = 'block';
20-
document.getElementById('hs_url').innerHTML = hsUrl;
78+
document.getElementById('hs_url').innerText = hsUrl;
2179
document.getElementById('step_login_header').innerHTML= 'Step 3: Register or Log in';
80+
81+
if (isUrl && isUrl !== "https://vector.im/") {
82+
document.getElementById('default_is').style.display = 'none';
83+
document.getElementById('custom_is').style.display = 'block';
84+
document.getElementById('is_url').style.display = 'block';
85+
document.getElementById('is_url').innerText = isUrl;
86+
}
2287
}
2388
}
2489

0 commit comments

Comments
 (0)