]> source.dussan.org Git - gitea.git/commitdiff
Fix Gravatar images in web view (like commit listing)
authorAndrew Burns <ErebusBat@gmail.com>
Fri, 5 Dec 2014 18:02:59 +0000 (11:02 -0700)
committerAndrew Burns <ErebusBat@gmail.com>
Fri, 5 Dec 2014 18:02:59 +0000 (11:02 -0700)
Related to #700

In the original bug report it was referencing only the sytem avatar images for setup users (like in the header); however the problem also persists with things like commit history.

This commit fixes the `tool.AvatarLink` function so that it also uses the already existing `avatar.HashEmail` function.

I also refactored the `tool.AvatarLink` method some to make the control flow more apparent and adhere better to DRY (there were multiple calls to the `EncodeMd5` function that the `HashEmail` function call replaced, now there is only one.)

modules/base/tool.go

index 0e083c8d0cb6815f587b1f1d8c58fb17b7c94439..14c0e7d086727aea7539da902f88bdc19c81c1ff 100644 (file)
@@ -23,6 +23,7 @@ import (
        "github.com/Unknwon/com"
        "github.com/Unknwon/i18n"
 
+       "github.com/gogits/gogs/modules/avatar"
        "github.com/gogits/gogs/modules/setting"
 )
 
@@ -177,10 +178,13 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
 func AvatarLink(email string) string {
        if setting.DisableGravatar {
                return setting.AppSubUrl + "/img/avatar_default.jpg"
-       } else if setting.Service.EnableCacheAvatar {
-               return setting.AppSubUrl + "/avatar/" + EncodeMd5(email)
        }
-       return setting.GravatarSource + EncodeMd5(email)
+
+       gravatarHash := avatar.HashEmail(email)
+       if setting.Service.EnableCacheAvatar {
+               return setting.AppSubUrl + "/avatar/" + gravatarHash
+       }
+       return setting.GravatarSource + gravatarHash
 }
 
 // Seconds-based time units