From 06673cbccb9ecb7682185fade8cfc4ee21cac64f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 3 Jan 2021 01:21:39 +0000 Subject: [PATCH] Fix avatar bugs (#14217) (#14220) Co-authored-by: Lunny Xiao --- models/user_avatar.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/models/user_avatar.go b/models/user_avatar.go index 2f9db5c2e2..4305554bf6 100644 --- a/models/user_avatar.go +++ b/models/user_avatar.go @@ -40,10 +40,9 @@ func (u *User) generateRandomAvatar(e Engine) error { return fmt.Errorf("RandomImage: %v", err) } - if u.Avatar == "" { - u.Avatar = base.HashEmail(u.AvatarEmail) - } + u.Avatar = base.HashEmail(seed) + // Don't share the images so that we can delete them easily if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error { if err := png.Encode(w, img); err != nil { log.Error("Encode: %v", err) @@ -133,7 +132,7 @@ func (u *User) UploadAvatar(data []byte) error { // Otherwise, if any of the users delete his avatar // Other users will lose their avatars too. u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data))))) - if err = updateUser(sess, u); err != nil { + if err = updateUserCols(sess, u, "use_custom_avatar", "avatar"); err != nil { return fmt.Errorf("updateUser: %v", err) }