mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-15 10:28:46 +00:00
Fix bug
This commit is contained in:
parent
803a3a4426
commit
4163c6dc68
@ -149,10 +149,11 @@ func CreateCommitNotifications(ctx context.Context, doerID, repoID int64, commit
|
||||
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)
|
||||
if _, err := db.GetEngine(ctx).
|
||||
Where("user_id = ?", receiverID).
|
||||
And("repo_id = ?", repoID).
|
||||
And("release_id = ?", releaseID).
|
||||
Get(notification); err != nil {
|
||||
return err
|
||||
@ -166,6 +167,7 @@ func CreateOrUpdateReleaseNotifications(ctx context.Context, doerID, releaseID,
|
||||
|
||||
notification = &Notification{
|
||||
Source: NotificationSourceRelease,
|
||||
RepoID: repoID,
|
||||
UserID: receiverID,
|
||||
Status: NotificationStatusUnread,
|
||||
ReleaseID: releaseID,
|
||||
@ -427,6 +429,17 @@ func SetReleaseReadBy(ctx context.Context, releaseID, userID int64) error {
|
||||
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
|
||||
func SetNotificationStatus(ctx context.Context, notificationID int64, user *user_model.User, status NotificationStatus) (*Notification, error) {
|
||||
notification, err := GetNotificationByID(ctx, notificationID)
|
||||
|
@ -492,6 +492,7 @@ func (nl NotificationList) LoadReleases(ctx context.Context) ([]int, error) {
|
||||
failures = append(failures, i)
|
||||
continue
|
||||
}
|
||||
notification.Release.Repo = notification.Repository
|
||||
}
|
||||
}
|
||||
return failures, nil
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
@ -301,6 +302,14 @@ func Diff(ctx *context.Context) {
|
||||
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")
|
||||
maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles
|
||||
files := ctx.FormStrings("files")
|
||||
|
@ -68,11 +68,11 @@ func handler(items ...notificationOpts) []notificationOpts {
|
||||
log.Error("CreateRepoTransferNotification: %v", err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
case activities_model.NotificationSourceIssue, activities_model.NotificationSourcePullRequest:
|
||||
@ -96,6 +96,7 @@ func (ns *notificationService) CreateIssueComment(ctx context.Context, doer *use
|
||||
opts := notificationOpts{
|
||||
Source: util.Iif(issue.IsPull, activities_model.NotificationSourcePullRequest, activities_model.NotificationSourceIssue),
|
||||
IssueID: issue.ID,
|
||||
RepoID: issue.RepoID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
}
|
||||
if comment != nil {
|
||||
@ -103,30 +104,22 @@ func (ns *notificationService) CreateIssueComment(ctx context.Context, doer *use
|
||||
}
|
||||
_ = ns.queue.Push(opts)
|
||||
for _, mention := range mentions {
|
||||
opts := notificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
ReceiverID: mention.ID,
|
||||
}
|
||||
if comment != nil {
|
||||
opts.CommentID = comment.ID
|
||||
}
|
||||
opts.ReceiverID = mention.ID
|
||||
_ = ns.queue.Push(opts)
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
RepoID: issue.RepoID,
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: issue.Poster.ID,
|
||||
})
|
||||
}
|
||||
_ = ns.queue.Push(opts)
|
||||
for _, mention := range mentions {
|
||||
_ = ns.queue.Push(notificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: issue.Poster.ID,
|
||||
ReceiverID: mention.ID,
|
||||
})
|
||||
opts.ReceiverID = mention.ID
|
||||
_ = ns.queue.Push(opts)
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,14 +205,7 @@ func (ns *notificationService) PullRequestReview(ctx context.Context, pr *issues
|
||||
}
|
||||
_ = ns.queue.Push(opts)
|
||||
for _, mention := range mentions {
|
||||
opts := notificationOpts{
|
||||
IssueID: pr.Issue.ID,
|
||||
NotificationAuthorID: r.Reviewer.ID,
|
||||
ReceiverID: mention.ID,
|
||||
}
|
||||
if c != nil {
|
||||
opts.CommentID = c.ID
|
||||
}
|
||||
opts.ReceiverID = mention.ID
|
||||
_ = 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) {
|
||||
opts := notificationOpts{
|
||||
Source: activities_model.NotificationSourceRelease,
|
||||
RepoID: rel.RepoID,
|
||||
ReleaseID: rel.ID,
|
||||
NotificationAuthorID: rel.PublisherID,
|
||||
}
|
||||
|
@ -72,7 +72,7 @@
|
||||
{{if .Issue}}
|
||||
{{DateUtils.TimeSince .Issue.UpdatedUnix}}
|
||||
{{else if .Release}}
|
||||
{{DateUtils.TimeSince .Release.UpdatedUnix}}
|
||||
{{DateUtils.TimeSince .Release.CreatedUnix}}
|
||||
{{else if .Commit}}
|
||||
{{DateUtils.TimeSince .Commit.Committer.When}}
|
||||
{{else}}
|
||||
|
Loading…
Reference in New Issue
Block a user