Show empty avatar when the user was not found

This commit is contained in:
kolaente 2021-04-07 14:56:44 +02:00
parent 325dcc5795
commit cb0df3ebbc
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -62,14 +62,13 @@ func GetAvatar(c echo.Context) error {
// Get the user // Get the user
u, err := user.GetUserWithEmail(s, &user.User{Username: username}) u, err := user.GetUserWithEmail(s, &user.User{Username: username})
if err != nil { if err != nil && !user.IsErrUserDoesNotExist(err) {
log.Errorf("Error getting user for avatar: %v", err) log.Errorf("Error getting user for avatar: %v", err)
return handler.HandleHTTPError(err, c) return handler.HandleHTTPError(err, c)
} }
// Initialize the avatar provider found := !(err != nil && user.IsErrUserDoesNotExist(err))
// For now, we only have one avatar provider, in the future there could be multiple which
// could be changed based on user settings etc.
var avatarProvider avatar.Provider var avatarProvider avatar.Provider
switch u.AvatarProvider { switch u.AvatarProvider {
case "gravatar": case "gravatar":
@ -82,6 +81,10 @@ func GetAvatar(c echo.Context) error {
avatarProvider = &empty.Provider{} avatarProvider = &empty.Provider{}
} }
if !found {
avatarProvider = &empty.Provider{}
}
size := c.QueryParam("size") size := c.QueryParam("size")
var sizeInt int64 = 250 // Default size of 250 var sizeInt int64 = 250 // Default size of 250
if size != "" { if size != "" {