Compare commits
2 Commits
main
...
notificati
Author | SHA1 | Date |
---|---|---|
Andrey Nering | 0904e5b9b4 | |
Andrey Nering | 9c267a071a |
|
@ -491,6 +491,7 @@ func runWeb(ctx *cli.Context) error {
|
|||
m.Group("/:index", func() {
|
||||
m.Post("/title", repo.UpdateIssueTitle)
|
||||
m.Post("/content", repo.UpdateIssueContent)
|
||||
m.Post("/watch", repo.IssueWatch)
|
||||
m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
|
||||
})
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// IssueWatch is connection request for receiving issue notification.
|
||||
type IssueWatch struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UserID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||
IssueID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||
IsWatching bool `xorm:"NOT NULL"`
|
||||
Created time.Time `xorm:"-"`
|
||||
CreatedUnix int64 `xorm:"NOT NULL"`
|
||||
}
|
||||
|
||||
// BeforeInsert is invoked from XORM before inserting an object of this type.
|
||||
func (iw *IssueWatch) BeforeInsert() {
|
||||
iw.CreatedUnix = time.Now().Unix()
|
||||
}
|
||||
|
||||
// CreateOrUpdateIssueWatch set watching for a user and issue
|
||||
func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
|
||||
s := x.NewSession()
|
||||
defer s.Close()
|
||||
if err := s.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
iw, exists, err := getIssueWatch(s, userID, issueID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
iw = &IssueWatch{
|
||||
UserID: userID,
|
||||
IssueID: issueID,
|
||||
IsWatching: isWatching,
|
||||
}
|
||||
|
||||
if _, err := s.Insert(iw); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
iw.IsWatching = isWatching
|
||||
|
||||
if _, err := s.Id(iw.ID).Update(iw); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetIssueWatch returns an issue watch by user and issue
|
||||
func GetIssueWatch(userID, issueID int64) (iw *IssueWatch, exists bool, err error) {
|
||||
iw, exists, err = getIssueWatch(x, userID, issueID)
|
||||
return
|
||||
}
|
||||
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).
|
||||
Get(iw)
|
||||
return
|
||||
}
|
|
@ -117,6 +117,7 @@ func init() {
|
|||
new(ExternalLoginUser),
|
||||
new(ProtectedBranch),
|
||||
new(UserOpenID),
|
||||
new(IssueWatch),
|
||||
)
|
||||
|
||||
gonicNames := []string{"SSL", "UID"}
|
||||
|
|
|
@ -652,6 +652,9 @@ issues.label.filter_sort.reverse_alphabetically = Reverse alphabetically
|
|||
issues.num_participants = %d Participants
|
||||
issues.attachment.open_tab = `Click to see "%s" in a new tab`
|
||||
issues.attachment.download = `Click to download "%s"`
|
||||
issues.watch = Watch
|
||||
issues.watch_issue = Watch issue
|
||||
issues.unwatch_issue = Unwatch issue
|
||||
|
||||
pulls.new = New Pull Request
|
||||
pulls.compare_changes = Compare Changes
|
||||
|
|
|
@ -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: false,
|
||||
}
|
||||
}
|
||||
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))
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
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
|
||||
}
|
||||
issueID := c.ParamsInt64("index")
|
||||
|
||||
if err := models.CreateOrUpdateIssueWatch(c.User.ID, issueID, watch); err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
|
||||
return
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueID)
|
||||
c.Redirect(url, http.StatusSeeOther)
|
||||
}
|
|
@ -98,5 +98,24 @@
|
|||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
|
||||
<div class="ui watching">
|
||||
<span class="text"><strong>{{.i18n.Tr "repo.issues.watch"}}</strong></span>
|
||||
<div>
|
||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/watch">
|
||||
<input type="hidden" name="watch" value="{{if $.IssueWatch.IsWatching}}0{{else}}1{{end}}" />
|
||||
{{$.CsrfTokenHtml}}
|
||||
<button class="fluid ui button">
|
||||
{{if $.IssueWatch.IsWatching}}
|
||||
{{.i18n.Tr "repo.issues.unwatch_issue"}}
|
||||
{{else}}
|
||||
{{.i18n.Tr "repo.issues.watch_issue"}}
|
||||
{{end}}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue