ploxion-agora/app.blade.php

257 lines
35 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{-- ◇ AGORA — l'agora du Nexus (18.10.2026 ; docs/braindumps/2026-10-18-clickion-eons-et-agora.md). RS-7 : « un forum, des serveurs comme
Discord, des forums comme 4chan ou Reddit, la liberté au max ; ça run sur le Nexus, d'un zion à un xeroction » ; « anonyme, ou pas, chacun
choisit » ; « le vocal maintenant ». Serveur : AgoraController (/agora/…). Le vocal : un maillage WebRTC (chaque paire en direct),
signalé par le relais /rtc existant dans une salle dont le nom n'est donné qu'aux admis. Peu de texte, des glyphes, les boutons en bas. --}}
<style>
.ag { --a:#a597cf; --b:#79d9a2; --t:#ddd6ea; --m:#8a81a6; --s:#0f0b18; --bd:#272036; --bd2:#3a3050; min-height:100%; box-sizing:border-box; display:flex; flex-direction:column;
background:#07050c; color:var(--t); font:14px/1.45 -apple-system,system-ui,sans-serif; padding:12px 14px 0; }
.ag * { box-sizing:border-box; } .ag-corps { flex:1; }
.ag button { font:700 13px -apple-system,system-ui,sans-serif; color:var(--t); cursor:pointer; }
.ag-h { margin:6px 0 10px; font-size:16px; display:flex; align-items:baseline; gap:8px; } .ag-h small { margin-left:auto; font:600 11px ui-monospace,Menlo,monospace; color:var(--m); }
.ag-mono { font:600 11px ui-monospace,Menlo,monospace; color:var(--m); }
.ag-bt { min-height:40px; padding:0 12px; border-radius:12px; border:2px solid var(--bd2); background:#0a0712; }
.ag-bt.act, .ag-bt.on { border-color:var(--a); background:var(--a); color:#0d0a16; } .ag-bt.vert { border-color:var(--b); background:var(--b); color:#04120a; }
.ag-ligne { display:flex; align-items:center; gap:10px; width:100%; text-align:left; padding:10px 12px; margin-bottom:6px; border-radius:14px; border:1.5px solid var(--bd); background:var(--s); }
.ag-ligne i { font-style:normal; font-size:18px; color:var(--a); width:22px; text-align:center; } .ag-ligne div { flex:1; min-width:0; }
.ag-ligne b { display:block; } .ag-ligne small { display:block; color:var(--m); font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.ag-fil { display:flex; gap:10px; padding:10px 12px; margin-bottom:6px; border-radius:14px; border:1.5px solid var(--bd); background:var(--s); }
.ag-vote { display:flex; flex-direction:column; align-items:center; gap:2px; min-width:30px; } .ag-vote button { border:0; background:none; font-size:15px; color:var(--m); padding:2px; } .ag-vote button.on { color:var(--b); }
.ag-vote b { font:700 12px ui-monospace,Menlo,monospace; }
.ag-fil .txt { flex:1; min-width:0; } .ag-fil .txt b { cursor:pointer; } .ag-fil .txt p { margin:4px 0; white-space:pre-wrap; word-break:break-word; color:#cfc6e3; }
.ag-qui { font:600 11px ui-monospace,Menlo,monospace; color:var(--m); } .ag-qui .anon { color:#f0d36c; } .ag-qui .nom { color:var(--b); }
.ag-rep { margin-left:14px; padding-left:10px; border-left:2px solid var(--bd); }
.ag-msg { padding:6px 4px; border-bottom:1px solid #120d1c; } .ag-msg p { margin:2px 0 0; white-space:pre-wrap; word-break:break-word; }
.ag-flux { max-height:55vh; overflow:auto; padding-right:4px; }
.ag-ecrire { display:flex; flex-direction:column; gap:6px; margin:10px 0; } .ag-ecrire input, .ag-ecrire textarea { width:100%; min-height:42px; padding:9px 12px; border-radius:12px; border:2px solid var(--bd2); background:#0a0712; color:var(--t); font:15px -apple-system,system-ui,sans-serif; }
.ag-ecrire textarea { min-height:70px; resize:vertical; } .ag-ecrire .rang { display:flex; gap:6px; } .ag-ecrire .rang .ag-bt:last-child { margin-left:auto; }
.ag-actions { display:flex; flex-wrap:wrap; gap:6px; margin:6px 0 10px; } .ag-mini { border:0; background:none; color:var(--m); font:600 11px ui-monospace,Menlo,monospace; padding:2px 6px; }
.ag-vocal { padding:14px; border-radius:16px; border:2px solid var(--b); background:#0b1a12; text-align:center; } .ag-vocal .gens { display:flex; flex-wrap:wrap; gap:8px; justify-content:center; margin:12px 0; }
.ag-vocal .gens span { padding:8px 12px; border-radius:20px; border:1.5px solid #2c5a42; background:#10201a; }
.ag-nav { position:sticky; bottom:calc(env(safe-area-inset-bottom,0px) + 8px); margin-top:12px; display:flex; gap:5px; padding:6px; border-radius:20px; border:2px solid var(--bd2); background:#0a0712; }
.ag-nav button { flex:1; min-height:50px; border:0; border-radius:14px; background:none; color:var(--m); font:700 9px ui-monospace,Menlo,monospace; text-transform:uppercase; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; }
.ag-nav button i { font-style:normal; font-size:17px; } .ag-nav button.on { background:#151021; color:var(--t); box-shadow:inset 0 0 0 1.5px var(--b); }
.ag-md { margin:4px 0; color:#cfc6e3; word-break:break-word; line-height:1.45; } .ag-md-sp { height:.6em; } .ag-md code { font:13px ui-monospace,Menlo,monospace; background:#151021; padding:1px 5px; border-radius:6px; }
.ag-md a { color:var(--b); } .ag-md blockquote { margin:3px 0; padding-left:10px; border-left:3px solid var(--bd2); color:var(--m); } .ag-md ul, .ag-md ol { margin:3px 0; padding-left:22px; } .ag-md hr { border:0; border-top:1px solid var(--bd2); }
.ag-md-h1 { font:700 19px -apple-system,system-ui,sans-serif; color:var(--t); margin:6px 0 2px; } .ag-md-h2 { font:700 16px -apple-system,system-ui,sans-serif; color:var(--t); margin:5px 0 2px; } .ag-md-h3 { font:700 14px -apple-system,system-ui,sans-serif; color:var(--b); }
.ag-pre { margin:4px 0; padding:8px 10px; border-radius:10px; background:#0a0712; border:1px solid var(--bd2); font:12.5px ui-monospace,Menlo,monospace; white-space:pre-wrap; overflow:auto; }
.ag-img { display:block; max-width:100%; max-height:360px; margin:6px 0; border-radius:10px; border:1.5px solid var(--bd2); cursor:zoom-in; }
.ag-zoom { position:fixed; inset:0; z-index:99; background:rgba(5,4,10,.92); display:flex; align-items:center; justify-content:center; padding:16px; } .ag-zoom img { max-width:100%; max-height:100%; border-radius:10px; }
.ag-ecrire.survol textarea, .ag-ecrire.survol input { border-color:var(--b); box-shadow:0 0 0 3px rgba(121,217,162,.2); }
.ag-vide { padding:22px 8px; text-align:center; color:var(--m); }
</style>
<script>
(function () {
'use strict';
var ID = 'agora', G = { serveur: '◫', forum: '▤', tableau: '▦' }, NOM_T = { serveur: 'serveurs', forum: 'forums', tableau: 'tableaux' };
function esc(s) { return window.jOSb.esc(s); }
function csrf() { var m = document.querySelector('meta[name="csrf-token"]'); return m ? m.content : ''; }
function toast(m) { try { var T = (window.jOSb && jOSb.toast) || (window.jOS && jOS.toast); if (T) T(m); } catch (e) {} }
/* le .md (19.10, RS-7) : on échappe TOUT d'abord, puis on rallume un petit markdown sûr. Images : seulement celles de l'agora. */
function enLigne(t) {
var codes = [];
t = t.replace(/`([^`\n]+)`/g, function (_, x) { codes.push(x); return '\u0000' + (codes.length - 1) + '\u0000'; });
t = t.replace(/!\[([^\]\n]*)\]\((\/agora\/media\/[0-9a-f\/-]+\.(?:jpg|png|gif))\)/g, function (_, alt, u) { return '<img class="ag-img" loading="lazy" alt="' + alt + '" src="' + u + '" data-zoom="' + u + '">'; });
t = t.replace(/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer nofollow">$1</a>');
t = t.replace(/(^|[\s(])(https?:\/\/[^\s<)]+)/g, '$1<a href="$2" target="_blank" rel="noopener noreferrer nofollow">$2</a>');
t = t.replace(/\*\*([^*\n]+)\*\*/g, '<b>$1</b>').replace(/(^|[^*\w])\*([^*\n]+)\*/g, '$1<i>$2</i>').replace(/(^|\W)_([^_\n]+)_(?=\W|$)/g, '$1<i>$2</i>').replace(/~~([^~\n]+)~~/g, '<s>$1</s>');
return t.replace(/\u0000(\d+)\u0000/g, function (_, i) { return '<code>' + codes[+i] + '</code>'; });
}
function md(src) {
var blocs = String(src == null ? '' : src).split(/```/), out = '';
blocs.forEach(function (b, k) {
if (k % 2) { out += '<pre class="ag-pre">' + esc(b.replace(/^[^\n]*\n/, '')) + '</pre>'; return; }
var lignes = esc(b).split('\n'), liste = null;
lignes.forEach(function (l) {
var m;
if ((m = l.match(/^\s*([-*+]|\d+\.)\s+(.*)$/))) { var t = /\d/.test(m[1]) ? 'ol' : 'ul'; if (liste !== t) { if (liste) out += '</' + liste + '>'; out += '<' + t + '>'; liste = t; } out += '<li>' + enLigne(m[2]) + '</li>'; return; }
if (liste) { out += '</' + liste + '>'; liste = null; }
if ((m = l.match(/^(#{1,3})\s+(.*)$/))) { out += '<div class="ag-md-h' + m[1].length + '">' + enLigne(m[2]) + '</div>'; return; }
if ((m = l.match(/^&gt;\s?(.*)$/))) { out += '<blockquote>' + enLigne(m[1]) + '</blockquote>'; return; }
if (/^\s*(---|\*\*\*)\s*$/.test(l)) { out += '<hr>'; return; }
out += l.trim() ? '<div>' + enLigne(l) + '</div>' : '<div class="ag-md-sp"></div>';
});
if (liste) out += '</' + liste + '>';
});
return '<div class="ag-md">' + out + '</div>';
}
/* une image → /agora/media (réencodée côté serveur : plus d'EXIF ni de GPS) → ![](url) au curseur */
function televerser(fichier, champ, toastFn) {
if (!fichier || !/^image\/(jpeg|png|gif|webp)$/.test(fichier.type)) return toastFn('◇ image jpg/png/gif/webp');
if (fichier.size > 8 * 1024 * 1024) return toastFn('◇ 8 Mo max');
var fd = new FormData(); fd.append('image', fichier);
var marque = '![…](envoi' + Math.random().toString(36).slice(2, 6) + ')'; inserer(champ, marque);
return fetch('/agora/media', { method: 'POST', credentials: 'same-origin', headers: { Accept: 'application/json', 'X-CSRF-TOKEN': csrf(), 'X-Requested-With': 'XMLHttpRequest' }, body: fd })
.then(function (r) { return r.json().then(function (d) { if (!r.ok || !d.url) throw new Error(d.message || 'envoi raté'); return d; }); })
.then(function (d) { champ.value = champ.value.replace(marque, '![](' + d.url + ')'); }, function (e) { champ.value = champ.value.replace(marque, ''); toastFn('◇ ' + e.message); });
}
function inserer(champ, txt) { var a = champ.selectionStart == null ? champ.value.length : champ.selectionStart, b = champ.selectionEnd == null ? a : champ.selectionEnd, av = champ.value.slice(0, a); var pre = av && !/\n$/.test(av) && champ.tagName === 'TEXTAREA' ? '\n' : (av && !/\s$/.test(av) ? ' ' : ''); champ.value = av + pre + txt + champ.value.slice(b); var p = (av + pre + txt).length; try { champ.setSelectionRange(p, p); } catch (e) {} }
function api(url, methode, corps) {
return fetch(url, { method: methode || 'GET', credentials: 'same-origin', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf(), 'X-Requested-With': 'XMLHttpRequest' }, body: corps ? JSON.stringify(corps) : undefined })
.then(function (r) { return r.json().catch(function () { return {}; }).then(function (d) { if (!r.ok || d.ok === false) throw new Error(d.message || (r.status === 403 ? 'l\'agora est sur le Nexus : d\'un zion à un xeroction' : 'erreur ' + r.status)); return d; }); });
}
/* ── l'ANONYMAT TOTAL (RS-7 : « 100 % anonyme, même les modos ne peuvent pas lire ») : un secret qui ne quitte jamais cet appareil ;
l'étiquette d'un anonyme = sha256(secret : lieu) (6 car.), la preuve pour retirer son message = sha256(secret : del : lieu).
Le serveur ne reçoit que l'étiquette et l'empreinte de la preuve : il ne peut relier aucun anonyme à personne. ── */
function secret() { var k = 'xb:agora:secret', v = null; try { v = localStorage.getItem(k); } catch (e) {}
if (!v || !/^[0-9a-f]{64}$/.test(v)) { var a = new Uint8Array(32); crypto.getRandomValues(a); v = Array.prototype.map.call(a, function (x) { return ('0' + x.toString(16)).slice(-2); }).join(''); try { localStorage.setItem(k, v); } catch (e) {} } return v; }
function sha(t) { return crypto.subtle.digest('SHA-256', new TextEncoder().encode(t)).then(function (b) { return Array.prototype.map.call(new Uint8Array(b), function (x) { return ('0' + x.toString(16)).slice(-2); }).join(''); }); }
function monTag(ou) { return sha(secret() + ':' + ou).then(function (h) { return h.slice(0, 6); }); }
function maPreuve(ou) { return sha(secret() + ':del:' + ou); }
// les champs d'un message : anonyme → l'étiquette et la preuve calculées ICI
function signer(corps, anonyme, ou) { if (!anonyme) return Promise.resolve(corps); return Promise.all([monTag(ou), maPreuve(ou)]).then(function (x) { corps.tag = x[0]; corps.suppr = x[1]; return corps; }); }
var MOI_TAG = null, OP_TAG = null; // mes étiquettes dans le lieu affiché (calculées sur l'appareil)
function qui(a, op) { return a.anonyme ? '<span class="anon">◐ anonyme · ' + esc(a.tag) + (op ? ' · OP' : '') + (MOI_TAG && a.tag === MOI_TAG || (op && OP_TAG && a.tag === OP_TAG) ? ' (toi)' : '') + '</span>' : '<span class="nom"' + (a.ref ? ' data-profil="' + esc(a.ref) + '"' : '') + '>' + esc(a.glyphe || '') + ' ' + esc(a.nom) + '</span>'; } /* (19.10) un nom signé → sa carte (window.jOSProfil.carte) ; un anonyme, jamais */
function aMoi(m) { return m.moi || (m.auteur && m.auteur.anonyme && MOI_TAG && m.auteur.tag === MOI_TAG); }
function quand(t) { var s = Math.round((Date.now() - Date.parse(String(t).replace(' ', 'T') + (String(t).indexOf('Z') < 0 && String(t).indexOf('+') < 0 ? 'Z' : ''))) / 1000); if (!(s >= 0)) return ''; return s < 60 ? 'maintenant' : s < 3600 ? Math.round(s / 60) + ' min' : s < 86400 ? Math.round(s / 3600) + ' h' : Math.round(s / 86400) + ' j'; }
/* ── le vocal : un maillage WebRTC ; la paire où mon id est le plus grand fait l'offre (jamais deux offres croisées) ── */
function Vocal(salle, moi, surGens) {
moi = { id: moi.id + Math.random().toString(36).slice(2, 6), nom: moi.nom }; /* un id par appareil : deux appareils du même compte se parlent */
var attente = {}, pcs = {}, noms = {}, vus = {}, flux = null, depuis = 0, vivant = true, tP = 0, tH = 0, ice = [{ urls: 'stun:stun.l.google.com:19302' }], audios = {}, muet = false, bloque = false;
function envoyer(o) { o.from = moi.id; return fetch('/rtc/' + salle, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRF-TOKEN': csrf(), 'X-Requested-With': 'XMLHttpRequest' }, body: JSON.stringify({ sender: moi.id, payload: JSON.stringify(o) }) }).catch(function () {}); }
function gens() { var n = Date.now(); surGens(Object.keys(noms).filter(function (k) { return n - (vus[k] || 0) < 60000; }).map(function (k) { return { id: k, nom: noms[k], relie: !!(pcs[k] && pcs[k].connectionState === 'connected') }; }), bloque); }
function vider(id) { var p = pcs[id], l = attente[id] || []; delete attente[id]; l.forEach(function (c) { p.addIceCandidate(c).catch(function () {}); }); }
function fermer(id) { try { if (pcs[id]) pcs[id].close(); } catch (e) {} delete pcs[id]; delete attente[id]; if (audios[id]) { audios[id].remove(); delete audios[id]; } gens(); }
function pc(id) {
if (pcs[id]) return pcs[id];
var p = pcs[id] = new RTCPeerConnection({ iceServers: ice });
if (flux) flux.getTracks().forEach(function (t) { p.addTrack(t, flux); });
p.onicecandidate = function (e) { if (e.candidate) envoyer({ t: 'ice', to: id, c: e.candidate }); };
p.ontrack = function (e) { var a = audios[id]; if (!a) { a = audios[id] = document.createElement('audio'); a.autoplay = true; a.setAttribute('playsinline', ''); a.style.display = 'none'; document.body.appendChild(a); } a.srcObject = e.streams[0]; var pr = a.play && a.play(); if (pr && pr.catch) pr.catch(function () { bloque = true; gens(); }); };
p.onconnectionstatechange = function () { if (p.connectionState === 'failed' || p.connectionState === 'closed') fermer(id); gens(); };
return p;
}
function recevoir(o) {
if (!o || o.from === moi.id || (o.to && o.to !== moi.id)) return;
var de = o.from; vus[de] = Date.now(); if (o.nom) noms[de] = o.nom; else if (!noms[de]) noms[de] = '…';
if (o.t === 'hello') { if (!pcs[de] && moi.id < de && !o.re) envoyer({ t: 'hello', to: de, re: 1, nom: moi.nom }); if (!pcs[de] && moi.id > de) { var p = pc(de); p.createOffer().then(function (of) { return p.setLocalDescription(of); }).then(function () { envoyer({ t: 'offer', to: de, sdp: p.localDescription, nom: moi.nom }); }); } gens(); return; }
if (o.t === 'offer') { var q = pc(de); q.setRemoteDescription(o.sdp).then(function () { vider(de); return q.createAnswer(); }).then(function (an) { return q.setLocalDescription(an); }).then(function () { envoyer({ t: 'answer', to: de, sdp: q.localDescription, nom: moi.nom }); }); return; }
if (o.t === 'answer' && pcs[de]) { pcs[de].setRemoteDescription(o.sdp).then(function () { vider(de); }, function () {}); return; }
if (o.t === 'ice') { if (pcs[de] && pcs[de].remoteDescription) pcs[de].addIceCandidate(o.c).catch(function () {}); else (attente[de] = attente[de] || []).push(o.c); return; }
if (o.t === 'bye') { fermer(de); delete noms[de]; gens(); }
}
function sonder() {
if (!vivant) return;
fetch('/rtc/' + salle + '?since=' + depuis + '&me=' + encodeURIComponent(moi.id), { credentials: 'same-origin', headers: { Accept: 'application/json' } }).then(function (r) { return r.json(); }).then(function (d) {
(d.data || []).forEach(function (s) { depuis = Math.max(depuis, s.id); try { recevoir(JSON.parse(s.payload)); } catch (e) {} });
}).catch(function () {}).then(function () { if (vivant) tP = setTimeout(sonder, document.hidden ? 4000 : 1000); });
}
return {
entrer: function () {
return fetch('/rtc/ice', { credentials: 'same-origin' }).then(function (r) { return r.json(); }).then(function (d) { if (d && d.iceServers && d.iceServers.length) ice = d.iceServers; }).catch(function () {})
.then(function () { return navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true } }); })
.then(function (s) { flux = s; noms[moi.id] = moi.nom + ' (toi)'; vus[moi.id] = Date.now() + 1e12; envoyer({ t: 'hello', nom: moi.nom }); sonder(); tH = setInterval(function () { envoyer({ t: 'hello', nom: moi.nom }); }, 20000); gens(); });
},
son: function () { bloque = false; Object.keys(audios).forEach(function (k) { var pr = audios[k].play(); if (pr && pr.catch) pr.catch(function () {}); }); gens(); },
muet: function () { muet = !muet; if (flux) flux.getAudioTracks().forEach(function (t) { t.enabled = !muet; }); return muet; },
sortir: function () { vivant = false; clearTimeout(tP); clearInterval(tH); envoyer({ t: 'bye' }); Object.keys(pcs).forEach(fermer); if (flux) flux.getTracks().forEach(function (t) { t.stop(); }); flux = null; }
};
}
function mount(c) {
var vivant = true, vue = { t: 'accueil' }, data = null, anonyme = false, tri = null, tM = 0, depuisMsg = 0, msgs = [], vocal = null, gensVocal = [], estMuet = false, sonBloque = false;
function charge() {
clearTimeout(tM);
if (vue.t === 'accueil') return api('/agora/espaces').then(function (d) { data = d; dessiner(); });
if (vue.t === 'espace') return api('/agora/e/' + vue.slug + (tri ? '?tri=' + tri : '')).then(function (d) { data = d; if (d.espace.type === 'tableau' && vue.nouveau == null) anonyme = true; dessiner(); });
if (vue.t === 'fil') return api('/agora/fil/' + vue.id).then(function (d) { data = d; return Promise.all([monTag('fil' + vue.id), monTag('op:' + vue.slug + ':' + d.fil.titre)]); }).then(function (t) { MOI_TAG = t[0]; OP_TAG = t[1]; dessiner(); });
if (vue.t === 'salon') { depuisMsg = 0; msgs = []; return monTag('salon' + vue.id).then(function (t) { MOI_TAG = t; return sonderSalon(true); }); }
MOI_TAG = OP_TAG = null;
return Promise.resolve(dessiner());
}
function sonderSalon(premier) {
if (!vivant || vue.t !== 'salon') return Promise.resolve();
return api('/agora/salon/' + vue.id + (depuisMsg ? '?depuis=' + depuisMsg : '')).then(function (d) {
if (d.messages.length) { msgs = msgs.concat(d.messages).slice(-300); depuisMsg = msgs[msgs.length - 1].id; premier ? dessiner() : majFlux(); }
else if (premier) dessiner();
}).catch(function () {}).then(function () { if (vivant && vue.t === 'salon') tM = setTimeout(function () { sonderSalon(false); }, document.hidden ? 10000 : 3000); });
}
function majFlux() { var f = c.querySelector('[data-flux]'); if (!f) return dessiner(); var bas = f.scrollTop + f.clientHeight >= f.scrollHeight - 30; f.innerHTML = fluxHtml(); if (bas) f.scrollTop = f.scrollHeight; }
function fluxHtml() { return msgs.map(function (m) { return '<div class="ag-msg"><span class="ag-qui">' + qui(m.auteur) + ' · ' + quand(m.le) + '</span>' + (aMoi(m) ? ' <button class="ag-mini" data-suppr="msg:' + m.id + '">✕</button>' : '') + md(m.corps) + '</div>'; }).join('') || '<div class="ag-vide">◫ silence</div>'; }
function bascule() { return '<button class="ag-bt' + (anonyme ? ' on' : '') + '" data-anon title="anonyme">◐ ' + (anonyme ? 'anonyme' : 'mon nom') + '</button>'; }
function vueAccueil() {
if (!data) return '<div class="ag-vide">…</div>';
return ['serveur', 'forum', 'tableau'].map(function (t) { var es = data.espaces.filter(function (e) { return e.type === t; });
return '<div class="ag-h">' + G[t] + ' ' + NOM_T[t] + '<small>' + es.length + '</small></div>' + es.map(function (e) { return '<button class="ag-ligne" data-espace="' + esc(e.slug) + '"><i>' + G[e.type] + '</i><div><b>' + esc(e.nom) + '</b><small>' + esc(e.description || '') + '</small></div></button>'; }).join(''); }).join('')
+ (vue.creer ? '<div class="ag-ecrire"><input data-cnom placeholder="nom" maxlength="80"><input data-cdesc placeholder="description" maxlength="300"><div class="rang">' + ['serveur', 'forum', 'tableau'].map(function (t) { return '<button class="ag-bt' + (vue.creer === t ? ' on' : '') + '" data-ctype="' + t + '">' + G[t] + ' ' + t + '</button>'; }).join('') + '<button class="ag-bt vert" data-creer-ok>+</button></div></div>'
: '<div class="ag-actions"><button class="ag-bt" data-creer>+ créer un espace</button></div>');
}
function vueEspace() {
if (!data || !data.espace) return '<div class="ag-vide">…</div>';
var e = data.espace, h = '<button class="ag-bt" data-retour="accueil">←</button><div class="ag-h">' + G[e.type] + ' ' + esc(e.nom) + '<small>' + esc(e.description || '') + '</small></div>';
if (e.type === 'serveur') return h + data.salons.map(function (s) { return '<button class="ag-ligne" data-salon="' + s.id + '" data-salon-type="' + s.type + '" data-salon-nom="' + esc(s.nom) + '"><i>' + (s.type === 'vocal' ? '◉' : '#') + '</i><div><b>' + esc(s.nom) + '</b><small>' + (s.type === 'vocal' ? 'vocal' : 'texte') + '</small></div></button>'; }).join('')
+ (data.moderer ? '<div class="ag-actions"><button class="ag-bt" data-nsalon="texte">+ #</button><button class="ag-bt" data-nsalon="vocal">+ ◉</button></div>' : '');
var tris = e.type === 'forum' ? [['top', '▲ top'], ['neuf', '✦ neuf'], ['actif', '◷ actif']] : [['actif', '◷ actif'], ['neuf', '✦ neuf']];
return h + '<div class="ag-actions">' + tris.map(function (t) { return '<button class="ag-bt' + ((tri || (e.type === 'forum' ? 'top' : 'actif')) === t[0] ? ' on' : '') + '" data-tri="' + t[0] + '">' + t[1] + '</button>'; }).join('') + '</div>'
+ '<div class="ag-ecrire"><input data-titre placeholder="un nouveau fil" maxlength="200"><textarea data-corps placeholder="…" maxlength="20000"></textarea><div class="rang">' + bascule() + '<button class="ag-bt" data-img title="image">▣</button><button class="ag-bt act" data-poster>poster</button></div></div>'
+ (data.fils.length ? data.fils.map(function (f) { return '<div class="ag-fil"><div class="ag-vote"><b>' + f.score + '</b></div><div class="txt"><b data-fil="' + f.id + '">' + (f.epingle ? '⚑ ' : '') + esc(f.titre) + '</b><p>' + esc(f.extrait) + '</p><span class="ag-qui">' + qui(f.auteur) + ' · ' + quand(f.le) + ' · ↳ ' + f.reponses + '</span></div></div>'; }).join('') : '<div class="ag-vide">' + G[e.type] + ' le premier fil est à toi</div>');
}
function vote(cible, id, mon, score) { return '<div class="ag-vote"><button data-vote="' + cible + ':' + id + ':' + (mon === 1 ? 0 : 1) + '" class="' + (mon === 1 ? 'on' : '') + '">▲</button><b>' + score + '</b><button data-vote="' + cible + ':' + id + ':' + (mon === -1 ? 0 : -1) + '" class="' + (mon === -1 ? 'on' : '') + '">▼</button></div>'; }
function vueFil() {
if (!data || !data.fil) return '<div class="ag-vide">…</div>';
var f = data.fil, enf = {}; data.messages.forEach(function (m) { (enf[m.parent_id || 0] = enf[m.parent_id || 0] || []).push(m); });
var arbre = function (pid, prof) { return (enf[pid] || []).map(function (m) { return '<div class="' + (prof ? 'ag-rep' : '') + '"><div class="ag-fil">' + vote('msg', m.id, m.vote, m.score) + '<div class="txt"><span class="ag-qui">' + qui(m.auteur) + ' · ' + quand(m.le) + '</span>' + md(m.corps)
+ '<button class="ag-mini" data-repondre="' + m.id + '">↳ répondre</button>' + (aMoi(m) || data.moderer ? '<button class="ag-mini" data-suppr="msg:' + m.id + '">✕</button>' : '') + '<button class="ag-mini" data-signaler="msg:' + m.id + '">⚐</button></div></div>' + (prof < 4 ? arbre(m.id, prof + 1) : '') + '</div>'; }).join(''); };
return '<button class="ag-bt" data-retour="espace">←</button><div class="ag-fil">' + vote('fil', f.id, f.vote, f.score) + '<div class="txt"><b>' + esc(f.titre) + '</b>' + md(f.corps || '') + '<span class="ag-qui">' + qui(f.auteur, true) + ' · ' + quand(f.le) + '</span>'
+ (f.moi || (f.auteur.anonyme && OP_TAG && f.auteur.tag === OP_TAG) || data.moderer ? ' <button class="ag-mini" data-suppr="fil:' + f.id + '">✕</button>' : '') + '<button class="ag-mini" data-signaler="fil:' + f.id + '">⚐</button></div></div>'
+ '<div class="ag-ecrire"><textarea data-rep placeholder="' + (vue.parent ? '↳ réponse' : 'répondre') + '" maxlength="20000"></textarea><div class="rang">' + bascule() + '<button class="ag-bt" data-img title="image">▣</button>' + (vue.parent ? '<button class="ag-bt" data-repondre="">✕ ↳</button>' : '') + '<button class="ag-bt act" data-envoyer-rep>↳</button></div></div>'
+ arbre(0, 0);
}
function vueSalon() {
if (vue.type === 'vocal') return '<button class="ag-bt" data-retour="espace">←</button><div class="ag-h">◉ ' + esc(vue.nom) + '</div><div class="ag-vocal">'
+ (vocal ? '<div class="gens">' + (gensVocal.map(function (g) { return '<span>' + (g.relie ? '◉ ' : '○ ') + esc(g.nom) + '</span>'; }).join('') || '<span>…</span>') + '</div>' + (sonBloque ? '<button class="ag-bt vert" data-son>▶ activer le son</button>' : '') + '<div class="ag-actions" style="justify-content:center"><button class="ag-bt' + (estMuet ? ' on' : '') + '" data-muet>' + (estMuet ? '⊘ muet' : '◉ micro') + '</button><button class="ag-bt act" data-quitter>quitter</button></div>'
: '<p class="ag-mono">le son passe en direct entre vous</p><button class="ag-bt vert" data-rejoindre>◉ rejoindre</button>') + '</div>';
return '<button class="ag-bt" data-retour="espace">←</button><div class="ag-h"># ' + esc(vue.nom) + '</div><div class="ag-flux" data-flux>' + fluxHtml() + '</div>'
+ '<div class="ag-ecrire"><input data-msg placeholder="message" maxlength="4000" enterkeyhint="send"><div class="rang">' + bascule() + '<button class="ag-bt" data-img title="image">▣</button><button class="ag-bt act" data-envoyer>↑</button></div></div>';
}
function dessiner() {
if (!vivant) return;
c.innerHTML = '<div class="ag"><div class="ag-corps">' + (vue.t === 'accueil' ? vueAccueil() : vue.t === 'espace' ? vueEspace() : vue.t === 'fil' ? vueFil() : vueSalon()) + '</div>'
+ '<nav class="ag-nav"><button data-retour="accueil" class="' + (vue.t === 'accueil' ? 'on' : '') + '"><i>◇</i>agora</button>' + (vue.slug ? '<button data-retour="espace" class="' + (vue.t !== 'accueil' ? 'on' : '') + '"><i>' + (G[vue.type0] || '▤') + '</i>' + esc(vue.nomEspace || '') + '</button>' : '') + '</nav></div>';
if (vue.t === 'salon') { var f = c.querySelector('[data-flux]'); if (f) f.scrollTop = f.scrollHeight; }
}
function quitterVocal() { if (vocal) { vocal.sortir(); vocal = null; gensVocal = []; } }
function aller(v) { if (vue.t === 'salon' && vue.type === 'vocal' && v.t !== 'salon') quitterVocal(); vue = v; charge().catch(function (e) { c.innerHTML = '<div class="ag"><div class="ag-vide">◇ ' + esc(e.message) + '</div></div>'; }); }
c.addEventListener('click', function (ev) {
var zm = ev.target.closest('[data-zoom]'); if (zm) { var z = document.createElement('div'); z.className = 'ag-zoom'; z.innerHTML = '<img alt="" src="' + esc(zm.dataset.zoom) + '">'; z.onclick = function () { z.remove(); }; document.body.appendChild(z); return; }
if (ev.target.closest('.ag-md a')) return;
var b = ev.target.closest('button,[data-fil]'); if (!b || !vivant) return; var d = b.dataset;
if (d.retour) { if (d.retour === 'accueil') return aller({ t: 'accueil' }); return aller({ t: 'espace', slug: vue.slug, type0: vue.type0, nomEspace: vue.nomEspace }); }
if (d.espace) { var e = (data.espaces || []).filter(function (x) { return x.slug === d.espace; })[0]; tri = null; anonyme = false; return aller({ t: 'espace', slug: d.espace, type0: e ? e.type : '', nomEspace: e ? e.nom : '' }); }
if (d.fil) return aller({ t: 'fil', id: +d.fil, slug: vue.slug, type0: vue.type0, nomEspace: vue.nomEspace });
if (d.salon) return aller({ t: 'salon', id: +d.salon, type: d.salonType, nom: d.salonNom, slug: vue.slug, type0: vue.type0, nomEspace: vue.nomEspace });
if (d.anon != null) { anonyme = !anonyme; b.classList.toggle('on', anonyme); b.textContent = '◐ ' + (anonyme ? 'anonyme' : 'mon nom'); return; }
if (d.tri) { tri = d.tri; return charge(); }
if (d.creer != null) { vue.creer = 'forum'; return dessiner(); }
if (d.ctype) { vue.creer = d.ctype; c.querySelectorAll('[data-ctype]').forEach(function (x) { x.classList.toggle('on', x === b); }); return; }
if (d.creerOk != null) { var n = c.querySelector('[data-cnom]').value.trim(); if (!n) return; api('/agora/espaces', 'POST', { type: vue.creer, nom: n, description: c.querySelector('[data-cdesc]').value.trim() || null }).then(function (r) { aller({ t: 'espace', slug: r.slug, type0: vue.creer, nomEspace: n }); }, function (er) { toast('◇ ' + er.message); }); return; }
if (d.poster != null) { var ti = c.querySelector('[data-titre]').value.trim(); if (!ti) return; signer({ titre: ti, corps: c.querySelector('[data-corps]').value.trim() || null, anonyme: anonyme }, anonyme, 'op:' + vue.slug + ':' + ti).then(function (cp) { return api('/agora/e/' + vue.slug + '/fils', 'POST', cp); }).then(charge, function (er) { toast('◇ ' + er.message); }); return; }
if (d.vote) { var p = d.vote.split(':'); api('/agora/vote', 'POST', { cible: p[0], id: +p[1], valeur: +p[2] }).then(charge); return; }
if (d.repondre != null) { vue.parent = d.repondre ? +d.repondre : null; dessiner(); var t = c.querySelector('[data-rep]'); if (t) t.focus(); return; }
if (d.envoyerRep != null) { var tx = c.querySelector('[data-rep]').value.trim(); if (!tx) return; signer({ corps: tx, anonyme: anonyme, parent_id: vue.parent || null }, anonyme, 'fil' + vue.id).then(function (cp) { return api('/agora/fil/' + vue.id + '/repondre', 'POST', cp); }).then(function () { vue.parent = null; charge(); }, function (er) { toast('◇ ' + er.message); }); return; }
if (d.envoyer != null) return envoyerMsg();
if (d.suppr) { var s = d.suppr.split(':'), lieu = s[0] === 'fil' ? 'op:' + vue.slug + ':' + (data.fil ? data.fil.titre : '') : (vue.t === 'salon' ? 'salon' : 'fil') + vue.id; maPreuve(lieu).then(function (pv) { return api('/agora/' + s[0] + '/' + s[1], 'DELETE', { suppr: pv }); }).then(function () { if (s[0] === 'fil') aller({ t: 'espace', slug: vue.slug, type0: vue.type0, nomEspace: vue.nomEspace }); else if (vue.t === 'salon') { msgs = msgs.filter(function (m) { return m.id !== +s[1]; }); majFlux(); } else charge(); }); return; }
if (d.signaler) { var g = d.signaler.split(':'); api('/agora/signaler', 'POST', { cible: g[0], id: +g[1] }).then(function () { toast('⚐ signalé'); }); return; }
if (d.nsalon) { var nm = window.prompt ? prompt('nom du salon') : null; if (nm) api('/agora/e/' + vue.slug + '/salons', 'POST', { nom: nm, type: d.nsalon }).then(charge); return; }
if (d.rejoindre != null) { api('/agora/salon/' + vue.id + '/vocal').then(function (r) { vocal = Vocal(r.salle, r.moi, function (g, bl) { gensVocal = g; sonBloque = !!bl; if (vue.t === 'salon') dessiner(); }); return vocal.entrer(); }).then(dessiner, function (er) { quitterVocal(); toast('◉ ' + (er && er.name === 'NotAllowedError' ? 'micro refusé' : (er.message || 'vocal indisponible'))); dessiner(); }); return; }
if (d.img != null) { var zc = b.closest('.ag-ecrire').querySelector('textarea,input[data-msg]'), pk = document.createElement('input'); pk.type = 'file'; pk.accept = 'image/*'; pk.multiple = true; pk.onchange = function () { Array.prototype.forEach.call(pk.files, function (f) { televerser(f, zc, toast); }); }; pk.click(); return; }
if (d.son != null) { if (vocal) vocal.son(); return; }
if (d.muet != null) { estMuet = vocal ? vocal.muet() : false; return dessiner(); }
if (d.quitter != null) { quitterVocal(); return dessiner(); }
});
function envoyerMsg() { var i = c.querySelector('[data-msg]'), tx = i && i.value.trim(); if (!tx) return; i.value = ''; signer({ corps: tx, anonyme: anonyme }, anonyme, 'salon' + vue.id).then(function (cp) { return api('/agora/salon/' + vue.id, 'POST', cp); }).then(function () { clearTimeout(tM); sonderSalon(false); }, function (er) { toast('◇ ' + er.message); }); }
function champDe(t) { var e = t && t.closest && t.closest('.ag-ecrire'); return e ? e.querySelector('textarea,input[data-msg]') : null; }
c.addEventListener('dragover', function (ev) { var e = ev.target.closest && ev.target.closest('.ag-ecrire'); if (!e) return; ev.preventDefault(); e.classList.add('survol'); });
c.addEventListener('dragleave', function (ev) { var e = ev.target.closest && ev.target.closest('.ag-ecrire'); if (e) e.classList.remove('survol'); });
c.addEventListener('drop', function (ev) { var ch = champDe(ev.target); if (!ch) return; ev.preventDefault(); ch.closest('.ag-ecrire').classList.remove('survol'); Array.prototype.forEach.call((ev.dataTransfer && ev.dataTransfer.files) || [], function (f) { televerser(f, ch, toast); }); });
c.addEventListener('paste', function (ev) { var ch = champDe(ev.target); if (!ch || !ev.clipboardData) return; var fs = Array.prototype.filter.call(ev.clipboardData.files || [], function (f) { return /^image\//.test(f.type); }); if (!fs.length) return; ev.preventDefault(); fs.forEach(function (f) { televerser(f, ch, toast); }); });
c.addEventListener('keydown', function (ev) { if (ev.key === 'Enter' && ev.target.dataset && ev.target.dataset.msg != null) { ev.preventDefault(); envoyerMsg(); } });
aller({ t: 'accueil' });
return { unmount: function () { vivant = false; clearTimeout(tM); quitterVocal(); c.innerHTML = ''; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps[ID] = { manifest: { id: ID, name: 'Agora', icon: '◇' }, mount: mount };
})();
</script>