if err != nil {
return err
}
- _, err = orm.InsertOne(&Action{
- UserId: userId,
- ActUserId: userId,
- ActUserName: userName,
- OpType: OP_COMMIT_REPO,
- Content: string(bs),
- RepoId: repoId,
- RepoName: repoName,
- })
- 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{
+ UserId: watches[i].UserId,
+ ActUserId: userId,
+ ActUserName: userName,
+ OpType: OP_COMMIT_REPO,
+ Content: string(bs),
+ RepoId: repoId,
+ RepoName: repoName,
+ })
+ return err
+ }
+ return nil
}
// NewRepoAction records action for create repository.
UserId int64 `xorm:"UNIQUE(watch)"`
}
+// Watch or unwatch repository.
func WatchRepo(userId, repoId int64, watch bool) (err error) {
if watch {
_, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId})
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 (
gitInitLocker = sync.Mutex{}
LanguageIgns, Licenses []string