]> source.dussan.org Git - gitea.git/commitdiff
Finish watch backend
authorUnknown <joe2010xtmf@163.com>
Thu, 20 Mar 2014 03:39:00 +0000 (23:39 -0400)
committerUnknown <joe2010xtmf@163.com>
Thu, 20 Mar 2014 03:39:00 +0000 (23:39 -0400)
models/action.go
models/repo.go

index d388bca991e8e8a8d417834bd7eecab234e691f3..b3be093533c91736d055a2ebc2ce7c035aa0208c 100644 (file)
@@ -55,16 +55,27 @@ func CommitRepoAction(userId int64, userName string,
        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.
index 187862fe27f5f9a99c3d6c395ff860427a50453f..fa6d97021bbeee49c80ede72295eb131abe8febd 100644 (file)
@@ -50,6 +50,7 @@ type Watch struct {
        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})
@@ -59,6 +60,13 @@ func WatchRepo(userId, repoId int64, watch bool) (err error) {
        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