fix(user): show worn badge in comments

This commit is contained in:
kate522 committed 2026-08-11 19:45:31 +08:00
1 parent 9781369b6b
commit bdbd85e434
2 files changed
+33 -8

No files matched your search

+5
View File
@@ -60,6 +60,11 @@ if (!function_exists('aksrt_render_user_identity_chips')) {
$priority = ['verify' => 0, 'badge' => 1, 'level' => 2]; $priority = ['verify' => 0, 'badge' => 1, 'level' => 2];
return ($priority[(string) ($left['type'] ?? '')] ?? 3) <=> ($priority[(string) ($right['type'] ?? '')] ?? 3); return ($priority[(string) ($left['type'] ?? '')] ?? 3) <=> ($priority[(string) ($right['type'] ?? '')] ?? 3);
}); });
if ($context === 'comment') {
$signals = array_values(array_filter($signals, static function (array $signal): bool {
return (string) ($signal['type'] ?? '') !== 'badge' || !empty($signal['wear']);
}));
}
// Comments stay compact; author/card can show more. // Comments stay compact; author/card can show more.
$limit = $context === 'comment' ? 3 : 6; $limit = $context === 'comment' ? 3 : 6;
$n = 0; $n = 0;
+28 -8
View File
@@ -165,15 +165,39 @@ class Home {
$limit = max(1, (int) ($settings['medal']['limit'] ?? 3)); $limit = max(1, (int) ($settings['medal']['limit'] ?? 3));
if (class_exists('AKSRT\\User\\Badges')) { if (class_exists('AKSRT\\User\\Badges')) {
$list = Badges::list_for_user($user_id); $list = Badges::list_for_user($user_id);
$badge_count = 0; $badge_items = [];
$done = false; $worn_item = null;
foreach ((array) ($list['categories'] ?? []) as $cat) { foreach ((array) ($list['categories'] ?? []) as $cat) {
foreach ((array) ($cat['items'] ?? []) as $item) { foreach ((array) ($cat['items'] ?? []) as $item) {
if (empty($item['owned'])) { if (empty($item['owned'])) {
continue; continue;
} }
if (!empty($item['wear'])) {
$worn_item = $item;
}
$badge_items[] = $item;
}
}
// Keep the worn badge visible even when it falls after the configured preview limit.
if (is_array($worn_item)) {
$signals[] = [
'type' => 'badge',
'slug' => (string) ($worn_item['slug'] ?? ''),
'label' => (string) ($worn_item['label'] ?? ''),
'icon' => 'award',
'tone' => 'info',
'icon_url' => (string) ($worn_item['icon_url'] ?? ''),
'wear' => true,
];
}
$badge_count = is_array($worn_item) ? 1 : 0;
foreach ($badge_items as $item) {
if (!empty($item['wear'])) {
continue;
}
if ($badge_count >= $limit) { if ($badge_count >= $limit) {
$done = true;
break; break;
} }
$signals[] = [ $signals[] = [
@@ -183,14 +207,10 @@ class Home {
'icon' => 'award', 'icon' => 'award',
'tone' => 'info', 'tone' => 'info',
'icon_url' => (string) ($item['icon_url'] ?? ''), 'icon_url' => (string) ($item['icon_url'] ?? ''),
'wear' => !empty($item['wear']), 'wear' => false,
]; ];
$badge_count++; $badge_count++;
} }
if ($done) {
break;
}
}
} }
} }