From c4600ff6cef896fbaf572070b686473f717cceb1 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 12 Feb 2023 22:23:51 -0800 Subject: [PATCH] Use anonymized avatars in chat for non-public profile pics --- pkg/controller/chat/chat.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/controller/chat/chat.go b/pkg/controller/chat/chat.go index e60e6e9..3756c73 100644 --- a/pkg/controller/chat/chat.go +++ b/pkg/controller/chat/chat.go @@ -7,6 +7,7 @@ import ( "time" "code.nonshy.com/nonshy/website/pkg/config" + "code.nonshy.com/nonshy/website/pkg/models" "code.nonshy.com/nonshy/website/pkg/photo" "code.nonshy.com/nonshy/website/pkg/session" "code.nonshy.com/nonshy/website/pkg/templates" @@ -51,10 +52,19 @@ func Landing() http.HandlerFunc { return } + // Avatar URL - masked if non-public. + avatar := photo.URLPath(currentUser.ProfilePhoto.CroppedFilename) + switch currentUser.ProfilePhoto.Visibility { + case models.PhotoPrivate: + avatar = "/static/img/shy-private.png" + case models.PhotoFriends: + avatar = "/static/img/shy-friends.png" + } + // Create the JWT claims. claims := Claims{ IsAdmin: currentUser.IsAdmin, - Avatar: photo.URLPath(currentUser.ProfilePhoto.CroppedFilename), + Avatar: avatar, ProfileURL: "/u/" + currentUser.Username, RegisteredClaims: jwt.RegisteredClaims{ // TODO: ExpiresAt 60 minutes to work around chat server reliability,