diff --git a/models/repo.go b/models/repo.go index fa6d97021..edf800bd7 100644 --- a/models/repo.go +++ b/models/repo.go @@ -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 diff --git a/modules/middleware/context.go b/modules/middleware/context.go index c97c3299c..dfa39c6f8 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -31,6 +31,7 @@ type Context struct { Repo struct { IsValid bool IsOwner bool + IsWatching bool Repository *models.Repository Owner *models.User } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index a12212aff..e03ddc50a 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -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