diff --git a/src/templates/mapping.go b/src/templates/mapping.go index 289f62f..78eaf9d 100644 --- a/src/templates/mapping.go +++ b/src/templates/mapping.go @@ -12,12 +12,6 @@ import ( ) func PostToTemplate(p *models.Post, author *models.User, currentTheme string) Post { - var authorUser *User - if author != nil { - authorTmpl := UserToTemplate(author, currentTheme) - authorUser = &authorTmpl - } - return Post{ ID: p.ID, @@ -26,7 +20,7 @@ func PostToTemplate(p *models.Post, author *models.User, currentTheme string) Po Preview: p.Preview, ReadOnly: p.ReadOnly, - Author: authorUser, + Author: UserToTemplate(author, currentTheme), // No content. A lot of the time we don't have this handy and don't need it. See AddContentVersion. PostDate: p.PostDate, } @@ -131,7 +125,7 @@ func UserAvatarUrl(u *models.User, currentTheme string) string { currentTheme = "light" } avatar := "" - if u.Avatar != nil && len(*u.Avatar) > 0 { + if u != nil && u.Avatar != nil && len(*u.Avatar) > 0 { avatar = hmnurl.BuildUserFile(*u.Avatar) } else { avatar = hmnurl.BuildTheme("empty-avatar.svg", currentTheme, true) @@ -148,7 +142,12 @@ func UserDisplayName(u *models.User) string { } func UserToTemplate(u *models.User, currentTheme string) User { - // TODO: Handle deleted users. Maybe not here, but if not, at call sites of this function. + if u == nil { + return User{ + Name: "Deleted user", + AvatarUrl: UserAvatarUrl(u, currentTheme), + } + } email := "" if u.ShowEmail { diff --git a/src/templates/src/forum_thread.html b/src/templates/src/forum_thread.html index 6364feb..d270e5c 100644 --- a/src/templates/src/forum_thread.html +++ b/src/templates/src/forum_thread.html @@ -9,53 +9,48 @@ {{ range .Posts }}