Add issue subscription check to API (#10967)
close #10962 Adds `GET /api/v1/repos/{owner}/{repo}/issues/{index}/subscriptions/check` -> return a `WachInfo`
This commit is contained in:
parent
33176e8d27
commit
bb4261a5ed
8 changed files with 205 additions and 20 deletions
|
@ -332,6 +332,13 @@ func (issue *Issue) GetIsRead(userID int64) error {
|
|||
|
||||
// APIURL returns the absolute APIURL to this issue.
|
||||
func (issue *Issue) APIURL() string {
|
||||
if issue.Repo == nil {
|
||||
err := issue.LoadRepo()
|
||||
if err != nil {
|
||||
log.Error("Issue[%d].APIURL(): %v", issue.ID, err)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s/issues/%d", issue.Repo.APIURL(), issue.Index)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue