summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar f0x52 <f0x@cthu.lu>2022-06-21 10:48:42 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-21 10:48:42 +0200
commit7c6c0cd547f356d5309bda2478a69ea9346c74b6 (patch)
treeacc2d165a17626a4264b5765464b7ab895725f32 /internal
parent[bugfix] Account self finger fix (#658) (diff)
downloadgotosocial-7c6c0cd547f356d5309bda2478a69ea9346c74b6.tar.xz
[frontend] Profile pages upgrade (#640)
* fix css indentation * profile styling update * update status styling to match profile * empty header fix * generate random avatars for thread views * appease the linter gods * upgrade deps * turn profile accent into border + $bg background * upgrade deps * small accessibility tweaks Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/web/thread.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/web/thread.go b/internal/web/thread.go
index 3db4952c7..d3b92bde3 100644
--- a/internal/web/thread.go
+++ b/internal/web/thread.go
@@ -23,6 +23,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "math/rand"
"net/http"
"strings"
@@ -35,6 +36,21 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
+var randAvatars = make(map[string]string)
+
+func (m *Module) ensureAvatar(status apimodel.Status) {
+ if status.Account.Avatar == "" && len(m.defaultAvatars) > 0 {
+ avatar, ok := randAvatars[status.Account.ID]
+ if !ok {
+ //nolint:gosec
+ randomIndex := rand.Intn(len(m.defaultAvatars))
+ avatar = m.defaultAvatars[randomIndex]
+ randAvatars[status.Account.ID] = avatar
+ }
+ status.Account.Avatar = avatar
+ }
+}
+
func (m *Module) threadGETHandler(c *gin.Context) {
ctx := c.Request.Context()
@@ -104,6 +120,16 @@ func (m *Module) threadGETHandler(c *gin.Context) {
return
}
+ m.ensureAvatar(*status)
+
+ for _, status := range context.Descendants {
+ m.ensureAvatar(status)
+ }
+
+ for _, status := range context.Ancestors {
+ m.ensureAvatar(status)
+ }
+
c.HTML(http.StatusOK, "thread.tmpl", gin.H{
"instance": instance,
"status": status,