From 296b5a30b8d3b8fd31dda3b9f32ffe88fb10b36a Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Mon, 13 Feb 2023 22:31:50 -0800 Subject: [PATCH] Spit and polish for Shy Accounts * Add a Shy/Non-shy badge to user profile pages. * Shy Accounts can always DM admin users. --- pkg/controller/inbox/compose.go | 3 ++- pkg/templates/template_funcs.go | 6 ++++++ web/templates/account/profile.html | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/controller/inbox/compose.go b/pkg/controller/inbox/compose.go index 08babcc..1de6010 100644 --- a/pkg/controller/inbox/compose.go +++ b/pkg/controller/inbox/compose.go @@ -73,9 +73,10 @@ func Compose() http.HandlerFunc { // Do not allow a shy user to initiate DMs with a non-shy one. var ( imShy = currentUser.IsShy() + theyreShy = user.IsShy() isShyFrom = currentUser.IsShyFrom(user) || (imShy && !models.AreFriends(currentUser.ID, user.ID)) ) - if imShy && isShyFrom { + if imShy && isShyFrom && !theyreShy && !user.IsAdmin { session.FlashError(w, r, "You have a Shy Account and can not initiate Direct Messages with a non-shy member.") templates.Redirect(w, "/u/"+user.Username) return diff --git a/pkg/templates/template_funcs.go b/pkg/templates/template_funcs.go index 7423b2b..851c36f 100644 --- a/pkg/templates/template_funcs.go +++ b/pkg/templates/template_funcs.go @@ -38,6 +38,12 @@ func TemplateFuncs(r *http.Request) template.FuncMap { `shy`, )) }, + "PrettyTitleShort": func() template.HTML { + return template.HTML(fmt.Sprintf( + `n` + + `s`, + )) + }, "Pluralize": Pluralize[int], "Pluralize64": Pluralize[int64], "PluralizeU64": Pluralize[uint64], diff --git a/web/templates/account/profile.html b/web/templates/account/profile.html index 4df9e8b..e97ef25 100644 --- a/web/templates/account/profile.html +++ b/web/templates/account/profile.html @@ -88,6 +88,22 @@ {{end}} + {{if .User.IsShy}} +
+
+ + + + Shy Account +
+
+ {{else}} +
+ {{PrettyTitleShort}} + Non-shy! +
+ {{end}} + {{if .User.IsAdmin}}