Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/lib/handlers/seventv/entitlement-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export default defineHandler({
const badge = app.badges.get(data.ref_id);
if (!badge) return;

getOrInsert(app.badges.users, user.id, []).push(badge);
const badges = getOrInsert(app.badges.users, user.id, []);

if (!badges.some((b) => b.id === badge.id)) {
badges.push(badge);
}
Comment on lines +18 to +22
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler is re-implementing badge de-duplication logic inline (some/push on app.badges.users), which duplicates similar logic now encapsulated in BadgeManager.#insert. Consider exposing a shared helper on BadgeManager (or another common utility) and invoking it here to keep badge insertion semantics consistent and reduce the risk of future divergence.

Copilot uses AI. Check for mistakes.

break;
}

Expand Down
15 changes: 13 additions & 2 deletions src/lib/managers/badge-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class BadgeManager extends SvelteMap<string, Badge> {
});
});

getOrInsert(this.users, user.providerId, []).push(badge);
this.#insert(user.providerId, badge);
}
}

Expand Down Expand Up @@ -124,8 +124,19 @@ export class BadgeManager extends SvelteMap<string, Badge> {
const badge = badges[badgeId];

for (const id of users) {
getOrInsert(this.users, id.toString(), []).push(badge);
this.#insert(id.toString(), badge);
}
}
}

#insert(id: string, badge: Badge) {
const badges = getOrInsert(this.users, id, []);
const idx = badges.findIndex((b) => b.id === badge.id);

if (idx === -1) {
badges.push(badge);
} else {
badges[idx] = badge;
}
}
}