Neuplan C11: - Vierte Chat-Stufe „Langsam“ (ein Beitrag je 10 s, Team frei); im Feld steht es, bevor jemand tippt. schreibGrund behandelte jede unbekannte Stufe wie „zu“ – „langsam“ ist ausdrücklich offen. - „Verwarnen …“ im Namensmenü (Team): ein ruhiger Hinweis „vom Team“ nur bei der Person, ohne Namen des Verwarnenden. - „Wache“ im Chatkopf: Regeln des Abends (Links nur vom Team, Großbuchstaben-Bremse schreibt leiser statt abzulehnen, neue Zugänge warten 2 min, Wortfilter mit Wortgrenzen und eingestreuten Zeichen) und das Protokoll der Sendung (Aktion, wer, wann; Wörter nur als Zahl). - Alles am Server (workspace-chatwache.js), neue Tabelle reaktion_chatregeln. - Nebenbei: Tonhinweis lag am Handy auf dem YouTube-Bild (jetzt darunter, Gegenprobe rot), Chat-Stufen am Handy 33 → 44 px, die Chatspalte zählt sichtbare Teile vor der Liste statt je eine Rasterregel. - pruef-reaktion 1085/0 (Abschnitt 32), neue Dauerprüfung pruef-chatwache-blick 23/0, Breiten, mess-quer, Handy grün. Co-Authored-By: Claude Opus 5.5 <[email protected]>
268 lines
12 KiB
JavaScript
268 lines
12 KiB
JavaScript
/* =====================================================================
|
||
DIE CHAT-WACHE IM SAAL (04.11.2026, Neuplan C11 – Server:
|
||
workspace-chatwache.js)
|
||
|
||
· „Langsam“ steht als vierte Stufe neben Offen/Team/Zu (die Knöpfe
|
||
bindet reaktion.js selbst). Wer langsam schreiben muss, liest es im
|
||
Feld, bevor er tippt.
|
||
· „Verwarnen …“ im Menü am Namen (Team und Regie): ein Satz an genau
|
||
diese Person. Sie sieht ihn ruhig oben im Chat, mit „Verstanden“.
|
||
· „Wache“ im Chatkopf (Team und Regie): die Regeln des Abends – die
|
||
Regie schaltet sie, das Team sieht sie – und das Protokoll dieser
|
||
Sendung (Aktion, wer, wann).
|
||
|
||
Eigene Datei wegen der 200-KB-Grenze von reaktion.js; liest den Stand
|
||
über `saal:lage`/`saal:strom`, hängt sich über `saal:modmenue` ins Menü.
|
||
===================================================================== */
|
||
(() => {
|
||
'use strict';
|
||
const $ = (id) => document.getElementById(id);
|
||
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
|
||
const satz = (f, ersatz) => (window.sagWas ? window.sagWas(f, ersatz) : ersatz);
|
||
let lage = null;
|
||
let regeln = null;
|
||
|
||
async function holen(pfad, art = 'GET', rumpf) {
|
||
const a = await fetch(pfad, {
|
||
method: art, credentials: 'same-origin', cache: 'no-store',
|
||
headers: rumpf ? { 'Content-Type': 'application/json' } : undefined,
|
||
body: rumpf ? JSON.stringify(rumpf) : undefined,
|
||
});
|
||
const j = await a.json().catch(() => null);
|
||
return { ok: a.ok, j };
|
||
}
|
||
|
||
/* ---------------------------------------------------- Langsam im Feld */
|
||
function feldSagen() {
|
||
const feld = $('chat-feld');
|
||
if (!feld || !lage) return;
|
||
const langsam = lage.chat_modus === 'langsam';
|
||
$('schiene')?.toggleAttribute('data-langsam', langsam);
|
||
if (langsam && lage.ich?.darf_schreiben !== false && !lage.ich?.moderiert) {
|
||
feld.placeholder = 'Langsamer Chat · ein Beitrag je 10 s';
|
||
feld.setAttribute('aria-label', 'Deine Nachricht – langsamer Chat, ein Beitrag je 10 Sekunden');
|
||
}
|
||
}
|
||
|
||
/* ---------------------------------------------------- Verwarnen */
|
||
window.addEventListener('saal:modmenue', (e) => {
|
||
const { b, tun } = e.detail || {};
|
||
if (!b?.person_id || typeof tun !== 'function') return;
|
||
tun('Verwarnen …', async () => {
|
||
const antwort = window.frageNach ? await window.frageNach({
|
||
titel: `${b.name} verwarnen?`,
|
||
was: 'Nur diese Person liest den Satz – im Saal sieht ihn niemand.',
|
||
grund: 'Was soll sie lesen? (freiwillig)',
|
||
grundPflicht: false,
|
||
platzhalter: 'z. B. bitte keine Links / bitte freundlich bleiben',
|
||
ja: 'Verwarnen', nein: 'Doch nicht',
|
||
}) : null;
|
||
if (!antwort) return;
|
||
const r = await holen('/workspace/api/reaktion/verwarnen', 'POST', { person_id: b.person_id, grund: (antwort && antwort.grund) || '' });
|
||
wacheSagen(r.ok ? `${b.name} ist verwarnt.` : satz(r.j?.fehler, 'Das ging gerade nicht.'));
|
||
});
|
||
});
|
||
|
||
/* Die Verwarnung beim Empfänger: ruhig, oben im Chat, bis „Verstanden“. */
|
||
function verwarnungZeigen(grund) {
|
||
const kopf = document.querySelector('#schiene .schiene__kopf');
|
||
if (!kopf) return;
|
||
$('cw-verwarnt')?.remove();
|
||
const k = el('section', 'cw-verwarnt');
|
||
k.id = 'cw-verwarnt';
|
||
k.setAttribute('role', 'alert');
|
||
k.append(el('strong', 'cw-verwarnt__titel', 'Hinweis vom Team'), el('p', 'cw-verwarnt__text', grund));
|
||
const ok = el('button', 'bs-knopf cw-verwarnt__ok', 'Verstanden');
|
||
ok.type = 'button';
|
||
ok.addEventListener('click', () => { k.remove(); $('schiene')?.removeAttribute('data-verwarnt'); });
|
||
k.append(ok);
|
||
kopf.after(k);
|
||
$('schiene')?.setAttribute('data-verwarnt', 'ja');
|
||
ok.focus({ preventScroll: true });
|
||
}
|
||
|
||
/* ---------------------------------------------------- Die Wache */
|
||
/* Der Knopf steht fest im HTML (die Befehlssuche springt auf ihn); hier
|
||
wird er nur verdrahtet – einmal. */
|
||
function knopfBauen() {
|
||
const k = $('cw-knopf');
|
||
if (!k || k.dataset.gebunden) return k;
|
||
k.dataset.gebunden = 'ja';
|
||
k.addEventListener('click', () => (k.getAttribute('aria-expanded') === 'true' ? tafelZu() : tafelAuf()));
|
||
return k;
|
||
}
|
||
|
||
const SCHALTER = [
|
||
['links_nur_team', 'Links nur vom Team', 'Adressen schickt heute nur das Team.'],
|
||
['caps_bremse', 'Großbuchstaben-Bremse', 'Wer schreit, wird leiser geschrieben – der Inhalt bleibt.'],
|
||
['neue_konten', 'Neue Zugänge warten 2 Minuten', 'Erst zwei Minuten nach dem Anlegen schreiben.'],
|
||
];
|
||
|
||
function tafelBauen() {
|
||
let t = $('cw-tafel');
|
||
if (t) return t;
|
||
const kopf = document.querySelector('#schiene .schiene__kopf');
|
||
t = el('section', 'cw-tafel');
|
||
t.id = 'cw-tafel';
|
||
t.hidden = true;
|
||
t.setAttribute('aria-labelledby', 'cw-titel');
|
||
const titel = el('h3', 'cw-titel', 'Chat-Wache');
|
||
titel.id = 'cw-titel';
|
||
const zu = el('button', 'cw-zu', '×');
|
||
zu.type = 'button';
|
||
zu.setAttribute('aria-label', 'Chat-Wache schließen');
|
||
zu.addEventListener('click', tafelZu);
|
||
const kopfzeile = el('div', 'cw-kopfzeile');
|
||
kopfzeile.append(titel, zu);
|
||
|
||
const r = el('fieldset', 'cw-regeln');
|
||
r.append(el('legend', 'cw-legende', 'Regeln des Abends'));
|
||
for (const [key, wort, hilfe] of SCHALTER) {
|
||
const z = el('label', 'cw-schalter');
|
||
const c = el('input');
|
||
c.type = 'checkbox';
|
||
c.id = `cw-${key}`;
|
||
c.dataset.regel = key;
|
||
c.addEventListener('change', () => speichern({ [key]: c.checked }));
|
||
const txt = el('span', 'cw-schalter__text');
|
||
txt.append(el('strong', '', wort), el('span', 'cw-hilfe', hilfe));
|
||
z.append(c, txt);
|
||
r.append(z);
|
||
}
|
||
const wl = el('label', 'cw-woerter');
|
||
wl.append(el('strong', '', 'Wortfilter'), el('span', 'cw-hilfe', 'Ein Wort je Zeile. Wer es benutzt, bekommt den Beitrag zurück – die Regie nicht.'));
|
||
const ta = el('textarea', 'cw-woerter__feld');
|
||
ta.id = 'cw-woerter';
|
||
ta.rows = 3;
|
||
ta.maxLength = 2500;
|
||
const sw = el('button', 'btn btn-klein btn-sekundaer cw-woerter__speichern', 'Wörter speichern');
|
||
sw.type = 'button';
|
||
sw.id = 'cw-woerter-speichern';
|
||
sw.addEventListener('click', () => speichern({ woerter: ta.value.split(/[\n,]/).map((w) => w.trim()).filter(Boolean) }));
|
||
wl.append(ta);
|
||
r.append(wl, sw);
|
||
|
||
const p = el('div', 'cw-protokoll');
|
||
p.append(el('strong', 'cw-legende', 'Protokoll dieser Sendung'));
|
||
const ol = el('ol', 'cw-protokoll__liste');
|
||
ol.id = 'cw-protokoll';
|
||
p.append(ol);
|
||
const sagt = el('p', 'cw-sagt');
|
||
sagt.id = 'cw-sagt';
|
||
sagt.setAttribute('role', 'status');
|
||
t.append(kopfzeile, r, sagt, p);
|
||
t.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.stopPropagation(); tafelZu(); $('cw-knopf')?.focus(); } });
|
||
/* ALS FLÄCHE ÜBER DER LISTE, NICHT ALS ZEILE DAVOR (gemessen 04.11.2026):
|
||
Bei offener Regie ist die Chatspalte am Rechner kurz, und als Zeile
|
||
bekam die Tafel nur einen Streifen – sichtbar war allein „Wörter
|
||
speichern“. Sie liegt jetzt unter dem Kopf über Liste und Feld und
|
||
rollt in sich; über dem Video liegt sie nie (sie lebt in der Spalte). */
|
||
($('schiene') || document.body).append(t);
|
||
/* Erst jetzt gibt es, worauf der Knopf zeigt. */
|
||
$('cw-knopf')?.setAttribute('aria-controls', 'cw-tafel');
|
||
void kopf;
|
||
return t;
|
||
}
|
||
|
||
function wacheSagen(text) {
|
||
const s = $('cw-sagt');
|
||
if (s && !$('cw-tafel').hidden) {
|
||
s.textContent = text;
|
||
clearTimeout(wacheSagen.uhr);
|
||
wacheSagen.uhr = setTimeout(() => { s.textContent = ''; }, 5000);
|
||
} else if (text) {
|
||
/* Tafel zu: dieselbe Fläche wie die anderen kurzen Meldungen im Saal. */
|
||
const f = $('fehler');
|
||
if (f) { f.textContent = text; f.dataset.art = 'kurz'; f.classList.remove('fehler'); f.hidden = false; setTimeout(() => { f.hidden = true; }, 4000); }
|
||
}
|
||
}
|
||
|
||
function regelnZeichnen() {
|
||
const t = $('cw-tafel');
|
||
if (!t || !regeln) return;
|
||
const regie = !!lage?.ich?.host;
|
||
for (const [key] of SCHALTER) {
|
||
const c = $(`cw-${key}`);
|
||
c.checked = !!regeln[key];
|
||
c.disabled = !regie;
|
||
}
|
||
const ta = $('cw-woerter');
|
||
if (document.activeElement !== ta) ta.value = (regeln.woerter || []).join('\n');
|
||
ta.readOnly = !regie;
|
||
$('cw-woerter-speichern').hidden = !regie;
|
||
t.dataset.regie = regie ? 'ja' : 'nein';
|
||
}
|
||
|
||
async function speichern(teil) {
|
||
if (!lage?.ich?.host) return;
|
||
const r = await holen('/workspace/api/reaktion/chatregeln', 'PUT', teil);
|
||
if (r.ok) { regeln = r.j; regelnZeichnen(); wacheSagen('Gespeichert.'); protokollHolen(); }
|
||
else { wacheSagen(satz(r.j?.fehler, 'Das ging gerade nicht.')); regelnHolen(); }
|
||
}
|
||
async function regelnHolen() {
|
||
const r = await holen('/workspace/api/reaktion/chatregeln');
|
||
if (r.ok) { regeln = r.j; regelnZeichnen(); }
|
||
}
|
||
async function protokollHolen() {
|
||
const ol = $('cw-protokoll');
|
||
if (!ol) return;
|
||
const r = await holen('/workspace/api/reaktion/chatwache/protokoll');
|
||
ol.textContent = '';
|
||
const l = r.ok ? (r.j?.eintraege || []) : [];
|
||
if (!r.ok) ol.append(el('li', 'cw-leer', 'Das Protokoll ließ sich gerade nicht laden.'));
|
||
else if (!l.length) ol.append(el('li', 'cw-leer', 'In dieser Sendung ist noch nichts passiert.'));
|
||
for (const e of l) {
|
||
const li = el('li', 'cw-eintrag');
|
||
const zeit = new Date(e.zeit);
|
||
const uhr = Number.isFinite(zeit.getTime()) ? zeit.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' }) : '';
|
||
li.append(el('span', 'cw-eintrag__zeit', uhr), el('strong', '', e.wer), document.createTextNode(` · ${e.was}`));
|
||
if (e.detail) li.append(el('span', 'cw-eintrag__detail', ` · ${e.detail}`));
|
||
ol.append(li);
|
||
}
|
||
}
|
||
|
||
function obenSetzen() {
|
||
const sch = $('schiene');
|
||
const kopf = document.querySelector('#schiene .schiene__kopf');
|
||
if (sch && kopf) sch.style.setProperty('--cw-oben', `${Math.round(kopf.getBoundingClientRect().bottom - sch.getBoundingClientRect().top)}px`);
|
||
}
|
||
function tafelAuf() {
|
||
const t = tafelBauen();
|
||
obenSetzen();
|
||
t.hidden = false;
|
||
$('schiene')?.setAttribute('data-wache', 'ja');
|
||
$('cw-knopf')?.setAttribute('aria-expanded', 'true');
|
||
regelnHolen();
|
||
protokollHolen();
|
||
$('cw-titel')?.setAttribute('tabindex', '-1');
|
||
$('cw-titel')?.focus({ preventScroll: true });
|
||
}
|
||
function tafelZu() {
|
||
const t = $('cw-tafel');
|
||
if (t) t.hidden = true;
|
||
$('schiene')?.removeAttribute('data-wache');
|
||
$('cw-knopf')?.setAttribute('aria-expanded', 'false');
|
||
}
|
||
|
||
/* ---------------------------------------------------- Stand */
|
||
window.addEventListener('saal:lage', (e) => {
|
||
lage = e.detail;
|
||
const k = knopfBauen();
|
||
const team = !!(lage?.ich?.moderiert || lage?.ich?.host);
|
||
if (k) k.hidden = !team || lage?.stand === 'zu';
|
||
if (!team || lage?.stand === 'zu') tafelZu();
|
||
else if ($('cw-tafel') && !$('cw-tafel').hidden) obenSetzen();
|
||
/* Nach reaktion.js (das den Platzhalter beim Zeichnen setzt). */
|
||
setTimeout(feldSagen, 0);
|
||
});
|
||
window.addEventListener('saal:strom', (e) => {
|
||
const d = e.detail || {};
|
||
if (d.was === 'verwarnt') verwarnungZeigen(String(d.grund || 'Bitte halte dich an die Regeln im Chat.'));
|
||
if (!$('cw-tafel')?.hidden && (d.was === 'chatmodus' || d.was === 'massnahme' || d.was === 'gaeste')) protokollHolen();
|
||
});
|
||
/* Läuft die Tafel offen, frischt das Protokoll alle 15 s auf. */
|
||
setInterval(() => { if ($('cw-tafel') && !$('cw-tafel').hidden && document.visibilityState === 'visible') protokollHolen(); }, 15_000);
|
||
|
||
window.Chatwache = { tafelAuf, tafelZu, verwarnungZeigen };
|
||
})();
|