Raid groups: no wrapping for long names; show website display names synced from the Discord server nickname
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
267a7f532c
commit
fd3928726b
7 changed files with 88 additions and 6 deletions
|
|
@ -219,6 +219,9 @@ include __DIR__ . '/../includes/header.php';
|
|||
<div>
|
||||
<label for="display_name">Anzeigename</label>
|
||||
<input type="text" id="display_name" name="display_name" value="<?= e($user['display_name']) ?>">
|
||||
<?php if ($hasDiscord): ?>
|
||||
<div class="field-hint">Wird beim nächsten Discord-Abgleich durch den Namen auf dem Discord-Server ersetzt.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ($isEdit): ?>
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -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']),
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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<int, array<string, mixed>> $raids
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -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
|
|||
<input type="hidden" name="action" value="update_profile">
|
||||
<div>
|
||||
<label for="display_name">Anzeigename</label>
|
||||
<input type="text" id="display_name" name="display_name" value="<?= e($user['display_name']) ?>" required>
|
||||
<input type="text" id="display_name" name="display_name" value="<?= e($user['display_name']) ?>" required<?= !empty($user['discord_id']) ? ' readonly' : '' ?>>
|
||||
<?php if (!empty($user['discord_id'])): ?>
|
||||
<div class="field-hint"><?= discord_logo(12) ?> Wird automatisch von deinem Namen auf unserem Discord-Server übernommen. Ändern kannst du ihn dort über „Server-Profil bearbeiten“.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div>
|
||||
<label for="class_name">Klasse</label>
|
||||
|
|
|
|||
|
|
@ -24,10 +24,7 @@ function render_signup_list(array $members, bool $draggable): void
|
|||
<?php elseif ($classIconUrl): ?>
|
||||
<img src="<?= e($classIconUrl) ?>" alt="<?= e($memberClass) ?>" title="<?= e($memberClass) ?>" class="class-icon">
|
||||
<?php endif; ?>
|
||||
<?= e($memberName) ?>
|
||||
<?php if (!$isPending && !$classIconUrl && $memberClass !== ''): ?>
|
||||
<span class="text-muted">(<?= e($memberClass) ?>)</span>
|
||||
<?php endif; ?>
|
||||
<span class="raid-signup-name" title="<?= e($memberName . ($memberClass !== '' && !$isPending ? ' – ' . $memberClass : '')) ?>"><?= e($memberName) ?><?php if (!$isPending && !$classIconUrl && $memberClass !== ''): ?> <span class="text-muted">(<?= e($memberClass) ?>)</span><?php endif; ?></span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
|
|
|||
Loading…
Reference in a new issue