mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-16 12:41:03 +00:00
Backport of https://github.com/go-gitea/gitea/pull/38847, which fixes the stopwatch push flake in https://github.com/go-gitea/gitea/actions/runs/43200377380/job/131122930118. The stopwatch e2e test keeps its v28 flow, since main reworked it in a separate change. Assisted-by: Claude Code:claude-opus-5-5
33 lines
997 B
Go
33 lines
997 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package websocket
|
|
|
|
import (
|
|
"context"
|
|
|
|
activities_model "gitea.dev/models/activities"
|
|
"gitea.dev/models/db"
|
|
"gitea.dev/modules/log"
|
|
)
|
|
|
|
const eventNotificationCount = "notification-count" // keep in sync with web_src/js/types.ts
|
|
|
|
func (n *wsNotifier) NotificationCountChange(ctx context.Context, userID int64) {
|
|
publishUserEvent(userID, func() []byte { return notificationCountEvent(ctx, userID) })
|
|
}
|
|
|
|
func notificationCountEvent(ctx context.Context, userID int64) []byte {
|
|
count, err := db.Count[activities_model.Notification](ctx, activities_model.FindNotificationOptions{
|
|
UserID: userID,
|
|
Status: []activities_model.NotificationStatus{activities_model.NotificationStatusUnread},
|
|
})
|
|
if err != nil {
|
|
log.Error("websocket: count notifications for user %d: %v", userID, err)
|
|
return nil
|
|
}
|
|
return makeEventMessage(eventNotificationCount, "", struct {
|
|
Count int64 `json:"count"`
|
|
}{count})
|
|
}
|