Browse Source

profile: use name or fallback for profile page

Torkel Ödegaard 8 years ago
parent
commit
2797e8e2d0
2 changed files with 12 additions and 2 deletions
  1. 2 2
      pkg/api/index.go
  2. 10 0
      pkg/models/user.go

+ 2 - 2
pkg/api/index.go

@@ -120,8 +120,8 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
 
 	if c.IsSignedIn {
 		profileNode := &dtos.NavLink{
-			Text:         c.SignedInUser.Login,
-			SubTitle:     c.SignedInUser.Name,
+			Text:         c.SignedInUser.NameOrFallback(),
+			SubTitle:     c.SignedInUser.Login,
 			Id:           "profile",
 			Img:          data.User.GravatarUrl,
 			Url:          setting.AppSubUrl + "/profile",

+ 10 - 0
pkg/models/user.go

@@ -170,6 +170,16 @@ func (u *SignedInUser) ShouldUpdateLastSeenAt() bool {
 	return u.UserId > 0 && time.Since(u.LastSeenAt) > time.Minute*5
 }
 
+func (u *SignedInUser) NameOrFallback() string {
+	if u.Name != "" {
+		return u.Name
+	} else if u.Login != "" {
+		return u.Login
+	} else {
+		return u.Email
+	}
+}
+
 type UpdateUserLastSeenAtCommand struct {
 	UserId int64
 }