diff options
author | 6543 <6543@obermui.de> | 2020-04-21 15:48:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 14:48:53 +0100 |
commit | bb4261a5ed678235fadef279fe1ba1505993a406 (patch) | |
tree | e3134123a4ccd273ddf5cd93701fef6db21d593b /models/issue_watch.go | |
parent | 33176e8d27eeb47c6d63fbd24bf11ac9e5c60acd (diff) | |
download | gitea-bb4261a5ed678235fadef279fe1ba1505993a406.tar.gz gitea-bb4261a5ed678235fadef279fe1ba1505993a406.zip |
Add issue subscription check to API (#10967)
close #10962
Adds `GET /api/v1/repos/{owner}/{repo}/issues/{index}/subscriptions/check`
-> return a `WachInfo`
Diffstat (limited to 'models/issue_watch.go')
-rw-r--r-- | models/issue_watch.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/models/issue_watch.go b/models/issue_watch.go index dea6aa5a52..9a2985fb69 100644 --- a/models/issue_watch.go +++ b/models/issue_watch.go @@ -64,6 +64,23 @@ func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool return } +// CheckIssueWatch check if an user is watching an issue +// it takes participants and repo watch into account +func CheckIssueWatch(user *User, issue *Issue) (bool, error) { + iw, exist, err := getIssueWatch(x, user.ID, issue.ID) + if err != nil { + return false, err + } + if exist { + return iw.IsWatching, nil + } + w, err := getWatch(x, user.ID, issue.RepoID) + if err != nil { + return false, err + } + return isWatchMode(w.Mode) || IsUserParticipantsOfIssue(user, issue), nil +} + // GetIssueWatchersIDs returns IDs of subscribers or explicit unsubscribers to a given issue id // but avoids joining with `user` for performance reasons // User permissions must be verified elsewhere if required |