Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inform participants on UI too #10473

Merged
merged 8 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,13 +1277,24 @@ func GetParticipantsIDsByIssueID(issueID int64) ([]int64, error) {

// GetParticipantsByIssueID returns all users who are participated in comments of an issue.
func GetParticipantsByIssueID(issueID int64) ([]*User, error) {
return getParticipantsByIssueID(x, issueID)
issue, err := getIssueByID(x, issueID)
if err != nil {
return nil, err
}
userIDs, err := getParticipantsByIssueID(x, issue)
if err != nil {
return nil, err
}
if len(userIDs) == 0 {
return nil, nil
}
return GetUsersByIDs(userIDs)
}

func getParticipantsByIssueID(e Engine, issueID int64) ([]*User, error) {
func getParticipantsByIssueID(e Engine, issue *Issue) ([]int64, error) {
userIDs := make([]int64, 0, 5)
if err := e.Table("comment").Cols("poster_id").
Where("`comment`.issue_id = ?", issueID).
Where("`comment`.issue_id = ?", issue.ID).
And("`comment`.type in (?,?,?)", CommentTypeComment, CommentTypeCode, CommentTypeReview).
And("`user`.is_active = ?", true).
And("`user`.prohibit_login = ?", false).
Expand All @@ -1292,12 +1303,20 @@ func getParticipantsByIssueID(e Engine, issueID int64) ([]*User, error) {
Find(&userIDs); err != nil {
return nil, fmt.Errorf("get poster IDs: %v", err)
}
if len(userIDs) == 0 {
return nil, nil
if !util.IsInt64InSlice(issue.PosterID, userIDs) {
return append(userIDs, issue.PosterID), nil
}
return userIDs, nil
}

users := make([]*User, 0, len(userIDs))
return users, e.In("id", userIDs).Find(&users)
// IsUserParticipantsOfIssue return true if user is participants of an issue
func IsUserParticipantsOfIssue(user *User, issue *Issue) bool {
userIDs, err := getParticipantsByIssueID(x, issue)
if err != nil {
log.Error(err.Error())
return false
}
return util.IsInt64InSlice(user.ID, userIDs)
}

// UpdateIssueMentions updates issue-user relations for mentioned users.
Expand Down
2 changes: 1 addition & 1 deletion models/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestGetParticipantsByIssueID(t *testing.T) {
// User 2 only labeled issue1 (see fixtures/comment.yml)
// Users 3 and 5 made actual comments (see fixtures/comment.yml)
// User 3 is inactive, thus not active participant
checkParticipants(1, []int{5})
checkParticipants(1, []int{1, 5})
}

func TestIssue_ClearLabels(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions models/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ func createOrUpdateIssueNotifications(e Engine, issueID, commentID int64, notifi
toNotify[id] = struct{}{}
}

issueParticipants, err := getParticipantsByIssueID(e, issue)
if err != nil {
return err
}
for _, id := range issueParticipants {
toNotify[id] = struct{}{}
}

// dont notify user who cause notification
delete(toNotify, notificationAuthorID)
// explicit unwatch on issue
Expand Down
10 changes: 10 additions & 0 deletions modules/util/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func IsStringInSlice(target string, slice []string) bool {
return false
}

// IsInt64InSlice sequential searches if int64 exists in slice.
func IsInt64InSlice(target int64, slice []int64) bool {
for i := 0; i < len(slice); i++ {
if slice[i] == target {
return true
}
}
return false
}

// IsEqualSlice returns true if slices are equal.
func IsEqualSlice(target []string, source []string) bool {
if len(target) != len(source) {
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ func ViewIssue(ctx *context.Context) {
iw = &models.IssueWatch{
UserID: ctx.User.ID,
IssueID: issue.ID,
IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) || models.IsUserParticipantsOfIssue(ctx.User, issue),
}
}
}
Expand Down