18
18
use OCP \IL10N ;
19
19
use OCP \IURLGenerator ;
20
20
use OCP \IUserManager ;
21
+ use OCP \Profile \IProfileManager ;
21
22
22
23
class ProfilePickerReferenceProvider extends ADiscoverableReferenceProvider {
23
24
public const RICH_OBJECT_TYPE = 'users_picker_profile ' ;
@@ -27,6 +28,7 @@ public function __construct(
27
28
private IURLGenerator $ urlGenerator ,
28
29
private IUserManager $ userManager ,
29
30
private IAccountManager $ accountManager ,
31
+ private IProfileManager $ profileManager ,
30
32
private ?string $ userId ,
31
33
) {
32
34
}
@@ -74,6 +76,8 @@ public function resolveReference(string $referenceText): ?IReference {
74
76
return null ;
75
77
}
76
78
79
+ $ currentUser = $ this ->userManager ->get ($ this ->userId );
80
+
77
81
$ userId = $ this ->getObjectId ($ referenceText );
78
82
$ user = $ this ->userManager ->get ($ userId );
79
83
if ($ user === null ) {
@@ -91,8 +95,17 @@ public function resolveReference(string $referenceText): ?IReference {
91
95
$ userEmail = $ user ->getEMailAddress ();
92
96
$ userAvatarUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.avatar.getAvatar ' , ['userId ' => $ userId , 'size ' => '64 ' ]);
93
97
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
+ }
96
109
$ headline = $ account ->getProperty (IAccountManager::PROPERTY_HEADLINE );
97
110
$ location = $ account ->getProperty (IAccountManager::PROPERTY_ADDRESS );
98
111
$ website = $ account ->getProperty (IAccountManager::PROPERTY_WEBSITE );
@@ -104,6 +117,8 @@ public function resolveReference(string $referenceText): ?IReference {
104
117
$ reference ->setDescription ($ userEmail ?? $ userDisplayName );
105
118
$ reference ->setImageUrl ($ userAvatarUrl );
106
119
120
+ $ isLocationVisible = $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ADDRESS , $ user , $ currentUser );
121
+
107
122
// for the Vue reference widget
108
123
$ reference ->setRichObject (
109
124
self ::RICH_OBJECT_TYPE ,
@@ -112,18 +127,14 @@ public function resolveReference(string $referenceText): ?IReference {
112
127
'title ' => $ userDisplayName ,
113
128
'subline ' => $ userEmail ?? $ userDisplayName ,
114
129
'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 ,
127
138
'url ' => $ referenceText ,
128
139
]
129
140
);
0 commit comments