Auto-fill username + live emoji reactions

- initAuth() now sets joinName.value to logged-in username (no more hardcoded "Danny")
- Migration V6: active_emojis TEXT column on gtl_rooms
- api.php send_emoji action: appends emoji+timestamp to room, prunes entries >4s old, max 20
- loadRoom() returns activeEmojis filtered to last 4 seconds
- render() skips emoji list when diffing state (prevents poll thrash)
- Floating emoji stage: new emojis animate upward from bottom, deduplicated by ID
- Emoji bar (4 buttons: sheep/fire/laugh/thumbs) shown in player waiting card

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
danny 2026-06-14 12:35:13 +02:00
parent 01cd98aaf4
commit 758001597c
3 changed files with 92 additions and 4 deletions

26
api.php
View file

@ -45,7 +45,7 @@ function loadRoom(PDO $pdo, string $code): ?array
{
$stmt = $pdo->prepare(
'SELECT code, revealed, liar_keys, normal_question, imposter_question,
round_num, voted_out_keys, round_outcome, voting_open
round_num, voted_out_keys, round_outcome, voting_open, active_emojis
FROM gtl_rooms WHERE code = ?'
);
$stmt->execute([$code]);
@ -92,6 +92,10 @@ function loadRoom(PDO $pdo, string $code): ?array
'votedOutKeys' => $j($room['voted_out_keys']),
'roundOutcome' => $outcome,
'votingOpen' => (bool) ($room['voting_open'] ?? false),
'activeEmojis' => array_values(array_filter(
$j($room['active_emojis'] ?? '[]'),
fn($e) => ($e['ts'] ?? 0) >= (time() - 4)
)),
'players' => $players,
];
}
@ -362,6 +366,26 @@ try {
respond(['ok' => true, 'state' => loadRoom($pdo, $code)]);
break;
case 'send_emoji':
$body = input();
$code = slugCode((string) ($body['code'] ?? ''));
$emoji = (string) ($body['emoji'] ?? '');
$allowed = ['🐑','🔥','😂','👍'];
if (!in_array($emoji, $allowed, true)) respond(['error' => 'Ungültiges Emoji.'], 400);
// Load existing, prune stale (>4s), append new, keep max 20
$emojiStmt = $pdo->prepare('SELECT active_emojis FROM gtl_rooms WHERE code=?');
$emojiStmt->execute([$code]);
$emojiRow = $emojiStmt->fetch();
if (!$emojiRow) respond(['error' => 'Raum nicht gefunden.'], 404);
$list = (!empty($emojiRow['active_emojis'])) ? (json_decode($emojiRow['active_emojis'], true) ?: []) : [];
$list = array_filter($list, fn($e) => ($e['ts'] ?? 0) >= ($now - 4));
$list[] = ['emoji' => $emoji, 'ts' => $now, 'id' => uniqid()];
$list = array_values(array_slice($list, -20));
$pdo->prepare('UPDATE gtl_rooms SET active_emojis=?, updated_at=? WHERE code=?')
->execute([json_encode($list), $now, $code]);
respond(['ok' => true]);
break;
case 'vote':
$body = input();
$code = slugCode((string) ($body['code'] ?? ''));