snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
60
services/notifications/status.go
Normal file
60
services/notifications/status.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Package notifications wraps activities_model notification-status mutations
|
||||
// with the matching real-time push, so route handlers cannot forget either side.
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
activities_model "gitea.dev/models/activities"
|
||||
user_model "gitea.dev/models/user"
|
||||
notify_service "gitea.dev/services/notify"
|
||||
)
|
||||
|
||||
func SetIssueReadBy(ctx context.Context, issueID, userID int64) error {
|
||||
changed, err := activities_model.SetIssueReadBy(ctx, issueID, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if changed {
|
||||
notify_service.NotificationCountChange(ctx, userID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetNotificationStatus(ctx context.Context, notificationID int64, user *user_model.User, status activities_model.NotificationStatus) (*activities_model.Notification, error) {
|
||||
notif, err := activities_model.SetNotificationStatus(ctx, notificationID, user, status)
|
||||
if err != nil {
|
||||
return notif, err
|
||||
}
|
||||
notify_service.NotificationCountChange(ctx, user.ID)
|
||||
return notif, nil
|
||||
}
|
||||
|
||||
func SetManyNotificationStatuses(ctx context.Context, ns []*activities_model.Notification, user *user_model.User, status activities_model.NotificationStatus) ([]*activities_model.Notification, error) {
|
||||
out := make([]*activities_model.Notification, 0, len(ns))
|
||||
for _, n := range ns {
|
||||
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, user, status)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out = append(out, notif)
|
||||
}
|
||||
if len(out) > 0 {
|
||||
notify_service.NotificationCountChange(ctx, user.ID)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func MarkAllRead(ctx context.Context, user *user_model.User) error {
|
||||
changed, err := activities_model.UpdateNotificationStatuses(ctx, user, activities_model.NotificationStatusUnread, activities_model.NotificationStatusRead)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if changed > 0 {
|
||||
notify_service.NotificationCountChange(ctx, user.ID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user