diff --git a/app/main.py b/app/main.py
index 5570900..d995417 100644
--- a/app/main.py
+++ b/app/main.py
@@ -560,19 +560,21 @@ PAGE_HTML = """
Matrix chat
-
You're invited to the co-op's Matrix space. Your registered Matrix ID:
+
We use the Matrix chat protocol to collaborate. You can access our space with an inference.coop account or an account hosted elsewhere.
+
Current Matrix ID:
-
Registered Matrix ID
checking…
-
-
+
+
+
+
+
+
+
+
+
+
-
Prefer a different account? Update it below (one account — it replaces the one above).
-
-
-
-
-
@@ -645,6 +647,11 @@ async function load() {
}
}
+let mxidLocal = ''; // @username:inference.coop, resolved by the portal
+let mxidCurrent = ''; // what is registered right now (external or local)
+
+function mxidValid(v) { return /^@[^\\s:]+:[^\\s]+\\.[^\\s]+$/.test(v); }
+
async function loadMxid() {
try {
const r = await fetch('/api/matrix-mxid');
@@ -652,38 +659,62 @@ async function loadMxid() {
const d = await r.json();
if (d.error) {
$('mxid-registered-value').textContent = 'unavailable';
- $('mxid-status').textContent = 'Could not load your Matrix registration: ' + d.error;
+ $('mxid-status').textContent = 'Could not load: ' + 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.';
+ mxidLocal = (d.local_mxid || '').trim();
+ mxidCurrent = (d.matrix_mxid || '').trim() || mxidLocal;
+ $('mxid-registered-value').textContent = mxidCurrent || 'pending — will use the inference.coop account once it exists';
+ const useLocalBtn = $('mxid-use-local');
+ if (mxidCurrent && mxidLocal && mxidCurrent !== mxidLocal) {
+ useLocalBtn.textContent = 'Use ' + mxidLocal;
+ useLocalBtn.style.display = '';
} else {
- $('mxid-registered-value').textContent = 'not set yet — invites go to your co-op account once it exists';
+ useLocalBtn.style.display = 'none';
}
} catch (e) {
$('mxid-registered-value').textContent = 'unavailable';
- $('mxid-status').textContent = 'Could not load your Matrix registration: ' + e.message;
+ $('mxid-status').textContent = 'Could not load: ' + e.message;
}
}
-async function clearMxid() {
- await saveMxid('');
+function showExternalField() {
+ $('mxid-actions').style.display = 'none';
+ $('mxid-field-row').style.display = '';
+ $('mxid-input').value = (mxidCurrent && mxidCurrent !== mxidLocal) ? mxidCurrent : '';
+ $('mxid-status').textContent = '';
+ $('mxid-input').focus();
}
-async function saveMxid(explicit) {
- const mxid = (explicit !== undefined ? explicit : $('mxid-input').value).trim();
+function hideExternalField() {
+ $('mxid-field-row').style.display = 'none';
+ $('mxid-actions').style.display = '';
+ $('mxid-status').textContent = '';
+}
+
+async function useLocalMxid() {
+ const btn = $('mxid-use-local');
+ btn.disabled = true;
+ try {
+ const r = await fetch('/api/matrix-mxid', {
+ method: 'POST', headers: {'Content-Type': 'application/json'},
+ body: JSON.stringify({ matrix_mxid: '' })
+ });
+ const d = await r.json();
+ if (d.error) { $('mxid-status').textContent = d.error; }
+ else { $('mxid-status').textContent = ''; await loadMxid(); }
+ } catch (e) { $('mxid-status').textContent = 'Could not switch: ' + e.message; }
+ btn.disabled = false;
+}
+
+async function saveMxid() {
+ const mxid = $('mxid-input').value.trim();
+ if (!mxidValid(mxid)) {
+ $('mxid-status').textContent = 'Enter a Matrix ID like @username:server.org';
+ return;
+ }
const btn = $('mxid-btn');
btn.disabled = true;
- $('mxid-status').textContent = '';
try {
const r = await fetch('/api/matrix-mxid', {
method: 'POST', headers: {'Content-Type': 'application/json'},
@@ -691,20 +722,13 @@ async function saveMxid(explicit) {
});
const d = await r.json();
if (d.error) { $('mxid-status').textContent = d.error; }
- else if (mxid) {
- const joined = d.invite_sent === false;
- $('mxid-status').innerHTML = 'Saved. An invite to the co-op Matrix space is on its way to