fix(chat): prevent pushing duplicate badges#178
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent external provider badges (BTTV, FFZ, 7TV) from being added multiple times for the same user, fixing the duplicated badge display reported in issue #177.
Changes:
- Refactors BTTV and FFZ badge assignment in
BadgeManagerto route through a new#inserthelper intended to de-duplicate per-user badges. - Updates the 7TV
entitlement.createhandler to only push a badge toapp.badges.usersif it is not already present for that user.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lib/managers/badge-manager.ts | Introduces a private #insert helper and uses it when assigning BTTV/FFZ badges to users to avoid duplicates (though the current comparison logic is incorrect). |
| src/lib/handlers/seventv/entitlement-create.ts | Adds per-user badge de-duplication when handling 7TV badge entitlements to avoid pushing the same badge multiple times. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const badges = getOrInsert(app.badges.users, user.id, []); | ||
|
|
||
| if (!badges.some((b) => b.id === badge.id)) { | ||
| badges.push(badge); | ||
| } |
There was a problem hiding this comment.
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.
Fixes #177