26
26
27
27
namespace OCA \Contacts \Reference ;
28
28
29
+
29
30
use OC \Collaboration \Reference \LinkReferenceProvider ;
30
31
use OCP \Collaboration \Reference \ADiscoverableReferenceProvider ;
31
32
use OCP \Collaboration \Reference \Reference ;
39
40
use OCP \IUserManager ;
40
41
41
42
class ProfilePickerReferenceProvider extends ADiscoverableReferenceProvider {
42
-
43
- // private const RICH_OBJECT_TYPE = Application::APP_ID . '_profile_picker';
44
43
private const RICH_OBJECT_TYPE = 'users_picker_profile ' ;
45
-
46
44
private ?string $ userId ;
47
45
private IL10N $ l10n ;
48
46
private IURLGenerator $ urlGenerator ;
@@ -105,52 +103,53 @@ public function matchReference(string $referenceText): bool {
105
103
* @inheritDoc
106
104
*/
107
105
public function resolveReference (string $ referenceText ): ?IReference {
108
- if ($ this ->matchReference ($ referenceText )) {
109
- $ userId = $ this ->getObjectId ($ referenceText );
110
- $ user = $ this ->userManager ->get ($ userId );
111
- if ($ user !== null ) {
112
- $ reference = new Reference ($ referenceText );
113
-
114
- $ userDisplayName = $ user ->getDisplayName ();
115
- $ userEmail = $ user ->getEMailAddress ();
116
- $ userAvatarUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.avatar.getAvatar ' , ['userId ' => $ userId , 'size ' => '64 ' ]);
117
-
118
- $ bio = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_BIOGRAPHY );
119
- $ bio = $ bio ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ bio ->getValue () : null ;
120
- $ headline = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_HEADLINE );
121
- $ location = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ADDRESS );
122
- $ website = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_WEBSITE );
123
- $ organisation = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ORGANISATION );
124
- $ role = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ROLE );
125
-
126
- // for clients who can't render the reference widgets
127
- $ reference ->setTitle ($ userDisplayName );
128
- $ reference ->setDescription ($ userEmail ?? $ userDisplayName );
129
- $ reference ->setImageUrl ($ userAvatarUrl );
130
-
131
- // for the Vue reference widget
132
- $ reference ->setRichObject (
133
- self ::RICH_OBJECT_TYPE ,
134
- [
135
- 'user_id ' => $ userId ,
136
- 'title ' => $ userDisplayName ,
137
- 'subline ' => $ userEmail ?? $ userDisplayName ,
138
- 'email ' => $ userEmail ,
139
- 'bio ' => isset ($ bio ) && $ bio !== '' ? substr_replace ($ bio , '... ' , 80 , strlen ($ bio )) : null ,
140
- 'headline ' => $ headline ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ headline ->getValue () : null ,
141
- 'location ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ location ->getValue () : null ,
142
- 'location_url ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ this ->getOpenStreetLocationUrl ($ location ->getValue ()) : null ,
143
- 'website ' => $ website ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ website ->getValue () : null ,
144
- 'organisation ' => $ organisation ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ organisation ->getValue () : null ,
145
- 'role ' => $ role ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ role ->getValue () : null ,
146
- 'url ' => $ referenceText ,
147
- ]
148
- );
149
- return $ reference ;
150
- }
151
- return $ this ->linkReferenceProvider ->resolveReference ($ referenceText );
106
+ if (!$ this ->matchReference ($ referenceText )) {
107
+ return null ;
152
108
}
153
- return null ;
109
+
110
+ $ userId = $ this ->getObjectId ($ referenceText );
111
+ $ user = $ this ->userManager ->get ($ userId );
112
+ if ($ user !== null ) {
113
+ $ reference = new Reference ($ referenceText );
114
+
115
+ $ userDisplayName = $ user ->getDisplayName ();
116
+ $ userEmail = $ user ->getEMailAddress ();
117
+ $ userAvatarUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.avatar.getAvatar ' , ['userId ' => $ userId , 'size ' => '64 ' ]);
118
+
119
+ $ bio = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_BIOGRAPHY );
120
+ $ bio = $ bio ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ bio ->getValue () : null ;
121
+ $ headline = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_HEADLINE );
122
+ $ location = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ADDRESS );
123
+ $ website = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_WEBSITE );
124
+ $ organisation = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ORGANISATION );
125
+ $ role = $ this ->accountManager ->getAccount ($ user )->getProperty (IAccountManager::PROPERTY_ROLE );
126
+
127
+ // for clients who can't render the reference widgets
128
+ $ reference ->setTitle ($ userDisplayName );
129
+ $ reference ->setDescription ($ userEmail ?? $ userDisplayName );
130
+ $ reference ->setImageUrl ($ userAvatarUrl );
131
+
132
+ // for the Vue reference widget
133
+ $ reference ->setRichObject (
134
+ self ::RICH_OBJECT_TYPE ,
135
+ [
136
+ 'user_id ' => $ userId ,
137
+ 'title ' => $ userDisplayName ,
138
+ 'subline ' => $ userEmail ?? $ userDisplayName ,
139
+ 'email ' => $ userEmail ,
140
+ 'bio ' => isset ($ bio ) && $ bio !== '' ? substr_replace ($ bio , '... ' , 80 , strlen ($ bio )) : null ,
141
+ 'headline ' => $ headline ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ headline ->getValue () : null ,
142
+ 'location ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ location ->getValue () : null ,
143
+ 'location_url ' => $ location ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ this ->getOpenStreetLocationUrl ($ location ->getValue ()) : null ,
144
+ 'website ' => $ website ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ website ->getValue () : null ,
145
+ 'organisation ' => $ organisation ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ organisation ->getValue () : null ,
146
+ 'role ' => $ role ->getScope () !== IAccountManager::SCOPE_PRIVATE ? $ role ->getValue () : null ,
147
+ 'url ' => $ referenceText ,
148
+ ]
149
+ );
150
+ return $ reference ;
151
+ }
152
+ return $ this ->linkReferenceProvider ->resolveReference ($ referenceText );
154
153
}
155
154
156
155
private function getObjectId (string $ url ): ?string {
@@ -169,7 +168,7 @@ private function getObjectId(string $url): ?string {
169
168
return null ;
170
169
}
171
170
172
- private function getOpenStreetLocationUrl ($ location ) {
171
+ private function getOpenStreetLocationUrl ($ location ): string {
173
172
return 'https://www.openstreetmap.org/search?query= ' . urlencode ($ location );
174
173
}
175
174
0 commit comments