Rename the main module to gotea.dev and the binary to gotea, and update the application name and English locale. Keep the external gitea.dev/sdk and gitea.dev/actionslib module imports unchanged. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
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 "gotea.dev/models/activities"
|
|
"gotea.dev/models/db"
|
|
"gotea.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})
|
|
}
|