This commit is contained in:
Lunny Xiao 2025-06-20 15:54:29 -07:00
parent 803a3a4426
commit 4163c6dc68
5 changed files with 37 additions and 27 deletions

View File

@ -149,10 +149,11 @@ func CreateCommitNotifications(ctx context.Context, doerID, repoID int64, commit
return db.Insert(ctx, notification) return db.Insert(ctx, notification)
} }
func CreateOrUpdateReleaseNotifications(ctx context.Context, doerID, releaseID, receiverID int64) error { func CreateOrUpdateReleaseNotifications(ctx context.Context, doerID, repoID, releaseID, receiverID int64) error {
notification := new(Notification) notification := new(Notification)
if _, err := db.GetEngine(ctx). if _, err := db.GetEngine(ctx).
Where("user_id = ?", receiverID). Where("user_id = ?", receiverID).
And("repo_id = ?", repoID).
And("release_id = ?", releaseID). And("release_id = ?", releaseID).
Get(notification); err != nil { Get(notification); err != nil {
return err return err
@ -166,6 +167,7 @@ func CreateOrUpdateReleaseNotifications(ctx context.Context, doerID, releaseID,
notification = &Notification{ notification = &Notification{
Source: NotificationSourceRelease, Source: NotificationSourceRelease,
RepoID: repoID,
UserID: receiverID, UserID: receiverID,
Status: NotificationStatusUnread, Status: NotificationStatusUnread,
ReleaseID: releaseID, ReleaseID: releaseID,
@ -427,6 +429,17 @@ func SetReleaseReadBy(ctx context.Context, releaseID, userID int64) error {
return err return err
} }
// SetCommitReadBy sets issue to be read by given user.
func SetCommitReadBy(ctx context.Context, repoID, userID int64, commitID string) error {
_, err := db.GetEngine(ctx).Where(builder.Eq{
"user_id": userID,
"status": NotificationStatusUnread,
"source": NotificationSourceCommit,
"commit_id": commitID,
}).Cols("status").Update(&Notification{Status: NotificationStatusRead})
return err
}
// SetNotificationStatus change the notification status // SetNotificationStatus change the notification status
func SetNotificationStatus(ctx context.Context, notificationID int64, user *user_model.User, status NotificationStatus) (*Notification, error) { func SetNotificationStatus(ctx context.Context, notificationID int64, user *user_model.User, status NotificationStatus) (*Notification, error) {
notification, err := GetNotificationByID(ctx, notificationID) notification, err := GetNotificationByID(ctx, notificationID)

View File

@ -492,6 +492,7 @@ func (nl NotificationList) LoadReleases(ctx context.Context) ([]int, error) {
failures = append(failures, i) failures = append(failures, i)
continue continue
} }
notification.Release.Repo = notification.Repository
} }
} }
return failures, nil return failures, nil

View File

@ -12,6 +12,7 @@ import (
"path" "path"
"strings" "strings"
activities_model "code.gitea.io/gitea/models/activities"
asymkey_model "code.gitea.io/gitea/models/asymkey" asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git" git_model "code.gitea.io/gitea/models/git"
@ -301,6 +302,14 @@ func Diff(ctx *context.Context) {
commitID = commit.ID.String() commitID = commit.ID.String()
} }
if ctx.IsSigned {
err = activities_model.SetCommitReadBy(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, commitID)
if err != nil {
ctx.ServerError("SetReleaseReadBy", err)
return
}
}
fileOnly := ctx.FormBool("file-only") fileOnly := ctx.FormBool("file-only")
maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles
files := ctx.FormStrings("files") files := ctx.FormStrings("files")

View File

@ -68,11 +68,11 @@ func handler(items ...notificationOpts) []notificationOpts {
log.Error("CreateRepoTransferNotification: %v", err) log.Error("CreateRepoTransferNotification: %v", err)
} }
case activities_model.NotificationSourceCommit: case activities_model.NotificationSourceCommit:
if err := activities_model.CreateCommitNotifications(db.DefaultContext, opts.RepoID, opts.NotificationAuthorID, opts.CommitID, opts.ReceiverID); err != nil { if err := activities_model.CreateCommitNotifications(db.DefaultContext, opts.NotificationAuthorID, opts.RepoID, opts.CommitID, opts.ReceiverID); err != nil {
log.Error("Was unable to create commit notification: %v", err) log.Error("Was unable to create commit notification: %v", err)
} }
case activities_model.NotificationSourceRelease: case activities_model.NotificationSourceRelease:
if err := activities_model.CreateOrUpdateReleaseNotifications(db.DefaultContext, opts.NotificationAuthorID, opts.ReleaseID, opts.ReceiverID); err != nil { if err := activities_model.CreateOrUpdateReleaseNotifications(db.DefaultContext, opts.NotificationAuthorID, opts.RepoID, opts.ReleaseID, opts.ReceiverID); err != nil {
log.Error("Was unable to create release notification: %v", err) log.Error("Was unable to create release notification: %v", err)
} }
case activities_model.NotificationSourceIssue, activities_model.NotificationSourcePullRequest: case activities_model.NotificationSourceIssue, activities_model.NotificationSourcePullRequest:
@ -96,6 +96,7 @@ func (ns *notificationService) CreateIssueComment(ctx context.Context, doer *use
opts := notificationOpts{ opts := notificationOpts{
Source: util.Iif(issue.IsPull, activities_model.NotificationSourcePullRequest, activities_model.NotificationSourceIssue), Source: util.Iif(issue.IsPull, activities_model.NotificationSourcePullRequest, activities_model.NotificationSourceIssue),
IssueID: issue.ID, IssueID: issue.ID,
RepoID: issue.RepoID,
NotificationAuthorID: doer.ID, NotificationAuthorID: doer.ID,
} }
if comment != nil { if comment != nil {
@ -103,30 +104,22 @@ func (ns *notificationService) CreateIssueComment(ctx context.Context, doer *use
} }
_ = ns.queue.Push(opts) _ = ns.queue.Push(opts)
for _, mention := range mentions { for _, mention := range mentions {
opts := notificationOpts{ opts.ReceiverID = mention.ID
IssueID: issue.ID,
NotificationAuthorID: doer.ID,
ReceiverID: mention.ID,
}
if comment != nil {
opts.CommentID = comment.ID
}
_ = ns.queue.Push(opts) _ = ns.queue.Push(opts)
} }
} }
func (ns *notificationService) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { func (ns *notificationService) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
_ = ns.queue.Push(notificationOpts{ opts := notificationOpts{
Source: activities_model.NotificationSourceIssue, Source: activities_model.NotificationSourceIssue,
RepoID: issue.RepoID,
IssueID: issue.ID, IssueID: issue.ID,
NotificationAuthorID: issue.Poster.ID, NotificationAuthorID: issue.Poster.ID,
}) }
_ = ns.queue.Push(opts)
for _, mention := range mentions { for _, mention := range mentions {
_ = ns.queue.Push(notificationOpts{ opts.ReceiverID = mention.ID
IssueID: issue.ID, _ = ns.queue.Push(opts)
NotificationAuthorID: issue.Poster.ID,
ReceiverID: mention.ID,
})
} }
} }
@ -212,14 +205,7 @@ func (ns *notificationService) PullRequestReview(ctx context.Context, pr *issues
} }
_ = ns.queue.Push(opts) _ = ns.queue.Push(opts)
for _, mention := range mentions { for _, mention := range mentions {
opts := notificationOpts{ opts.ReceiverID = mention.ID
IssueID: pr.Issue.ID,
NotificationAuthorID: r.Reviewer.ID,
ReceiverID: mention.ID,
}
if c != nil {
opts.CommentID = c.ID
}
_ = ns.queue.Push(opts) _ = ns.queue.Push(opts)
} }
} }
@ -366,6 +352,7 @@ func (ns *notificationService) NewRelease(ctx context.Context, rel *repo_model.R
func (ns *notificationService) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { func (ns *notificationService) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
opts := notificationOpts{ opts := notificationOpts{
Source: activities_model.NotificationSourceRelease, Source: activities_model.NotificationSourceRelease,
RepoID: rel.RepoID,
ReleaseID: rel.ID, ReleaseID: rel.ID,
NotificationAuthorID: rel.PublisherID, NotificationAuthorID: rel.PublisherID,
} }

View File

@ -72,7 +72,7 @@
{{if .Issue}} {{if .Issue}}
{{DateUtils.TimeSince .Issue.UpdatedUnix}} {{DateUtils.TimeSince .Issue.UpdatedUnix}}
{{else if .Release}} {{else if .Release}}
{{DateUtils.TimeSince .Release.UpdatedUnix}} {{DateUtils.TimeSince .Release.CreatedUnix}}
{{else if .Commit}} {{else if .Commit}}
{{DateUtils.TimeSince .Commit.Committer.When}} {{DateUtils.TimeSince .Commit.Committer.When}}
{{else}} {{else}}