Files
stack/packages/webui/src/public/user.js
T

25 lines
1.4 KiB
JavaScript

/* FED R6 (#1800): a granted user's page. Projects, threads and messages through chat.js; the
broker decides what this user reads and sends. No owner control is on this page. */
(() => {
'use strict';
const $ = id => document.getElementById(id);
let canSend = false, ready = false;
const route = () => {
const path = location.hash.slice(1).split('?')[0];
return path.startsWith('/chat') || path.startsWith('/projects') ? path : '/projects';
};
function show(navigated) {
if (ready && window.MosaicChat) void window.MosaicChat.render({ path: route(), container: $('chat'), canSend, user: true, navigated });
}
document.addEventListener('mosaic-signed-out', () => { $('signed-out').hidden = false; $('sign-out').hidden = true; });
window.addEventListener('hashchange', () => show(true));
setInterval(() => { if (!document.hidden) show(false); }, 5000);
fetch('/api/config', { cache: 'no-store', redirect: 'manual' }).then(async res => {
if (res.type === 'opaqueredirect' || res.status === 401) { document.dispatchEvent(new Event('mosaic-signed-out')); return; }
const config = await res.json();
canSend = config.send === true;
window.MosaicFederation?.render(config.federation, $('federation'));
ready = true; show(true);
}).catch(() => { $('chat').textContent = 'The Console could not be read. Refresh to try again.'; });
})();