]> source.dussan.org Git - gitea.git/commitdiff
Show the username as a fallback on feeds if full name is blank (#10461)
authorJames Lakin <jamesorlakin@users.noreply.github.com>
Thu, 27 Feb 2020 01:59:07 +0000 (01:59 +0000)
committerGitHub <noreply@github.com>
Thu, 27 Feb 2020 01:59:07 +0000 (20:59 -0500)
Co-authored-by: Lauris BH <lauris@nix.lv>
models/action.go
models/user.go

index 3bc88f006321b6ba0aa026d2f7d9ab3a54593b3b..cd722cbe7ce2dc21509f857b4c5b88e45006188f 100644 (file)
@@ -122,10 +122,13 @@ func (a *Action) ShortActUserName() string {
        return base.EllipsisString(a.GetActUserName(), 20)
 }
 
-// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME
+// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
 func (a *Action) GetDisplayName() string {
        if setting.UI.DefaultShowFullName {
-               return a.GetActFullName()
+               trimmedFullName := strings.TrimSpace(a.GetActFullName())
+               if len(trimmedFullName) > 0 {
+                       return trimmedFullName
+               }
        }
        return a.ShortActUserName()
 }
index d8c0fcf47dc658359b6c24d164a0e7b6e6b2652f..4cc14664db70c45afbe13ba92d78423ec0c9a9d4 100644 (file)
@@ -712,9 +712,11 @@ func (u *User) DisplayName() string {
 // GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set,
 // returns username otherwise.
 func (u *User) GetDisplayName() string {
-       trimmed := strings.TrimSpace(u.FullName)
-       if len(trimmed) > 0 && setting.UI.DefaultShowFullName {
-               return trimmed
+       if setting.UI.DefaultShowFullName {
+               trimmed := strings.TrimSpace(u.FullName)
+               if len(trimmed) > 0 {
+                       return trimmed
+               }
        }
        return u.Name
 }