Skip to content

Commit 4163c6d

Browse files
committed
Fix bug
1 parent 803a3a4 commit 4163c6d

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

models/activities/notification.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ func CreateCommitNotifications(ctx context.Context, doerID, repoID int64, commit
149149
return db.Insert(ctx, notification)
150150
}
151151

152-
func CreateOrUpdateReleaseNotifications(ctx context.Context, doerID, releaseID, receiverID int64) error {
152+
func CreateOrUpdateReleaseNotifications(ctx context.Context, doerID, repoID, releaseID, receiverID int64) error {
153153
notification := new(Notification)
154154
if _, err := db.GetEngine(ctx).
155155
Where("user_id = ?", receiverID).
156+
And("repo_id = ?", repoID).
156157
And("release_id = ?", releaseID).
157158
Get(notification); err != nil {
158159
return err
@@ -166,6 +167,7 @@ func CreateOrUpdateReleaseNotifications(ctx context.Context, doerID, releaseID,
166167

167168
notification = &Notification{
168169
Source: NotificationSourceRelease,
170+
RepoID: repoID,
169171
UserID: receiverID,
170172
Status: NotificationStatusUnread,
171173
ReleaseID: releaseID,
@@ -427,6 +429,17 @@ func SetReleaseReadBy(ctx context.Context, releaseID, userID int64) error {
427429
return err
428430
}
429431

432+
// SetCommitReadBy sets issue to be read by given user.
433+
func SetCommitReadBy(ctx context.Context, repoID, userID int64, commitID string) error {
434+
_, err := db.GetEngine(ctx).Where(builder.Eq{
435+
"user_id": userID,
436+
"status": NotificationStatusUnread,
437+
"source": NotificationSourceCommit,
438+
"commit_id": commitID,
439+
}).Cols("status").Update(&Notification{Status: NotificationStatusRead})
440+
return err
441+
}
442+
430443
// SetNotificationStatus change the notification status
431444
func SetNotificationStatus(ctx context.Context, notificationID int64, user *user_model.User, status NotificationStatus) (*Notification, error) {
432445
notification, err := GetNotificationByID(ctx, notificationID)

models/activities/notification_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ func (nl NotificationList) LoadReleases(ctx context.Context) ([]int, error) {
492492
failures = append(failures, i)
493493
continue
494494
}
495+
notification.Release.Repo = notification.Repository
495496
}
496497
}
497498
return failures, nil

routers/web/repo/commit.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path"
1313
"strings"
1414

15+
activities_model "code.gitea.io/gitea/models/activities"
1516
asymkey_model "code.gitea.io/gitea/models/asymkey"
1617
"code.gitea.io/gitea/models/db"
1718
git_model "code.gitea.io/gitea/models/git"
@@ -301,6 +302,14 @@ func Diff(ctx *context.Context) {
301302
commitID = commit.ID.String()
302303
}
303304

305+
if ctx.IsSigned {
306+
err = activities_model.SetCommitReadBy(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, commitID)
307+
if err != nil {
308+
ctx.ServerError("SetReleaseReadBy", err)
309+
return
310+
}
311+
}
312+
304313
fileOnly := ctx.FormBool("file-only")
305314
maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles
306315
files := ctx.FormStrings("files")

services/uinotification/notify.go

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ func handler(items ...notificationOpts) []notificationOpts {
6868
log.Error("CreateRepoTransferNotification: %v", err)
6969
}
7070
case activities_model.NotificationSourceCommit:
71-
if err := activities_model.CreateCommitNotifications(db.DefaultContext, opts.RepoID, opts.NotificationAuthorID, opts.CommitID, opts.ReceiverID); err != nil {
71+
if err := activities_model.CreateCommitNotifications(db.DefaultContext, opts.NotificationAuthorID, opts.RepoID, opts.CommitID, opts.ReceiverID); err != nil {
7272
log.Error("Was unable to create commit notification: %v", err)
7373
}
7474
case activities_model.NotificationSourceRelease:
75-
if err := activities_model.CreateOrUpdateReleaseNotifications(db.DefaultContext, opts.NotificationAuthorID, opts.ReleaseID, opts.ReceiverID); err != nil {
75+
if err := activities_model.CreateOrUpdateReleaseNotifications(db.DefaultContext, opts.NotificationAuthorID, opts.RepoID, opts.ReleaseID, opts.ReceiverID); err != nil {
7676
log.Error("Was unable to create release notification: %v", err)
7777
}
7878
case activities_model.NotificationSourceIssue, activities_model.NotificationSourcePullRequest:
@@ -96,37 +96,30 @@ func (ns *notificationService) CreateIssueComment(ctx context.Context, doer *use
9696
opts := notificationOpts{
9797
Source: util.Iif(issue.IsPull, activities_model.NotificationSourcePullRequest, activities_model.NotificationSourceIssue),
9898
IssueID: issue.ID,
99+
RepoID: issue.RepoID,
99100
NotificationAuthorID: doer.ID,
100101
}
101102
if comment != nil {
102103
opts.CommentID = comment.ID
103104
}
104105
_ = ns.queue.Push(opts)
105106
for _, mention := range mentions {
106-
opts := notificationOpts{
107-
IssueID: issue.ID,
108-
NotificationAuthorID: doer.ID,
109-
ReceiverID: mention.ID,
110-
}
111-
if comment != nil {
112-
opts.CommentID = comment.ID
113-
}
107+
opts.ReceiverID = mention.ID
114108
_ = ns.queue.Push(opts)
115109
}
116110
}
117111

118112
func (ns *notificationService) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
119-
_ = ns.queue.Push(notificationOpts{
113+
opts := notificationOpts{
120114
Source: activities_model.NotificationSourceIssue,
115+
RepoID: issue.RepoID,
121116
IssueID: issue.ID,
122117
NotificationAuthorID: issue.Poster.ID,
123-
})
118+
}
119+
_ = ns.queue.Push(opts)
124120
for _, mention := range mentions {
125-
_ = ns.queue.Push(notificationOpts{
126-
IssueID: issue.ID,
127-
NotificationAuthorID: issue.Poster.ID,
128-
ReceiverID: mention.ID,
129-
})
121+
opts.ReceiverID = mention.ID
122+
_ = ns.queue.Push(opts)
130123
}
131124
}
132125

@@ -212,14 +205,7 @@ func (ns *notificationService) PullRequestReview(ctx context.Context, pr *issues
212205
}
213206
_ = ns.queue.Push(opts)
214207
for _, mention := range mentions {
215-
opts := notificationOpts{
216-
IssueID: pr.Issue.ID,
217-
NotificationAuthorID: r.Reviewer.ID,
218-
ReceiverID: mention.ID,
219-
}
220-
if c != nil {
221-
opts.CommentID = c.ID
222-
}
208+
opts.ReceiverID = mention.ID
223209
_ = ns.queue.Push(opts)
224210
}
225211
}
@@ -366,6 +352,7 @@ func (ns *notificationService) NewRelease(ctx context.Context, rel *repo_model.R
366352
func (ns *notificationService) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
367353
opts := notificationOpts{
368354
Source: activities_model.NotificationSourceRelease,
355+
RepoID: rel.RepoID,
369356
ReleaseID: rel.ID,
370357
NotificationAuthorID: rel.PublisherID,
371358
}

templates/user/notification/notification_div.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
{{if .Issue}}
7373
{{DateUtils.TimeSince .Issue.UpdatedUnix}}
7474
{{else if .Release}}
75-
{{DateUtils.TimeSince .Release.UpdatedUnix}}
75+
{{DateUtils.TimeSince .Release.CreatedUnix}}
7676
{{else if .Commit}}
7777
{{DateUtils.TimeSince .Commit.Committer.When}}
7878
{{else}}

0 commit comments

Comments
 (0)