summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-02-04 07:37:26 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-04 20:37:26 +0800
commitd0960b80354c0c8326063c8408d2274adb50dec1 (patch)
tree7c082f5d30bee7a526c42a33031981b247eb537e /models/issue.go
parentd4035d1cb143a758463f2e3ee9d037fd5dab72f9 (diff)
downloadgitea-d0960b80354c0c8326063c8408d2274adb50dec1.tar.gz
gitea-d0960b80354c0c8326063c8408d2274adb50dec1.zip
Move IssueUser code to separate file (#836)
Also add unit tests
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go125
1 files changed, 0 insertions, 125 deletions
diff --git a/models/issue.go b/models/issue.go
index 7d7591837e..2f4c157920 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -1106,70 +1106,6 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
return issues, nil
}
-// .___ ____ ___
-// | | ______ ________ __ ____ | | \______ ___________
-// | |/ ___// ___/ | \_/ __ \| | / ___// __ \_ __ \
-// | |\___ \ \___ \| | /\ ___/| | /\___ \\ ___/| | \/
-// |___/____ >____ >____/ \___ >______//____ >\___ >__|
-// \/ \/ \/ \/ \/
-
-// IssueUser represents an issue-user relation.
-type IssueUser struct {
- ID int64 `xorm:"pk autoincr"`
- UID int64 `xorm:"INDEX"` // User ID.
- IssueID int64
- IsRead bool
- IsAssigned bool
- IsMentioned bool
-}
-
-func newIssueUsers(e *xorm.Session, repo *Repository, issue *Issue) error {
- assignees, err := repo.getAssignees(e)
- if err != nil {
- return fmt.Errorf("getAssignees: %v", err)
- }
-
- // Poster can be anyone, append later if not one of assignees.
- isPosterAssignee := false
-
- // Leave a seat for poster itself to append later, but if poster is one of assignee
- // and just waste 1 unit is cheaper than re-allocate memory once.
- issueUsers := make([]*IssueUser, 0, len(assignees)+1)
- for _, assignee := range assignees {
- issueUsers = append(issueUsers, &IssueUser{
- IssueID: issue.ID,
- UID: assignee.ID,
- IsAssigned: assignee.ID == issue.AssigneeID,
- })
- isPosterAssignee = isPosterAssignee || assignee.ID == issue.PosterID
- }
- if !isPosterAssignee {
- issueUsers = append(issueUsers, &IssueUser{
- IssueID: issue.ID,
- UID: issue.PosterID,
- })
- }
-
- if _, err = e.Insert(issueUsers); err != nil {
- return err
- }
- return nil
-}
-
-// NewIssueUsers adds new issue-user relations for new issue of repository.
-func NewIssueUsers(repo *Repository, issue *Issue) (err error) {
- sess := x.NewSession()
- defer sessionRelease(sess)
- if err = sess.Begin(); err != nil {
- return err
- }
-
- if err = newIssueUsers(sess, repo, issue); err != nil {
- return err
- }
-
- return sess.Commit()
-}
// UpdateIssueMentions extracts mentioned people from content and
// updates issue-user relations for them.
@@ -1400,67 +1336,6 @@ func UpdateIssue(issue *Issue) error {
return updateIssue(x, issue)
}
-func updateIssueUserByAssignee(e *xorm.Session, issue *Issue) (err error) {
- if _, err = e.Exec("UPDATE `issue_user` SET is_assigned = ? WHERE issue_id = ?", false, issue.ID); err != nil {
- return err
- }
-
- // Assignee ID equals to 0 means clear assignee.
- if issue.AssigneeID > 0 {
- if _, err = e.Exec("UPDATE `issue_user` SET is_assigned = ? WHERE uid = ? AND issue_id = ?", true, issue.AssigneeID, issue.ID); err != nil {
- return err
- }
- }
-
- return updateIssue(e, issue)
-}
-
-// UpdateIssueUserByAssignee updates issue-user relation for assignee.
-func UpdateIssueUserByAssignee(issue *Issue) (err error) {
- sess := x.NewSession()
- defer sessionRelease(sess)
- if err = sess.Begin(); err != nil {
- return err
- }
-
- if err = updateIssueUserByAssignee(sess, issue); err != nil {
- return err
- }
-
- return sess.Commit()
-}
-
-// UpdateIssueUserByRead updates issue-user relation for reading.
-func UpdateIssueUserByRead(uid, issueID int64) error {
- _, err := x.Exec("UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=?", true, uid, issueID)
- return err
-}
-
-// UpdateIssueUsersByMentions updates issue-user pairs by mentioning.
-func UpdateIssueUsersByMentions(e Engine, issueID int64, uids []int64) error {
- for _, uid := range uids {
- iu := &IssueUser{
- UID: uid,
- IssueID: issueID,
- }
- has, err := e.Get(iu)
- if err != nil {
- return err
- }
-
- iu.IsMentioned = true
- if has {
- _, err = e.Id(iu.ID).AllCols().Update(iu)
- } else {
- _, err = e.Insert(iu)
- }
- if err != nil {
- return err
- }
- }
- return nil
-}
-
// _____ .__.__ __
// / \ |__| | ____ _______/ |_ ____ ____ ____
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \