Use anonymized avatars in chat for non-public profile pics

This commit is contained in:
Noah Petherbridge 2023-02-12 22:23:51 -08:00
parent 5e3e02ee33
commit c4600ff6ce

View File

@ -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,