Skip to content

Fix Issue Unsubscription #9634

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

Merged
merged 5 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions models/issue_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package models

import "code.gitea.io/gitea/modules/timeutil"
import (
"code.gitea.io/gitea/modules/timeutil"
)

// IssueWatch is connection request for receiving issue notification.
type IssueWatch struct {
Expand Down Expand Up @@ -46,17 +48,18 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
return nil
}

// GetIssueWatch returns an issue watch by user and issue
// GetIssueWatch returns all IssueWatch objects from db by user and issue
// the current Web-UI need iw object for watchers AND explicit non-watchers
func GetIssueWatch(userID, issueID int64) (iw *IssueWatch, exists bool, err error) {
return getIssueWatch(x, userID, issueID)
}

// Return watcher AND explicit non-watcher if entry in db exist
func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool, err error) {
iw = new(IssueWatch)
exists, err = e.
Where("user_id = ?", userID).
And("issue_id = ?", issueID).
And("is_watching = ?", true).
Get(iw)
return
}
Expand Down
5 changes: 3 additions & 2 deletions models/issue_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ func TestGetIssueWatch(t *testing.T) {
assert.True(t, exists)
assert.NoError(t, err)

_, exists, err = GetIssueWatch(2, 2)
assert.False(t, exists)
iw, exists, err := GetIssueWatch(2, 2)
assert.True(t, exists)
assert.NoError(t, err)
assert.EqualValues(t, false, iw.IsWatching)

_, exists, err = GetIssueWatch(3, 1)
assert.False(t, exists)
Expand Down