From fc63422cafe48b055bea52f7cc03fca0d8e0fef1 Mon Sep 17 00:00:00 2001 From: James Anderson Date: Sat, 8 Aug 2015 17:16:11 -0500 Subject: [PATCH 1/6] Add check to see if comments on an issue are by the repo owner --- templates/repo/issue/view.tmpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/repo/issue/view.tmpl b/templates/repo/issue/view.tmpl index 61adfe619..2889856f3 100644 --- a/templates/repo/issue/view.tmpl +++ b/templates/repo/issue/view.tmpl @@ -69,7 +69,9 @@ {{.Poster.Name}} commented {{TimeSince .Created $.Lang}} + {{if eq .Poster.Id $.Owner.Id}} Owner + {{end}}
{{if len .Content}} From aede5cdb04fdbf74d9c602062fdece9f408e90f4 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 9 Aug 2015 10:18:35 +0800 Subject: [PATCH 2/6] fix app suburl in feeds --- gogs.go | 2 +- templates/.VERSION | 2 +- templates/user/dashboard/feeds.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gogs.go b/gogs.go index ad52f2552..df6b58366 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.6.4.0808 Beta" +const APP_VER = "0.6.4.0809 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/templates/.VERSION b/templates/.VERSION index 1fd1eb741..b039250bc 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.6.4.0808 Beta \ No newline at end of file +0.6.4.0809 Beta \ No newline at end of file diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 47b55693f..d2e66b308 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -30,7 +30,7 @@ {{range $push.Commits}}
  • {{ShortSha .Sha1}} {{.Message}}
  • {{end}} - {{if $push.CompareUrl}}
  • {{$.i18n.Tr "action.compare_2_commits"}} »
  • {{end}} + {{if $push.CompareUrl}}
  • {{$.i18n.Tr "action.compare_2_commits"}} »
  • {{end}}
    {{else if eq .GetOpType 6}} From 4b43ffc96cf16cd49b5796feca8ad853f3e3a8ee Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 9 Aug 2015 11:46:10 +0800 Subject: [PATCH 3/6] Generate random avatar based on e-mail when disable Gravatar --- .gopmfile | 1 + models/user.go | 32 +++++++++++++++++++++++++++++++- modules/avatar/avatar.go | 24 ++++++++++++++++++++++++ templates/repo/pulls/fork.tmpl | 6 +++--- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/.gopmfile b/.gopmfile index d59b474ee..ad090603e 100644 --- a/.gopmfile +++ b/.gopmfile @@ -14,6 +14,7 @@ github.com/go-xorm/core = github.com/go-xorm/xorm = github.com/gogits/chardet = commit:2404f77725 github.com/gogits/go-gogs-client = commit:92e76d616a +github.com/issue9/identicon = github.com/lib/pq = commit:0dad96c0b9 github.com/macaron-contrib/binding = commit:de6ed78668 github.com/macaron-contrib/cache = commit:cd824f6f2d diff --git a/models/user.go b/models/user.go index 6dd31536f..65b23f791 100644 --- a/models/user.go +++ b/models/user.go @@ -13,7 +13,9 @@ import ( "fmt" "image" "image/jpeg" + _ "image/jpeg" "os" + "path" "path/filepath" "strings" "time" @@ -116,11 +118,39 @@ func (u *User) HomeLink() string { // AvatarLink returns user gravatar link. func (u *User) AvatarLink() string { + defaultImgUrl := setting.AppSubUrl + "/img/avatar_default.jpg" + imgPath := path.Join(setting.AvatarUploadPath, com.ToStr(u.Id)) switch { case u.UseCustomAvatar: + if !com.IsExist(imgPath) { + return defaultImgUrl + } return setting.AppSubUrl + "/avatars/" + com.ToStr(u.Id) case setting.DisableGravatar, setting.OfflineMode: - return setting.AppSubUrl + "/img/avatar_default.jpg" + if !com.IsExist(imgPath) { + img, err := avatar.RandomImage([]byte(u.Email)) + if err != nil { + log.Error(3, "RandomImage: %v", err) + return defaultImgUrl + } + if err = os.MkdirAll(path.Dir(imgPath), os.ModePerm); err != nil { + log.Error(3, "Create: %v", err) + return defaultImgUrl + } + fw, err := os.Create(imgPath) + if err != nil { + log.Error(3, "Create: %v", err) + return defaultImgUrl + } + defer fw.Close() + + if err = jpeg.Encode(fw, img, nil); err != nil { + log.Error(3, "Encode: %v", err) + return defaultImgUrl + } + } + + return setting.AppSubUrl + "/avatars/" + com.ToStr(u.Id) case setting.Service.EnableCacheAvatar: return setting.AppSubUrl + "/avatar/" + u.Avatar } diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 73daa213c..5aef6e02c 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -19,9 +19,11 @@ import ( "errors" "fmt" "image" + "image/color/palette" "image/jpeg" "image/png" "io" + "math/rand" "net/http" "net/url" "os" @@ -30,6 +32,7 @@ import ( "sync" "time" + "github.com/issue9/identicon" "github.com/nfnt/resize" "github.com/gogits/gogs/modules/log" @@ -59,6 +62,27 @@ func HashEmail(email string) string { return hex.EncodeToString(h.Sum(nil)) } +const _RANDOM_AVATAR_SIZE = 200 + +// RandomImage generates and returns a random avatar image. +func RandomImage(data []byte) (image.Image, error) { + randExtent := len(palette.WebSafe) - 32 + rand.Seed(time.Now().UnixNano()) + colorIndex := rand.Intn(randExtent) + backColorIndex := colorIndex - 1 + if backColorIndex < 0 { + backColorIndex = randExtent - 1 + } + + // Size, background, forecolor + imgMaker, err := identicon.New(_RANDOM_AVATAR_SIZE, + palette.WebSafe[backColorIndex], palette.WebSafe[colorIndex:colorIndex+32]...) + if err != nil { + return nil, err + } + return imgMaker.Make(data), nil +} + // Avatar represents the avatar object. type Avatar struct { Hash string diff --git a/templates/repo/pulls/fork.tmpl b/templates/repo/pulls/fork.tmpl index 2f76cf002..01bbe9b79 100644 --- a/templates/repo/pulls/fork.tmpl +++ b/templates/repo/pulls/fork.tmpl @@ -14,19 +14,19 @@