mirror of https://github.com/go-gitea/gitea.git
Finish watch backend
This commit is contained in:
parent
a922c3ff6a
commit
59ea3c0413
|
@ -55,8 +55,17 @@ func CommitRepoAction(userId int64, userName string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add feeds for user self and all watchers.
|
||||||
|
watches, err := GetWatches(repoId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
watches = append(watches, Watch{UserId: userId})
|
||||||
|
|
||||||
|
for i := range watches {
|
||||||
_, err = orm.InsertOne(&Action{
|
_, err = orm.InsertOne(&Action{
|
||||||
UserId: userId,
|
UserId: watches[i].UserId,
|
||||||
ActUserId: userId,
|
ActUserId: userId,
|
||||||
ActUserName: userName,
|
ActUserName: userName,
|
||||||
OpType: OP_COMMIT_REPO,
|
OpType: OP_COMMIT_REPO,
|
||||||
|
@ -66,6 +75,8 @@ func CommitRepoAction(userId int64, userName string,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewRepoAction records action for create repository.
|
// NewRepoAction records action for create repository.
|
||||||
func NewRepoAction(user *User, repo *Repository) error {
|
func NewRepoAction(user *User, repo *Repository) error {
|
||||||
|
|
|
@ -50,6 +50,7 @@ type Watch struct {
|
||||||
UserId int64 `xorm:"UNIQUE(watch)"`
|
UserId int64 `xorm:"UNIQUE(watch)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch or unwatch repository.
|
||||||
func WatchRepo(userId, repoId int64, watch bool) (err error) {
|
func WatchRepo(userId, repoId int64, watch bool) (err error) {
|
||||||
if watch {
|
if watch {
|
||||||
_, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId})
|
_, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId})
|
||||||
|
@ -59,6 +60,13 @@ func WatchRepo(userId, repoId int64, watch bool) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWatches returns all watches of given repository.
|
||||||
|
func GetWatches(repoId int64) ([]Watch, error) {
|
||||||
|
watches := make([]Watch, 0, 10)
|
||||||
|
err := orm.Find(&watches, &Watch{RepoId: repoId})
|
||||||
|
return watches, err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gitInitLocker = sync.Mutex{}
|
gitInitLocker = sync.Mutex{}
|
||||||
LanguageIgns, Licenses []string
|
LanguageIgns, Licenses []string
|
||||||
|
|
Loading…
Reference in New Issue