Lazy compute UserRelationships on CanSeeProfilePicture function

face-detect
Noah Petherbridge 2024-01-07 14:25:00 -08:00
parent 8fca36836c
commit 7a6b21fee5
2 changed files with 5 additions and 0 deletions

View File

@ -559,6 +559,10 @@ func (u *User) VisibleAvatarURL(currentUser *User) string {
//
// If the user has no profile photo, returns (false, PhotoPublic) which should manifest as the blue shy.png placeholder image.
func (u *User) CanSeeProfilePicture(currentUser *User) (bool, PhotoVisibility) {
if !u.UserRelationship.Computed {
SetUserRelationships(currentUser, []*User{u})
}
visibility := u.ProfilePhoto.Visibility
if visibility == PhotoPrivate && !u.UserRelationship.IsPrivateGranted {
// Private photo

View File

@ -5,6 +5,7 @@ package models
// The zero-values should fail safely: in case the UserRelationship isn't populated correctly,
// private profile pics show as private by default.
type UserRelationship struct {
Computed bool // check whether the SetUserRelationships function has been run
IsFriend bool // if true, a friends-only profile pic can show
IsPrivateGranted bool // if true, a private profile pic can show
IsInnerCirclePeer bool // if true, the current user is in the inner circle so may see circle-only profile picture