1818use OCP \IL10N ;
1919use OCP \IURLGenerator ;
2020use OCP \IUserManager ;
21+ use OCP \Profile \IProfileManager ;
2122
2223class ProfilePickerReferenceProvider extends ADiscoverableReferenceProvider {
2324 public const RICH_OBJECT_TYPE = 'users_picker_profile ' ;
@@ -27,6 +28,7 @@ public function __construct(
2728 private IURLGenerator $ urlGenerator ,
2829 private IUserManager $ userManager ,
2930 private IAccountManager $ accountManager ,
31+ private IProfileManager $ profileManager ,
3032 private ?string $ userId ,
3133 ) {
3234 }
@@ -74,6 +76,8 @@ public function resolveReference(string $referenceText): ?IReference {
7476 return null ;
7577 }
7678
79+ $ currentUser = $ this ->userManager ->get ($ this ->userId );
80+
7781 $ userId = $ this ->getObjectId ($ referenceText );
7882 $ user = $ this ->userManager ->get ($ userId );
7983 if ($ user === null ) {
@@ -91,8 +95,17 @@ public function resolveReference(string $referenceText): ?IReference {
9195 $ userEmail = $ user ->getEMailAddress ();
9296 $ userAvatarUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.avatar.getAvatar ' , ['userId ' => $ userId , 'size ' => '64 ' ]);
9397
94- $ bio = $ account ->getProperty (IAccountManager::PROPERTY_BIOGRAPHY );
95- $ bio = $ bio ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ bio ->getValue () : null ;
98+ $ bioProperty = $ account ->getProperty (IAccountManager::PROPERTY_BIOGRAPHY );
99+ $ bio = null ;
100+ $ fullBio = null ;
101+ if ($ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_BIOGRAPHY , $ user , $ currentUser )) {
102+ $ fullBio = $ bioProperty ->getValue ();
103+ $ bio = $ fullBio !== ''
104+ ? (mb_strlen ($ fullBio ) > 80
105+ ? (mb_substr ($ fullBio , 0 , 80 ) . '... ' )
106+ : $ fullBio )
107+ : null ;
108+ }
96109 $ headline = $ account ->getProperty (IAccountManager::PROPERTY_HEADLINE );
97110 $ location = $ account ->getProperty (IAccountManager::PROPERTY_ADDRESS );
98111 $ website = $ account ->getProperty (IAccountManager::PROPERTY_WEBSITE );
@@ -104,6 +117,8 @@ public function resolveReference(string $referenceText): ?IReference {
104117 $ reference ->setDescription ($ userEmail ?? $ userDisplayName );
105118 $ reference ->setImageUrl ($ userAvatarUrl );
106119
120+ $ isLocationVisible = $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ADDRESS , $ user , $ currentUser );
121+
107122 // for the Vue reference widget
108123 $ reference ->setRichObject (
109124 self ::RICH_OBJECT_TYPE ,
@@ -112,18 +127,14 @@ public function resolveReference(string $referenceText): ?IReference {
112127 'title ' => $ userDisplayName ,
113128 'subline ' => $ userEmail ?? $ userDisplayName ,
114129 'email ' => $ userEmail ,
115- 'bio ' => isset ($ bio ) && $ bio !== ''
116- ? (mb_strlen ($ bio ) > 80
117- ? (mb_substr ($ bio , 0 , 80 ) . '... ' )
118- : $ bio )
119- : null ,
120- 'full_bio ' => $ bio ,
121- 'headline ' => $ headline ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ headline ->getValue () : null ,
122- 'location ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ location ->getValue () : null ,
123- 'location_url ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ this ->getOpenStreetLocationUrl ($ location ->getValue ()) : null ,
124- 'website ' => $ website ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ website ->getValue () : null ,
125- 'organisation ' => $ organisation ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ organisation ->getValue () : null ,
126- 'role ' => $ role ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ role ->getValue () : null ,
130+ 'bio ' => $ bio ,
131+ 'full_bio ' => $ fullBio ,
132+ 'headline ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_HEADLINE , $ user , $ currentUser ) ? $ headline ->getValue () : null ,
133+ 'location ' => $ isLocationVisible ? $ location ->getValue () : null ,
134+ 'location_url ' => $ isLocationVisible ? $ this ->getOpenStreetLocationUrl ($ location ->getValue ()) : null ,
135+ 'website ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_WEBSITE , $ user , $ currentUser ) ? $ website ->getValue () : null ,
136+ 'organisation ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ORGANISATION , $ user , $ currentUser ) ? $ organisation ->getValue () : null ,
137+ 'role ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ROLE , $ user , $ currentUser ) ? $ role ->getValue () : null ,
127138 'url ' => $ referenceText ,
128139 ]
129140 );
0 commit comments