summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/issue_watch.go33
-rw-r--r--models/userlist.go10
2 files changed, 41 insertions, 2 deletions
diff --git a/models/issue_watch.go b/models/issue_watch.go
index 2f55c6a84d..1ae0c9d474 100644
--- a/models/issue_watch.go
+++ b/models/issue_watch.go
@@ -16,6 +16,9 @@ type IssueWatch struct {
UpdatedUnix timeutil.TimeStamp `xorm:"updated NOT NULL"`
}
+// IssueWatchList contains IssueWatch
+type IssueWatchList []*IssueWatch
+
// CreateOrUpdateIssueWatch set watching for a user and issue
func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
iw, exists, err := getIssueWatch(x, userID, issueID)
@@ -58,11 +61,11 @@ func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool
}
// GetIssueWatchers returns watchers/unwatchers of a given issue
-func GetIssueWatchers(issueID int64) ([]*IssueWatch, error) {
+func GetIssueWatchers(issueID int64) (IssueWatchList, error) {
return getIssueWatchers(x, issueID)
}
-func getIssueWatchers(e Engine, issueID int64) (watches []*IssueWatch, err error) {
+func getIssueWatchers(e Engine, issueID int64) (watches IssueWatchList, err error) {
err = e.
Where("`issue_watch`.issue_id = ?", issueID).
And("`user`.is_active = ?", true).
@@ -83,3 +86,29 @@ func removeIssueWatchersByRepoID(e Engine, userID int64, repoID int64) error {
Update(iw)
return err
}
+
+// LoadWatchUsers return watching users
+func (iwl IssueWatchList) LoadWatchUsers() (users UserList, err error) {
+ return iwl.loadWatchUsers(x)
+}
+
+func (iwl IssueWatchList) loadWatchUsers(e Engine) (users UserList, err error) {
+ if len(iwl) == 0 {
+ return []*User{}, nil
+ }
+
+ var userIDs = make([]int64, 0, len(iwl))
+ for _, iw := range iwl {
+ if iw.IsWatching {
+ userIDs = append(userIDs, iw.UserID)
+ }
+ }
+
+ if len(userIDs) == 0 {
+ return []*User{}, nil
+ }
+
+ err = e.In("id", userIDs).Find(&users)
+
+ return
+}
diff --git a/models/userlist.go b/models/userlist.go
index a2a4248482..16ec6fee55 100644
--- a/models/userlist.go
+++ b/models/userlist.go
@@ -8,6 +8,7 @@ import (
"fmt"
"code.gitea.io/gitea/modules/log"
+ api "code.gitea.io/gitea/modules/structs"
)
//UserList is a list of user.
@@ -93,3 +94,12 @@ func (users UserList) loadTwoFactorStatus(e Engine) (map[int64]*TwoFactor, error
}
return tokenMaps, nil
}
+
+//APIFormat return list of users in api format
+func (users UserList) APIFormat() []*api.User {
+ var result []*api.User
+ for _, u := range users {
+ result = append(result, u.APIFormat())
+ }
+ return result
+}