dashboard: show the member's registered Matrix ID prominently (registered box + notes), surface load errors, add 'Use my co-op account instead' clear button
This commit is contained in:
1 parent
1242024cc7
commit
88bda332c3
1 file changed
+40
-9
+40
-9
@@ -560,7 +560,14 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
|
||||
<div class="card">
|
||||
<h2>Matrix chat</h2>
|
||||
<p class="hint">You're invited to the co-op's Matrix space at your co-op account (<code id="local-mxid">@you:inference.coop</code>). Prefer to use an existing account on another server instead? Add it below (one account).</p>
|
||||
<p class="hint">You're invited to the co-op's Matrix space. Your registered Matrix ID:</p>
|
||||
<div class="key-reveal" id="mxid-registered">
|
||||
<div class="key-reveal-title">Registered Matrix ID</div>
|
||||
<code class="key-reveal-value" id="mxid-registered-value">checking…</code>
|
||||
<div class="key-reveal-name" id="mxid-registered-note"></div>
|
||||
<button class="ghost" id="mxid-clear" onclick="clearMxid()" style="display:none">Use my co-op account instead</button>
|
||||
</div>
|
||||
<p class="hint" id="mxid-custom-hint" style="display:none">Prefer a different account? Update it below (one account — it replaces the one above).</p>
|
||||
<div class="new-key">
|
||||
<input id="mxid-input" type="text" placeholder="e.g. @you:matrix.org" maxlength="255" />
|
||||
<button class="primary" id="mxid-btn" onclick="saveMxid()">Save</button>
|
||||
@@ -643,17 +650,37 @@ async function loadMxid() {
|
||||
const r = await fetch('/api/matrix-mxid');
|
||||
if (r.status === 401) return;
|
||||
const d = await r.json();
|
||||
if (d.error) return;
|
||||
if (d.local_mxid) $('local-mxid').textContent = d.local_mxid;
|
||||
if (d.matrix_mxid) {
|
||||
$('mxid-input').value = d.matrix_mxid;
|
||||
$('mxid-status').textContent = 'Using ' + d.matrix_mxid + ' for Matrix invites.';
|
||||
if (d.error) {
|
||||
$('mxid-registered-value').textContent = 'unavailable';
|
||||
$('mxid-status').textContent = 'Could not load your Matrix registration: ' + d.error;
|
||||
return;
|
||||
}
|
||||
const custom = (d.matrix_mxid || '').trim();
|
||||
const local = d.local_mxid || '';
|
||||
if (custom) {
|
||||
$('mxid-registered-value').textContent = custom;
|
||||
$('mxid-registered-note').textContent = 'External account — Matrix invites go here; your co-op account will not receive them.';
|
||||
$('mxid-input').value = custom;
|
||||
$('mxid-clear').style.display = '';
|
||||
$('mxid-custom-hint').style.display = '';
|
||||
} else if (local) {
|
||||
$('mxid-registered-value').textContent = local;
|
||||
$('mxid-registered-note').textContent = 'Your co-op account — invites go here.';
|
||||
} else {
|
||||
$('mxid-registered-value').textContent = 'not set yet — invites go to your co-op account once it exists';
|
||||
}
|
||||
} catch (e) {
|
||||
$('mxid-registered-value').textContent = 'unavailable';
|
||||
$('mxid-status').textContent = 'Could not load your Matrix registration: ' + e.message;
|
||||
}
|
||||
} catch (e) { /* non-critical */ }
|
||||
}
|
||||
|
||||
async function saveMxid() {
|
||||
const mxid = $('mxid-input').value.trim();
|
||||
async function clearMxid() {
|
||||
await saveMxid('');
|
||||
}
|
||||
|
||||
async function saveMxid(explicit) {
|
||||
const mxid = (explicit !== undefined ? explicit : $('mxid-input').value).trim();
|
||||
const btn = $('mxid-btn');
|
||||
btn.disabled = true;
|
||||
$('mxid-status').textContent = '';
|
||||
@@ -672,8 +699,12 @@ async function saveMxid() {
|
||||
$('mxid-status').className = 'hint ok';
|
||||
} else {
|
||||
$('mxid-status').textContent = 'Cleared — your co-op account will be used for Matrix.';
|
||||
$('mxid-status').className = 'hint ok';
|
||||
$('mxid-input').value = '';
|
||||
$('mxid-clear').style.display = 'none';
|
||||
}
|
||||
btn.disabled = false;
|
||||
await loadMxid();
|
||||
} catch (e) { $('mxid-status').textContent = 'Could not save: ' + e.message; }
|
||||
btn.disabled = false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user