44
55namespace OCA \UsersPicker \Reference ;
66
7- use OC \Collaboration \Reference \LinkReferenceProvider ;
7+ use OCA \UsersPicker \AppInfo \Application ;
8+ use OCP \Accounts \IAccountManager ;
9+
810use OCP \Collaboration \Reference \ADiscoverableReferenceProvider ;
11+ use OCP \Collaboration \Reference \IReference ;
912use OCP \Collaboration \Reference \Reference ;
1013
11- use OCP \Collaboration \Reference \IReference ;
12- use OCP \Contacts \IManager ;
1314use OCP \IL10N ;
1415use OCP \IURLGenerator ;
15-
16- use OCA \UsersPicker \AppInfo \Application ;
17- use OCP \Accounts \IAccountManager ;
1816use OCP \IUserManager ;
19- use Psr \ Log \ LoggerInterface ;
17+ use OCP \ Profile \ IProfileManager ;
2018
2119class ProfilePickerReferenceProvider extends ADiscoverableReferenceProvider {
22-
23- private const RICH_OBJECT_TYPE = Application::APP_ID . '_profile ' ;
24-
25- private ?string $ userId ;
26- private IL10N $ l10n ;
27- private IURLGenerator $ urlGenerator ;
28- private LinkReferenceProvider $ linkReferenceProvider ;
29- private IUserManager $ userManager ;
30- private IAccountManager $ accountManager ;
31- private IManager $ contactsManager ;
20+ public const RICH_OBJECT_TYPE = 'users_picker_profile ' ;
3221
3322 public function __construct (
34- IL10N $ l10n ,
35- IURLGenerator $ urlGenerator ,
36- LinkReferenceProvider $ linkReferenceProvider ,
37- IUserManager $ userManager ,
38- IAccountManager $ accountManager ,
39- IManager $ contactsManager ,
40- ?string $ userId ,
41- private LoggerInterface $ logger ,
23+ private IL10N $ l10n ,
24+ private IURLGenerator $ urlGenerator ,
25+ private IUserManager $ userManager ,
26+ private IAccountManager $ accountManager ,
27+ private IProfileManager $ profileManager ,
28+ private ?string $ userId ,
4229 ) {
43- $ this ->userId = $ userId ;
44- $ this ->l10n = $ l10n ;
45- $ this ->urlGenerator = $ urlGenerator ;
46- $ this ->linkReferenceProvider = $ linkReferenceProvider ;
47- $ this ->userManager = $ userManager ;
48- $ this ->accountManager = $ accountManager ;
49- $ this ->contactsManager = $ contactsManager ;
5030 }
5131
5232 /**
5333 * @inheritDoc
5434 */
55- public function getId (): string {
35+ public function getId (): string {
5636 return 'profile_picker ' ;
5737 }
5838
@@ -66,7 +46,7 @@ public function getTitle(): string {
6646 /**
6747 * @inheritDoc
6848 */
69- public function getOrder (): int {
49+ public function getOrder (): int {
7050 return 10 ;
7151 }
7252
@@ -94,32 +74,46 @@ public function resolveReference(string $referenceText): ?IReference {
9474
9575 $ userId = $ this ->getObjectId ($ referenceText );
9676 $ user = $ this ->userManager ->get ($ userId );
97- $ contacts = $ this ->contactsManager ->search ($ userId , ['UID ' , 'FN ' , 'EMAIL ' ], ['types ' => true ]);
98- $ this ->logger ->error ('Contancts: ' . json_encode ($ contacts ));
99-
10077 if ($ user === null ) {
101- return $ this ->linkReferenceProvider ->resolveReference ($ referenceText );
78+ return null ;
79+ }
80+ if (!$ this ->profileManager ->isProfileEnabled ($ user )) {
81+ return null ;
10282 }
83+ $ account = $ this ->accountManager ->getAccount ($ user );
84+
85+ $ currentUser = $ this ->userManager ->get ($ this ->userId );
10386
10487 $ reference = new Reference ($ referenceText );
10588
10689 $ userDisplayName = $ user ->getDisplayName ();
10790 $ userEmail = $ user ->getEMailAddress ();
10891 $ userAvatarUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.avatar.getAvatar ' , ['userId ' => $ userId , 'size ' => '64 ' ]);
10992
110- $ bio = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_BIOGRAPHY );
111- $ bio = $ bio ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ bio ->getValue () : null ;
112- $ headline = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_HEADLINE );
113- $ location = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ADDRESS );
114- $ website = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_WEBSITE );
115- $ organisation = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ORGANISATION );
116- $ role = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ROLE );
93+ $ bioProperty = $ account ->getProperty (IAccountManager::PROPERTY_BIOGRAPHY );
94+ $ bio = null ;
95+ $ fullBio = null ;
96+ if ($ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_BIOGRAPHY , $ user , $ currentUser )) {
97+ $ fullBio = $ bioProperty ->getValue ();
98+ $ bio = $ fullBio !== ''
99+ ? (mb_strlen ($ fullBio ) > 80
100+ ? (mb_substr ($ fullBio , 0 , 80 ) . '... ' )
101+ : $ fullBio )
102+ : null ;
103+ }
104+ $ headline = $ account ->getProperty (IAccountManager::PROPERTY_HEADLINE );
105+ $ location = $ account ->getProperty (IAccountManager::PROPERTY_ADDRESS );
106+ $ website = $ account ->getProperty (IAccountManager::PROPERTY_WEBSITE );
107+ $ organisation = $ account ->getProperty (IAccountManager::PROPERTY_ORGANISATION );
108+ $ role = $ account ->getProperty (IAccountManager::PROPERTY_ROLE );
117109
118110 // for clients who can't render the reference widgets
119111 $ reference ->setTitle ($ userDisplayName );
120112 $ reference ->setDescription ($ userEmail ?? $ userDisplayName );
121113 $ reference ->setImageUrl ($ userAvatarUrl );
122114
115+ $ isLocationVisible = $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ADDRESS , $ user , $ currentUser );
116+
123117 // for the Vue reference widget
124118 $ reference ->setRichObject (
125119 self ::RICH_OBJECT_TYPE ,
@@ -128,20 +122,21 @@ public function resolveReference(string $referenceText): ?IReference {
128122 'title ' => $ userDisplayName ,
129123 'subline ' => $ userEmail ?? $ userDisplayName ,
130124 'email ' => $ userEmail ,
131- 'bio ' => isset ($ bio ) && $ bio !== '' ? substr_replace ($ bio , '... ' , 80 , strlen ($ bio )) : null ,
132- 'headline ' => $ headline ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ headline ->getValue () : null ,
133- 'location ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ location ->getValue () : null ,
134- 'location_url ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ this ->getOpenStreetLocationUrl ($ location ->getValue ()) : null ,
135- 'website ' => $ website ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ website ->getValue () : null ,
136- 'organisation ' => $ organisation ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ organisation ->getValue () : null ,
137- 'role ' => $ role ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ role ->getValue () : null ,
125+ 'bio ' => $ bio ,
126+ 'full_bio ' => $ fullBio ,
127+ 'headline ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_HEADLINE , $ user , $ currentUser ) ? $ headline ->getValue () : null ,
128+ 'location ' => $ isLocationVisible ? $ location ->getValue () : null ,
129+ 'location_url ' => $ isLocationVisible ? $ this ->getOpenStreetLocationUrl ($ location ->getValue ()) : null ,
130+ 'website ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_WEBSITE , $ user , $ currentUser ) ? $ website ->getValue () : null ,
131+ 'organisation ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ORGANISATION , $ user , $ currentUser ) ? $ organisation ->getValue () : null ,
132+ 'role ' => $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ROLE , $ user , $ currentUser ) ? $ role ->getValue () : null ,
138133 'url ' => $ referenceText ,
139134 ]
140135 );
141136 return $ reference ;
142137 }
143138
144- private function getObjectId (string $ url ): ?string {
139+ public function getObjectId (string $ url ): ?string {
145140 $ baseUrl = $ this ->urlGenerator ->getBaseUrl ();
146141 $ baseWithIndex = $ baseUrl . '/index.php ' ;
147142
@@ -157,7 +152,7 @@ private function getObjectId(string $url): ?string {
157152 return null ;
158153 }
159154
160- private function getOpenStreetLocationUrl ($ location ) {
155+ public function getOpenStreetLocationUrl ($ location ): string {
161156 return 'https://www.openstreetmap.org/search?query= ' . urlencode ($ location );
162157 }
163158
0 commit comments