Skip to content

Commit 06673cb

Browse files
6543lunny
andauthored
Fix avatar bugs (#14217) (#14220)
Co-authored-by: Lunny Xiao <[email protected]>
1 parent 2fd708a commit 06673cb

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

models/user_avatar.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ func (u *User) generateRandomAvatar(e Engine) error {
4040
return fmt.Errorf("RandomImage: %v", err)
4141
}
4242

43-
if u.Avatar == "" {
44-
u.Avatar = base.HashEmail(u.AvatarEmail)
45-
}
43+
u.Avatar = base.HashEmail(seed)
4644

45+
// Don't share the images so that we can delete them easily
4746
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
4847
if err := png.Encode(w, img); err != nil {
4948
log.Error("Encode: %v", err)
@@ -133,7 +132,7 @@ func (u *User) UploadAvatar(data []byte) error {
133132
// Otherwise, if any of the users delete his avatar
134133
// Other users will lose their avatars too.
135134
u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
136-
if err = updateUser(sess, u); err != nil {
135+
if err = updateUserCols(sess, u, "use_custom_avatar", "avatar"); err != nil {
137136
return fmt.Errorf("updateUser: %v", err)
138137
}
139138

0 commit comments

Comments
 (0)