Fix Issue Unsubscription (#9634)
This commit is contained in:
parent
b6fa229dcf
commit
9406368633
2 changed files with 9 additions and 5 deletions
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "code.gitea.io/gitea/modules/timeutil"
|
import (
|
||||||
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
)
|
||||||
|
|
||||||
// IssueWatch is connection request for receiving issue notification.
|
// IssueWatch is connection request for receiving issue notification.
|
||||||
type IssueWatch struct {
|
type IssueWatch struct {
|
||||||
|
@ -46,17 +48,18 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
|
||||||
return nil
|
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) {
|
func GetIssueWatch(userID, issueID int64) (iw *IssueWatch, exists bool, err error) {
|
||||||
return getIssueWatch(x, userID, issueID)
|
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) {
|
func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool, err error) {
|
||||||
iw = new(IssueWatch)
|
iw = new(IssueWatch)
|
||||||
exists, err = e.
|
exists, err = e.
|
||||||
Where("user_id = ?", userID).
|
Where("user_id = ?", userID).
|
||||||
And("issue_id = ?", issueID).
|
And("issue_id = ?", issueID).
|
||||||
And("is_watching = ?", true).
|
|
||||||
Get(iw)
|
Get(iw)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,10 @@ func TestGetIssueWatch(t *testing.T) {
|
||||||
assert.True(t, exists)
|
assert.True(t, exists)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, exists, err = GetIssueWatch(2, 2)
|
iw, exists, err := GetIssueWatch(2, 2)
|
||||||
assert.False(t, exists)
|
assert.True(t, exists)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, false, iw.IsWatching)
|
||||||
|
|
||||||
_, exists, err = GetIssueWatch(3, 1)
|
_, exists, err = GetIssueWatch(3, 1)
|
||||||
assert.False(t, exists)
|
assert.False(t, exists)
|
||||||
|
|
Reference in a new issue