mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Merge branch 'master' into refactor_issues-subscription
This commit is contained in:
+31
-3
@@ -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)
|
||||
@@ -59,12 +62,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) {
|
||||
// handle manual watchers
|
||||
func getIssueWatchers(e Engine, issueID int64) (watches IssueWatchList, err error) {
|
||||
err = e.
|
||||
Where("`issue_watch`.issue_id = ?", issueID).
|
||||
And("`issue_watch`.is_watching = ?", true).
|
||||
@@ -91,3 +93,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user