Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ignore gravatar error #2083

Merged
merged 3 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,14 @@ func (u *User) generateRandomAvatar(e Engine) error {
// which includes app sub-url as prefix. However, it is possible
// to return full URL if user enables Gravatar-like service.
func (u *User) RelAvatarLink() string {
defaultImgURL := setting.AppSubURL + "/img/avatar_default.png"
if u.ID == -1 {
return defaultImgURL
return base.DefaultAvatarLink()
}

switch {
case u.UseCustomAvatar:
if !com.IsFile(u.CustomAvatarPath()) {
return defaultImgURL
return base.DefaultAvatarLink()
}
return setting.AppSubURL + "/avatars/" + u.Avatar
case setting.DisableGravatar, setting.OfflineMode:
Expand Down
14 changes: 11 additions & 3 deletions modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,29 @@ func HashEmail(email string) string {
return EncodeMD5(strings.ToLower(strings.TrimSpace(email)))
}

// DefaultAvatarLink the default avatar link
func DefaultAvatarLink() string {
return setting.AppSubURL + "/img/avatar_default.png"
}

// AvatarLink returns relative avatar link to the site domain by given email,
// which includes app sub-url as prefix. However, it is possible
// to return full URL if user enables Gravatar-like service.
func AvatarLink(email string) string {
if setting.EnableFederatedAvatar && setting.LibravatarService != nil {
// TODO: This doesn't check any error. AvatarLink should return (string, error)
url, _ := setting.LibravatarService.FromEmail(email)
url, err := setting.LibravatarService.FromEmail(email)
if err != nil {
log.Error(4, "LibravatarService.FromEmail(email=%s): error %v", email, err)
return DefaultAvatarLink()
}
return url
}

if !setting.DisableGravatar {
return setting.GravatarSource + HashEmail(email)
}

return setting.AppSubURL + "/img/avatar_default.png"
return DefaultAvatarLink()
}

// Seconds-based time units
Expand Down