fix(user): show worn badge in comments
This commit is contained in:
1 parent
9781369b6b
commit
bdbd85e434
2 files changed
+42
-17
No files matched your search
@@ -60,7 +60,12 @@ 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);
|
||||||
});
|
});
|
||||||
// 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;
|
$limit = $context === 'comment' ? 3 : 6;
|
||||||
$n = 0;
|
$n = 0;
|
||||||
foreach ($signals as $signal) {
|
foreach ($signals as $signal) {
|
||||||
|
|||||||
+36
-16
@@ -165,31 +165,51 @@ 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 ($badge_count >= $limit) {
|
if (!empty($item['wear'])) {
|
||||||
$done = true;
|
$worn_item = $item;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
$signals[] = [
|
$badge_items[] = $item;
|
||||||
'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++;
|
|
||||||
}
|
}
|
||||||
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;
|
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