Files
wibosim/server/public/js/notifycore.js
T
db9979andClaude Opus 5.5 f6bf11be79 Spielerfirmen, Schritt A: Gründung, Startup, Börsengang, Vorstand, Fairness
Spieler gründen ab Stufe 5 eine eigene AG in Wiborien (Steckbrief, Logo aus dem
Pool, Mitgründer), führen sie als Startup über Hebel und Quartalszahlen und
bringen sie über das IPO-Modul an die Börse. Danach entscheidet je Quartal die
Vorstandssitzung (Investitionen, Ausrichtung, Expansion, Dividende, Kapital-
maßnahmen, Kredit, Prognose). Fairness: Haltefrist, Handelsfenster nach den
Zahlen, Directors' Dealings, Deckel je Fenster, 75-%-Grenze, Glaubwürdigkeit.
Grenzen in den Admin-Einstellungen (Gruppe Spielerfirmen), Admin-Übersicht,
Hilfe/Handbuch, Simulation scripts/firmsim.mjs mit Ergebnis in BALANCING.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
2026-12-05 14:14:54 +00:00

154 lines
9.1 KiB
JavaScript
Raw 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.
// Benachrichtigungs-Einstellungen: gemeinsamer Kern für Server (src/notifyprefs.js) und Client (js/notifyprefs.js).
// Hier steht die eine Prüfung, ob ein Hinweis einer Kategorie auf einem Weg (In der App, Posteingang, Push, Taby)
// zugestellt wird – mit Vorgaben, Ruhezeiten und dem Sonderfall „Interviews nur bei Bezug zum Rivalen“.
// Pflichtmeldungen (Orders, Margin, Börsenaufsicht, Spielleitung, Hebelprodukte) haben keine Kategorie und kommen immer.
/** Wege, auf denen ein Hinweis ankommen kann */
export const NOTIF_CHANNELS = [
{ k: 'toast', label: 'In der App', short: 'App', hint: 'Kurzer Hinweis am Bildschirmrand, solange WiBoSim offen ist' },
{ k: 'inbox', label: 'Posteingang', short: 'Post', hint: 'Meldung bleibt im Posteingang, auch wenn du nicht da bist' },
{ k: 'push', label: 'Push', short: 'Push', hint: 'Benachrichtigung des Geräts, wenn WiBoSim im Hintergrund ist' },
{ k: 'taby', label: 'Taby', short: 'Taby', hint: 'Erinnerung in der Taby-App, falls verbunden' },
];
const CH_KEYS = NOTIF_CHANNELS.map((c) => c.k);
/**
* Kategorien. kinds = Meldungsarten des Posteingangs (social.notify) bzw. Live-Hinweise, die dazugehören;
* ch = angebotene Wege; def = Vorgabe. Reihenfolge = Reihenfolge auf der Einstellungsseite.
*/
export const NOTIF_CATS = [
{ k: 'alert', label: 'Kursalarme', desc: 'Deine Kursalarme lösen aus oder werden angepasst.', ic: 'bell', art: 'bell',
kinds: ['alert'], ch: ['toast', 'inbox', 'push', 'taby'], def: { toast: true, inbox: true, push: true, taby: true } },
{ k: 'corporate', label: 'Firmenmeldungen zu deinem Depot', desc: 'Splits, Übernahmen, Hauptversammlungen, Ratings, Abspaltungen und Börsengänge deiner Werte, dazu deine eigene Firma.', ic: 'handshake', art: 'briefcase',
kinds: ['corporate', 'agm', 'ipo', 'firm'], ch: ['toast', 'inbox', 'push'], def: { toast: true, inbox: true, push: true } },
{ k: 'interview', label: 'Interviews', desc: 'Ein Rivale gibt einem Wirtschaftsmedium ein Interview.', ic: 'chat', art: 'chat',
kinds: ['interview'], ch: ['toast', 'inbox', 'push'], def: { toast: true, inbox: false, push: false }, scope: true },
{ k: 'paper', label: 'Zeitung', desc: 'Eine neue Ausgabe der „Schlussglocke“ ist erschienen.', ic: 'news', art: 'news',
kinds: ['paper'], ch: ['toast', 'inbox', 'push'], def: { toast: true, inbox: false, push: false } },
{ k: 'battle', label: 'Battles & Turniere', desc: 'Herausforderungen, Start und Ergebnis deiner Battles, Turnierrunden.', ic: 'swords', art: 'swords',
kinds: ['battle', 'tournament'], ch: ['toast', 'inbox', 'push'], def: { toast: true, inbox: true, push: true } },
{ k: 'clan', label: 'Clan & Fonds', desc: 'Einladungen, Wochenziele und Bewegungen im Clan-Fonds.', ic: 'clan', art: 'clan',
kinds: ['clan', 'fund'], ch: ['toast', 'inbox', 'push'], def: { toast: true, inbox: true, push: true } },
{ k: 'politics', label: 'Politik', desc: 'Abstimmungen, Wahlergebnisse und deine Gesetzesvorlagen.', ic: 'parliament', art: 'parliament',
kinds: ['politics'], ch: ['toast', 'inbox', 'push'], def: { toast: true, inbox: true, push: true } },
{ k: 'coach', label: 'Coach-Notiz', desc: 'Dein Coach hat zum Handelsschluss eine neue Tagesnotiz geschrieben.', ic: 'cap', art: 'cap',
kinds: ['coach'], ch: ['toast', 'inbox', 'push'], def: { toast: false, inbox: false, push: false } },
{ k: 'achievement', label: 'Erfolge & Fortschritt', desc: 'Neue Erfolge, Level-Aufstiege, erledigte Aufgaben und Analysen.', ic: 'medal', art: 'medal',
kinds: ['achievement', 'level', 'quest', 'analysis', 'unlock'], ch: ['toast', 'inbox', 'push'], def: { toast: true, inbox: true, push: true } },
{ k: 'social', label: 'Freunde & Einladungen', desc: 'Jemand folgt dir oder ist deiner Einladung gefolgt.', ic: 'users', art: 'users',
kinds: ['social'], ch: ['toast', 'inbox', 'push'], def: { toast: false, inbox: true, push: true } },
// Team App: private Nachrichten nur als Push (In der App und im Posteingang → Nachrichten kommen sie ohnehin an)
{ k: 'dm', label: 'Private Nachrichten', desc: 'Ein Spieler schreibt dir. In der App und unter Posteingang → Nachrichten kommen sie immer an.', ic: 'chat', art: 'chat',
kinds: ['dm'], ch: ['push'], def: { push: true }, preview: true },
];
const CAT = Object.fromEntries(NOTIF_CATS.map((c) => [c.k, c]));
const KIND_CAT = Object.fromEntries(NOTIF_CATS.flatMap((c) => c.kinds.map((k) => [k, c.k])));
/** Bereiche für Interviews: nur bei Bezug zum Rivalen (Vorgabe) oder alle */
export const INTERVIEW_SCOPES = { related: 'Nur bei Bezug zum Rivalen', all: 'Alle Interviews' };
/** Was als Bezug gilt – steht so auf der Einstellungsseite */
export const RELATED_HINT = 'Bezug heißt: Du folgst dem Rivalen, hattest ein Battle gegen ihn oder hältst die Aktie, um die es im Interview geht.';
/** Team App: Was ein Push zu einer privaten Nachricht zeigt */
export const DM_PREVIEWS = { sender: 'Nur den Absender', text: 'Absender und Textanfang' };
/** Meldungsart → Kategorie (null = Pflichtmeldung) */
export const kindCat = (kind) => KIND_CAT[kind] ?? null;
const TIME_RE = /^([01]\d|2[0-3]):[0-5]\d$/;
const tzOk = new Map();
function validTz(tz) {
if (typeof tz !== 'string' || !tz || tz.length > 64) return false;
if (!tzOk.has(tz)) {
if (tzOk.size > 200) tzOk.clear();
try { tzOk.set(tz, new Intl.DateTimeFormat('de-DE', { timeZone: tz, hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })); } catch { tzOk.set(tz, null); }
}
return !!tzOk.get(tz);
}
/** Vorgaben (frisches Objekt) */
export function defaultPrefs() {
return {
c: Object.fromEntries(NOTIF_CATS.map((c) => [c.k, Object.fromEntries(c.ch.map((k) => [k, !!c.def[k]]))])),
scope: { interview: 'related', dm: 'sender' }, // dm: Team App (Vorschau im Push; Sperrbildschirm: Vorgabe nur Absender)
quiet: { on: false, from: '22:00', to: '07:00', tz: null, toast: false },
};
}
/** Beliebige Eingabe (gespeichert oder vom Client) → vollständige, geprüfte Einstellungen. Unbekanntes fällt weg. */
export function normPrefs(raw) {
const out = defaultPrefs();
if (!raw || typeof raw !== 'object') return out;
const c = raw.c && typeof raw.c === 'object' ? raw.c : {};
for (const cat of NOTIF_CATS) {
const v = c[cat.k];
if (!v || typeof v !== 'object') continue;
for (const k of cat.ch) if (typeof v[k] === 'boolean') out.c[cat.k][k] = v[k];
}
if (Object.hasOwn(INTERVIEW_SCOPES, raw.scope?.interview)) out.scope.interview = raw.scope.interview;
if (Object.hasOwn(DM_PREVIEWS, raw.scope?.dm)) out.scope.dm = raw.scope.dm; // Team App
const q = raw.quiet;
if (q && typeof q === 'object') {
out.quiet.on = q.on === true;
out.quiet.toast = q.toast === true;
if (TIME_RE.test(q.from)) out.quiet.from = q.from;
if (TIME_RE.test(q.to)) out.quiet.to = q.to;
if (validTz(q.tz)) out.quiet.tz = q.tz;
}
return out;
}
const mins = (hhmm) => Number(hhmm.slice(0, 2)) * 60 + Number(hhmm.slice(3, 5));
/** Minuten seit Mitternacht in einer Zeitzone */
export function minuteOfDay(now, tz) {
if (validTz(tz)) {
const parts = tzOk.get(tz).formatToParts(new Date(now));
const h = Number(parts.find((x) => x.type === 'hour')?.value ?? 0), m = Number(parts.find((x) => x.type === 'minute')?.value ?? 0);
return (h % 24) * 60 + m;
}
const d = new Date(now);
return d.getHours() * 60 + d.getMinutes();
}
/**
* Liegt `now` in der Ruhezeit? Von–bis darf über Mitternacht gehen (22:00–07:00). Gleiche Zeiten = keine Ruhezeit.
* @param {{on:boolean, from:string, to:string, tz?:string|null}} q @param {number} now @param {string} [fallbackTz]
*/
export function inQuiet(q, now, fallbackTz) {
if (!q?.on) return false;
const a = mins(q.from), b = mins(q.to);
if (a === b) return false;
const t = minuteOfDay(now, q.tz || fallbackTz);
return a < b ? t >= a && t < b : t >= a || t < b;
}
const SYSTEM = Object.freeze({ toast: false, inbox: true, push: true, taby: false, cat: null });
/**
* Die zentrale Prüfung: auf welchen Wegen kommt ein Hinweis dieser Kategorie an?
* Pflichtmeldungen (cat null/unbekannt): Posteingang und Push wie bisher, keine Ruhezeit.
* In der Ruhezeit schweigen Push und Taby (und In-App-Hinweise, falls gewählt); der Posteingang sammelt weiter.
* @param {object} prefs normalisierte Einstellungen (normPrefs)
* @param {string|null} cat
* @param {{now?: number, tz?: string, related?: boolean}} [o] related: nur für Interviews
* @returns {{toast:boolean, inbox:boolean, push:boolean, taby:boolean, cat:string|null, quiet?:boolean}}
*/
export function route(prefs, cat, { now = Date.now(), tz, related = true } = {}) {
const c = CAT[cat];
if (!c) return { ...SYSTEM };
const v = prefs?.c?.[cat] ?? {};
const out = { cat, toast: false, inbox: false, push: false, taby: false };
for (const k of CH_KEYS) out[k] = c.ch.includes(k) && v[k] === true;
if (c.scope && prefs?.scope?.interview !== 'all' && !related) for (const k of CH_KEYS) out[k] = false;
if (inQuiet(prefs?.quiet, now, tz)) {
out.quiet = true;
out.push = false;
out.taby = false;
if (prefs.quiet.toast) out.toast = false;
}
return out;
}
/** Kommt irgendetwas an? */
export const anyChannel = (r) => !!(r && (r.toast || r.inbox || r.push || r.taby));