diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-06-13 17:37:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-13 17:37:59 +0800 |
commit | 1a9821f57a0293db3adc0eab8aff08ca5fa1026c (patch) | |
tree | 3c3d02813eb63c0d0827ef6d9745f6dcdd2636cb /models/issue_user.go | |
parent | 3708ca8e2849ca7e36e6bd15ec6935a2a2d81e55 (diff) | |
download | gitea-1a9821f57a0293db3adc0eab8aff08ca5fa1026c.tar.gz gitea-1a9821f57a0293db3adc0eab8aff08ca5fa1026c.zip |
Move issues related files into models/issues (#19931)
* Move access and repo permission to models/perm/access
* fix test
* fix git test
* Move functions sequence
* Some improvements per @KN4CK3R and @delvh
* Move issues related code to models/issues
* Move some issues related sub package
* Merge
* Fix test
* Fix test
* Fix test
* Fix test
* Rename some files
Diffstat (limited to 'models/issue_user.go')
-rw-r--r-- | models/issue_user.go | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/models/issue_user.go b/models/issue_user.go deleted file mode 100644 index 19c64094a1..0000000000 --- a/models/issue_user.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2017 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package models - -import ( - "context" - "fmt" - - "code.gitea.io/gitea/models/db" - repo_model "code.gitea.io/gitea/models/repo" -) - -// IssueUser represents an issue-user relation. -type IssueUser struct { - ID int64 `xorm:"pk autoincr"` - UID int64 `xorm:"INDEX"` // User ID. - IssueID int64 - IsRead bool - IsMentioned bool -} - -func init() { - db.RegisterModel(new(IssueUser)) -} - -func newIssueUsers(ctx context.Context, repo *repo_model.Repository, issue *Issue) error { - assignees, err := repo_model.GetRepoAssignees(ctx, repo) - 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, - }) - isPosterAssignee = isPosterAssignee || assignee.ID == issue.PosterID - } - if !isPosterAssignee { - issueUsers = append(issueUsers, &IssueUser{ - IssueID: issue.ID, - UID: issue.PosterID, - }) - } - - return db.Insert(ctx, issueUsers) -} - -// UpdateIssueUserByRead updates issue-user relation for reading. -func UpdateIssueUserByRead(uid, issueID int64) error { - _, err := db.GetEngine(db.DefaultContext).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(ctx context.Context, issueID int64, uids []int64) error { - for _, uid := range uids { - iu := &IssueUser{ - UID: uid, - IssueID: issueID, - } - has, err := db.GetEngine(ctx).Get(iu) - if err != nil { - return err - } - - iu.IsMentioned = true - if has { - _, err = db.GetEngine(ctx).ID(iu.ID).Cols("is_mentioned").Update(iu) - } else { - _, err = db.GetEngine(ctx).Insert(iu) - } - if err != nil { - return err - } - } - return nil -} |