feat(user): use name for initals avatar, not username

For external auth providers, the username might be randomly generated,
which results in a random initial - this is unexpected and confusing for
users.
This commit is contained in:
kolaente
2025-06-27 14:13:49 +02:00
parent 4f8a2b0d38
commit 99bc065272
2 changed files with 5 additions and 1 deletions

View File

@@ -143,7 +143,7 @@ func getAvatarForUser(u *user.User) (fullSizeAvatar *image.RGBA64, err error) {
if !exists {
log.Debugf("Initials avatar for user %d not cached, creating...", u.ID)
firstRune := []rune(strings.ToUpper(u.Username))[0]
firstRune := []rune(strings.ToUpper(u.Name))[0]
bg := avatarBgColors[int(u.ID)%len(avatarBgColors)] // Random color based on the user id
fullSizeAvatar, err = drawImage(firstRune, bg)

View File

@@ -144,6 +144,10 @@ func ChangeUserAvatarProvider(c echo.Context) error {
return handler.HandleHTTPError(err)
}
if user.AvatarProvider == "initials" {
avatar.FlushAllCaches(user)
}
if err := s.Commit(); err != nil {
_ = s.Rollback()
return handler.HandleHTTPError(err)