You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@answer.apache.org by "rstrzelecki-inne-projekty (via GitHub)" <gi...@apache.org> on 2026/09/22 20:34:04 UTC
[PR] fix(notification): the badge congratulations dialog can always be dismissed [answer]
rstrzelecki-inne-projekty opened a new pull request, #1633:
URL: https://github.com/apache/answer/pull/1633
### Problem
The "congratulations, you earned a badge" dialog reads its content from the red dot cache (`GET /notification/status` → `badge_award`). Closing it calls `PUT /answer/api/v1/notification/read/state`, and `NotificationService.ClearIDUnRead` does this:
```go
notificationInfo, exist, err := ns.notificationRepo.GetById(ctx, id)
...
if !exist || notificationInfo.UserID != userID {
return nil // <- returns success, and the alert stays in the cache
}
...
err = ns.notificationCommon.RemoveBadgeAwardAlertCache(ctx, userID, id)
```
When the notification row behind the alert is missing, the method returns `nil`, the endpoint answers `200`, and the alert is never removed. `/notification/status` keeps returning the same `badge_award`, so the dialog comes back on the next page load — and there is no way to close it, because every attempt takes the same early return.
The rows do go missing in practice: revoking a badge deletes its notification while the alert stays in the cache. The same early return also skips the cleanup when the notification is already read or belongs to another user.
Observed on a live instance: `PUT /notification/read/state` answered `{"code":200}` repeatedly while `/notification/status` kept serving the same `badge_award`, whose `notification_id` no longer appeared in `/notification/page`.
### Change
The alert is removed from the cache before the notification row is looked up. The cache key is built from the caller's own user id (`RedDotCacheKey` + the login user), so a request can only ever clear the caller's own alert — passing somebody else's notification id does nothing to them.
### Tests
`internal/service/notification/badge_alert_test.go` puts an alert in the cache, has the repository report the notification as missing, dismisses it and asserts the alert is gone. It fails on the current code ("the badge alert is still there, the dialog would come back") and passes with the fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org