fix(user): show worn badge in comments

This commit is contained in:
2026-08-11 19:45:31 +08:00
parent 9781369b6b
commit bdbd85e434
2 changed files with 42 additions and 17 deletions
+36 -16
View File
@@ -165,31 +165,51 @@ class Home {
$limit = max(1, (int) ($settings['medal']['limit'] ?? 3));
if (class_exists('AKSRT\\User\\Badges')) {
$list = Badges::list_for_user($user_id);
$badge_count = 0;
$done = false;
$badge_items = [];
$worn_item = null;
foreach ((array) ($list['categories'] ?? []) as $cat) {
foreach ((array) ($cat['items'] ?? []) as $item) {
if (empty($item['owned'])) {
continue;
}
if ($badge_count >= $limit) {
$done = true;
break;
if (!empty($item['wear'])) {
$worn_item = $item;
}
$signals[] = [
'type' => 'badge',
'slug' => (string) ($item['slug'] ?? ''),
'label' => (string) ($item['label'] ?? ''),
'icon' => 'award',
'tone' => 'info',
'icon_url' => (string) ($item['icon_url'] ?? ''),
'wear' => !empty($item['wear']),
];
$badge_count++;
$badge_items[] = $item;
}
if ($done) {
}
// 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) {
break;
}
$signals[] = [
'type' => 'badge',
'slug' => (string) ($item['slug'] ?? ''),
'label' => (string) ($item['label'] ?? ''),
'icon' => 'award',
'tone' => 'info',
'icon_url' => (string) ($item['icon_url'] ?? ''),
'wear' => false,
];
$badge_count++;
}
}
}