From 940636863370855f39688ddf0aae41667ac8935c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 7 Jan 2020 16:41:35 +0100 Subject: [PATCH] Fix Issue Unsubscription (#9634) --- models/issue_watch.go | 9 ++++++--- models/issue_watch_test.go | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/models/issue_watch.go b/models/issue_watch.go index e42e371a1..6144d6caf 100644 --- a/models/issue_watch.go +++ b/models/issue_watch.go @@ -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 { @@ -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 } diff --git a/models/issue_watch_test.go b/models/issue_watch_test.go index 1d0473426..90140591b 100644 --- a/models/issue_watch_test.go +++ b/models/issue_watch_test.go @@ -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)