Add watch button on issue
This commit is contained in:
parent
a0d0de7233
commit
b674460748
6 changed files with 111 additions and 0 deletions
|
@ -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))
|
||||
|
|
34
routers/repo/issue_watch.go
Normal file
34
routers/repo/issue_watch.go
Normal file
|
@ -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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue