Lazy compute UserRelationships on CanSeeProfilePicture function
This commit is contained in:
parent
8fca36836c
commit
7a6b21fee5
|
@ -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.
|
// 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) {
|
func (u *User) CanSeeProfilePicture(currentUser *User) (bool, PhotoVisibility) {
|
||||||
|
if !u.UserRelationship.Computed {
|
||||||
|
SetUserRelationships(currentUser, []*User{u})
|
||||||
|
}
|
||||||
|
|
||||||
visibility := u.ProfilePhoto.Visibility
|
visibility := u.ProfilePhoto.Visibility
|
||||||
if visibility == PhotoPrivate && !u.UserRelationship.IsPrivateGranted {
|
if visibility == PhotoPrivate && !u.UserRelationship.IsPrivateGranted {
|
||||||
// Private photo
|
// Private photo
|
||||||
|
|
|
@ -5,6 +5,7 @@ package models
|
||||||
// The zero-values should fail safely: in case the UserRelationship isn't populated correctly,
|
// The zero-values should fail safely: in case the UserRelationship isn't populated correctly,
|
||||||
// private profile pics show as private by default.
|
// private profile pics show as private by default.
|
||||||
type UserRelationship struct {
|
type UserRelationship struct {
|
||||||
|
Computed bool // check whether the SetUserRelationships function has been run
|
||||||
IsFriend bool // if true, a friends-only profile pic can show
|
IsFriend bool // if true, a friends-only profile pic can show
|
||||||
IsPrivateGranted bool // if true, a private 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
|
IsInnerCirclePeer bool // if true, the current user is in the inner circle so may see circle-only profile picture
|
||||||
|
|
Loading…
Reference in New Issue
Block a user