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 }}
- {{ if .Author }} -
- -
-
-
-
- {{ .Author.Username }} {{/* TODO: Text scale stuff? Seems unnecessary. */}} - -
- {{ if .Author.IsStaff }} -
- {{ end }} -
-
- {{ if and .Author.Name (ne .Author.Name .Author.Username) }} -
{{ .Author.Name }}
- {{ end }} - -
-
-
- {{/* TODO: Aggregate user data -
- {{ post.author.posts }} posts - {% if post.author.public_projects.values|length > 0 %} - / {{ post.author.public_projects.values|length }} project{%if post.author.public_projects.values|length > 1 %}s{% endif %} - {% endif %} -
*/}} - -
+
+ +
+
+
+
+ {{ .Author.Username }} {{/* TODO: Text scale stuff? Seems unnecessary. */}} + +
{{ if .Author.IsStaff }}
{{ end }}
-
- {{ if .Author.Blurb }} - {{ .Author.Blurb }} {{/* TODO: Linebreaks? */}} - {{ else if .Author.Bio }} - {{ .Author.Bio }} - {{ end }} -
- {{ else }} -
Deleted member
-
- {{ end }} + {{ if and .Author.Name (ne .Author.Name .Author.Username) }} +
{{ .Author.Name }}
+ {{ end }} + +
+
+
+ {{/* TODO: Aggregate user data +
+ {{ post.author.posts }} posts + {% if post.author.public_projects.values|length > 0 %} + / {{ post.author.public_projects.values|length }} project{%if post.author.public_projects.values|length > 1 %}s{% endif %} + {% endif %} +
*/}} + +
+ {{ if .Author.IsStaff }} +
+ {{ end }} +
+
+ {{ if .Author.Blurb }} + {{ .Author.Blurb }} {{/* TODO: Linebreaks? */}} + {{ else if .Author.Bio }} + {{ .Author.Bio }} + {{ end }} +
+
diff --git a/src/templates/types.go b/src/templates/types.go index 968c3ae..626b614 100644 --- a/src/templates/types.go +++ b/src/templates/types.go @@ -77,7 +77,7 @@ type Post struct { Preview string ReadOnly bool - Author *User + Author User Content template.HTML PostDate time.Time