From fd3928726b9e3917e9344d2f299848ae25f94a15 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Mon, 21 Sep 2026 20:57:56 +0200 Subject: [PATCH] Raid groups: no wrapping for long names; show website display names synced from the Discord server nickname Co-Authored-By: Claude Opus 5 --- admin/user_form.php | 3 +++ assets/css/style.css | 13 ++++++++++ includes/discord.php | 3 +++ includes/discord_auth.php | 11 +++++++++ includes/raids_api.php | 50 ++++++++++++++++++++++++++++++++++++++- profile.php | 9 ++++++- raids.php | 5 +--- 7 files changed, 88 insertions(+), 6 deletions(-) diff --git a/admin/user_form.php b/admin/user_form.php index 4e6452f..fa57b25 100644 --- a/admin/user_form.php +++ b/admin/user_form.php @@ -219,6 +219,9 @@ include __DIR__ . '/../includes/header.php';
+ +
Wird beim nächsten Discord-Abgleich durch den Namen auf dem Discord-Server ersetzt.
+
diff --git a/assets/css/style.css b/assets/css/style.css index 04e1187..a7e3e70 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -793,8 +793,21 @@ input[type="datetime-local"]::-webkit-calendar-picker-indicator { flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.4rem; + min-width: 0; } +/* Name bleibt neben dem Klassen-Icon; zu lange Namen werden mit "…" gekuerzt + (voller Name im Tooltip), statt unter das Icon umzubrechen. */ +.raid-signup-name { + flex: 1 1 0; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.raid-group li .class-icon { flex-shrink: 0; } + /* Mobile-/Touch-Alternative zum Drag&Drop: natives HTML5-Drag&Drop funktioniert auf Touch-Geraeten nicht, daher gibt es im Editor-Modus zusaetzlich dieses Dropdown pro Spieler. Ausserhalb des Editor-Modus bleibt es versteckt. */ diff --git a/includes/discord.php b/includes/discord.php index f0f2556..1a18a1e 100644 --- a/includes/discord.php +++ b/includes/discord.php @@ -266,6 +266,9 @@ function discord_fetch_member(string $accessToken): ?array return [ 'roles' => array_map('strval', (array) ($data['roles'] ?? [])), 'nick' => (string) ($data['nick'] ?? ''), + // Fuer den Anzeigenamen: Server-Spitzname, sonst globaler Discord-Name, sonst Benutzername + 'global_name' => (string) ($data['user']['global_name'] ?? ''), + 'username' => (string) ($data['user']['username'] ?? ''), // Profilbild: das Server-Profilbild hat Vorrang vor dem globalen. avatar_known = false, // wenn Discord das Nutzerobjekt nicht mitschickt - dann bleibt das Bild, wie es ist. 'avatar_known' => isset($data['user']) && is_array($data['user']), diff --git a/includes/discord_auth.php b/includes/discord_auth.php index b835a0e..221afb2 100644 --- a/includes/discord_auth.php +++ b/includes/discord_auth.php @@ -57,6 +57,17 @@ function discord_apply_member(int $userId, array $member): void { discord_sync_roles($userId, $member['roles']); db()->prepare('UPDATE users SET discord_synced_at = NOW() WHERE id = ?')->execute([$userId]); + // Anzeigename = Name auf dem Discord-Server (Spitzname, sonst globaler Name, sonst Benutzername) + $discordName = trim((string) ($member['nick'] ?? '')); + if ($discordName === '') { + $discordName = trim((string) ($member['global_name'] ?? '')); + } + if ($discordName === '') { + $discordName = trim((string) ($member['username'] ?? '')); + } + if ($discordName !== '') { + db()->prepare('UPDATE users SET display_name = ? WHERE id = ?')->execute([mb_substr($discordName, 0, 100), $userId]); + } // Beitritt zum Discord-Server merken ("Dabei seit" in Mitgliederliste und Profil) $joined = !empty($member['joined_at']) ? strtotime($member['joined_at']) : false; if ($joined !== false) { diff --git a/includes/raids_api.php b/includes/raids_api.php index cdd7f5f..3e1e0bf 100644 --- a/includes/raids_api.php +++ b/includes/raids_api.php @@ -107,7 +107,55 @@ function fetch_raids(string $status = 'active'): array throw new RuntimeException('Unerwartetes Antwortformat der Raid-API.'); } - return $data['raids']; + return raids_apply_display_names($data['raids']); +} + +/** + * Ersetzt die Namen in den Anmeldungen durch den Anzeigenamen des verknuepften + * Website-Kontos. Der Bot speichert den Namen zum Zeitpunkt der Anmeldung; der Anzeigename + * folgt dagegen immer dem aktuellen Namen auf dem Discord-Server. + * + * @param array> $raids + * @return array> + */ +function raids_apply_display_names(array $raids): array +{ + $ids = []; + foreach ($raids as $raid) { + foreach ((array) ($raid['signups'] ?? []) as $signup) { + if (!empty($signup['user_id'])) { + $ids[(string) $signup['user_id']] = true; + } + } + } + if (empty($ids)) { + return $raids; + } + + try { + $placeholders = implode(',', array_fill(0, count($ids), '?')); + $stmt = db()->prepare( + "SELECT discord_id, display_name FROM users WHERE discord_id IN ($placeholders) AND display_name <> ''" + ); + $stmt->execute(array_keys($ids)); + $names = []; + foreach ($stmt->fetchAll() as $row) { + $names[(string) $row['discord_id']] = (string) $row['display_name']; + } + } catch (PDOException $e) { + return $raids; + } + + foreach ($raids as &$raid) { + foreach ((array) ($raid['signups'] ?? []) as $i => $signup) { + $id = (string) ($signup['user_id'] ?? ''); + if (isset($names[$id])) { + $raid['signups'][$i]['name'] = $names[$id]; + } + } + } + unset($raid); + return $raids; } /** @throws RuntimeException */ diff --git a/profile.php b/profile.php index 66ecf46..00efa22 100644 --- a/profile.php +++ b/profile.php @@ -14,6 +14,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($action === 'update_profile') { $displayName = trim((string) ($_POST['display_name'] ?? '')); + // Mit Discord-Verknuepfung folgt der Anzeigename dem Namen auf dem Discord-Server. + if (!empty($user['discord_id'])) { + $displayName = (string) $user['display_name']; + } $className = (string) ($_POST['class_name'] ?? ''); $className = in_array($className, AION_CLASSES, true) ? $className : null; if ($displayName === '') { @@ -162,7 +166,10 @@ document.getElementById('avatar-upload-input').addEventListener('change', functi
- + > + +
Wird automatisch von deinem Namen auf unserem Discord-Server übernommen. Ändern kannst du ihn dort über „Server-Profil bearbeiten“.
+
diff --git a/raids.php b/raids.php index 70010b0..a36e144 100644 --- a/raids.php +++ b/raids.php @@ -24,10 +24,7 @@ function render_signup_list(array $members, bool $draggable): void <?= e($memberClass) ?> - - - () - +