fix(user): show worn badge in comments
This commit is contained in:
@@ -60,7 +60,12 @@ if (!function_exists('aksrt_render_user_identity_chips')) {
|
||||
$priority = ['verify' => 0, 'badge' => 1, 'level' => 2];
|
||||
return ($priority[(string) ($left['type'] ?? '')] ?? 3) <=> ($priority[(string) ($right['type'] ?? '')] ?? 3);
|
||||
});
|
||||
// Comments stay compact; author/card can show more.
|
||||
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.
|
||||
$limit = $context === 'comment' ? 3 : 6;
|
||||
$n = 0;
|
||||
foreach ($signals as $signal) {
|
||||
|
||||
+36
-16
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user