|
|
@ -96,6 +96,11 @@ func CreateOrUpdateIssueNotifications(issue *Issue, notificationAuthorID int64) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthorID int64) error { |
|
|
|
func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthorID int64) error { |
|
|
|
|
|
|
|
issueWatches, err := getIssueWatchers(e, issue.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
watches, err := getWatchers(e, issue.RepoID) |
|
|
|
watches, err := getWatchers(e, issue.RepoID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
@ -106,23 +111,42 @@ func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthor |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, watch := range watches { |
|
|
|
alreadyNotified := make(map[int64]struct{}, len(issueWatches)+len(watches)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifyUser := func(userID int64) error { |
|
|
|
// do not send notification for the own issuer/commenter
|
|
|
|
// do not send notification for the own issuer/commenter
|
|
|
|
if watch.UserID == notificationAuthorID { |
|
|
|
if userID == notificationAuthorID { |
|
|
|
continue |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if notificationExists(notifications, issue.ID, watch.UserID) { |
|
|
|
if _, ok := alreadyNotified[userID]; ok { |
|
|
|
err = updateIssueNotification(e, watch.UserID, issue.ID, notificationAuthorID) |
|
|
|
return nil |
|
|
|
} else { |
|
|
|
|
|
|
|
err = createIssueNotification(e, watch.UserID, issue, notificationAuthorID) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
alreadyNotified[userID] = struct{}{} |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if notificationExists(notifications, issue.ID, userID) { |
|
|
|
|
|
|
|
return updateIssueNotification(e, userID, issue.ID, notificationAuthorID) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return createIssueNotification(e, userID, issue, notificationAuthorID) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, issueWatch := range issueWatches { |
|
|
|
|
|
|
|
// ignore if user unwatched the issue
|
|
|
|
|
|
|
|
if !issueWatch.IsWatching { |
|
|
|
|
|
|
|
alreadyNotified[issueWatch.UserID] = struct{}{} |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := notifyUser(issueWatch.UserID); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, watch := range watches { |
|
|
|
|
|
|
|
if err := notifyUser(watch.UserID); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|