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

index fa6d97021bbeee49c80ede72295eb131abe8febd..edf800bd70438de66e1150d30f78dff7d84785c6 100644 (file)
@@ -67,6 +67,12 @@ func GetWatches(repoId int64) ([]Watch, error) {
        return watches, err
 }
 
+// IsWatching checks if user has watched given repository.
+func IsWatching(userId, repoId int64) bool {
+       has, _ := orm.Get(&Watch{0, repoId, userId})
+       return has
+}
+
 var (
        gitInitLocker          = sync.Mutex{}
        LanguageIgns, Licenses []string
index c97c3299c48b4bc6a01e68378a3b3e53fecec73a..dfa39c6f86164729ecc2d57badb1be3f3ad06933 100644 (file)
@@ -31,6 +31,7 @@ type Context struct {
        Repo struct {
                IsValid    bool
                IsOwner    bool
+               IsWatching bool
                Repository *models.Repository
                Owner      *models.User
        }
index a12212affa96a047a5c2ba11d2e62cda89a1c462..e03ddc50a631c1501bf958bf9dd9a18f8a3815a9 100644 (file)
@@ -63,6 +63,7 @@ func RepoAssignment(redirect bool) martini.Handler {
                }
 
                ctx.Repo.IsValid = true
+               ctx.Repo.IsWatching = models.IsWatching(ctx.User.Id, repo.Id)
                ctx.Repo.Repository = repo
 
                ctx.Data["IsRepositoryValid"] = true