diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2017-03-29 20:31:47 -0300 |
---|---|---|
committer | Andrey Nering <andrey.nering@gmail.com> | 2017-03-29 20:31:47 -0300 |
commit | b6744607484008826d18f129326664105b9d7bfc (patch) | |
tree | 77a41fe51c110e211bc1b0de95f163e62859c781 /routers | |
parent | a0d0de7233cd8a85d6572ae13d74078482a1ee27 (diff) | |
download | gitea-b6744607484008826d18f129326664105b9d7bfc.tar.gz gitea-b6744607484008826d18f129326664105b9d7bfc.zip |
Add watch button on issue
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/issue.go | 14 | ||||
-rw-r--r-- | routers/repo/issue_watch.go | 34 |
2 files changed, 48 insertions, 0 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 0a723d755b..61f79a239c 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -465,6 +465,20 @@ func ViewIssue(ctx *context.Context) { } ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title) + iw, exists, err := models.GetIssueWatch(ctx.User.ID, issue.ID) + if err != nil { + ctx.Handle(500, "GetIssueWatch", err) + return + } + if !exists { + iw = &models.IssueWatch{ + UserID: ctx.User.ID, + IssueID: issue.ID, + IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID), + } + } + ctx.Data["IssueWatch"] = iw + // Make sure type and URL matches. if ctx.Params(":type") == "issues" && issue.IsPull { ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index)) diff --git a/routers/repo/issue_watch.go b/routers/repo/issue_watch.go new file mode 100644 index 0000000000..64c99c5f79 --- /dev/null +++ b/routers/repo/issue_watch.go @@ -0,0 +1,34 @@ +package repo + +import ( + "fmt" + "net/http" + "strconv" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/context" +) + +// IssueWatch sets issue watching +func IssueWatch(c *context.Context) { + watch, err := strconv.ParseBool(c.Req.PostForm.Get("watch")) + if err != nil { + c.Handle(http.StatusInternalServerError, "watch is not bool", err) + return + } + + issueIndex := c.ParamsInt64("index") + issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex) + if err != nil { + c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err) + return + } + + if err := models.CreateOrUpdateIssueWatch(c.User.ID, issue.ID, watch); err != nil { + c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err) + return + } + + url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex) + c.Redirect(url, http.StatusSeeOther) +} |