4
4
5
5
namespace OCA \UsersPicker \Reference ;
6
6
7
- use OC \Collaboration \Reference \LinkReferenceProvider ;
7
+ use OCA \UsersPicker \AppInfo \Application ;
8
+ use OCP \Accounts \IAccountManager ;
9
+
8
10
use OCP \Collaboration \Reference \ADiscoverableReferenceProvider ;
11
+ use OCP \Collaboration \Reference \IReference ;
9
12
use OCP \Collaboration \Reference \Reference ;
10
13
11
- use OCP \Collaboration \Reference \IReference ;
12
- use OCP \Contacts \IManager ;
13
14
use OCP \IL10N ;
14
15
use OCP \IURLGenerator ;
15
-
16
- use OCA \UsersPicker \AppInfo \Application ;
17
- use OCP \Accounts \IAccountManager ;
18
16
use OCP \IUserManager ;
19
- use Psr \ Log \ LoggerInterface ;
17
+ use OCP \ Profile \ IProfileManager ;
20
18
21
19
class 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 ' ;
32
21
33
22
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 ,
42
29
) {
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 ;
50
30
}
51
31
52
32
/**
53
33
* @inheritDoc
54
34
*/
55
- public function getId (): string {
35
+ public function getId (): string {
56
36
return 'profile_picker ' ;
57
37
}
58
38
@@ -66,7 +46,7 @@ public function getTitle(): string {
66
46
/**
67
47
* @inheritDoc
68
48
*/
69
- public function getOrder (): int {
49
+ public function getOrder (): int {
70
50
return 10 ;
71
51
}
72
52
@@ -94,32 +74,46 @@ public function resolveReference(string $referenceText): ?IReference {
94
74
95
75
$ userId = $ this ->getObjectId ($ referenceText );
96
76
$ 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
-
100
77
if ($ user === null ) {
101
- return $ this ->linkReferenceProvider ->resolveReference ($ referenceText );
78
+ return null ;
79
+ }
80
+ if (!$ this ->profileManager ->isProfileEnabled ($ user )) {
81
+ return null ;
102
82
}
83
+ $ account = $ this ->accountManager ->getAccount ($ user );
84
+
85
+ $ currentUser = $ this ->userManager ->get ($ this ->userId );
103
86
104
87
$ reference = new Reference ($ referenceText );
105
88
106
89
$ userDisplayName = $ user ->getDisplayName ();
107
90
$ userEmail = $ user ->getEMailAddress ();
108
91
$ userAvatarUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.avatar.getAvatar ' , ['userId ' => $ userId , 'size ' => '64 ' ]);
109
92
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 );
117
109
118
110
// for clients who can't render the reference widgets
119
111
$ reference ->setTitle ($ userDisplayName );
120
112
$ reference ->setDescription ($ userEmail ?? $ userDisplayName );
121
113
$ reference ->setImageUrl ($ userAvatarUrl );
122
114
115
+ $ isLocationVisible = $ this ->profileManager ->isProfileFieldVisible (IAccountManager::PROPERTY_ADDRESS , $ user , $ currentUser );
116
+
123
117
// for the Vue reference widget
124
118
$ reference ->setRichObject (
125
119
self ::RICH_OBJECT_TYPE ,
@@ -128,20 +122,21 @@ public function resolveReference(string $referenceText): ?IReference {
128
122
'title ' => $ userDisplayName ,
129
123
'subline ' => $ userEmail ?? $ userDisplayName ,
130
124
'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 ,
138
133
'url ' => $ referenceText ,
139
134
]
140
135
);
141
136
return $ reference ;
142
137
}
143
138
144
- private function getObjectId (string $ url ): ?string {
139
+ public function getObjectId (string $ url ): ?string {
145
140
$ baseUrl = $ this ->urlGenerator ->getBaseUrl ();
146
141
$ baseWithIndex = $ baseUrl . '/index.php ' ;
147
142
@@ -157,7 +152,7 @@ private function getObjectId(string $url): ?string {
157
152
return null ;
158
153
}
159
154
160
- private function getOpenStreetLocationUrl ($ location ) {
155
+ public function getOpenStreetLocationUrl ($ location ): string {
161
156
return 'https://www.openstreetmap.org/search?query= ' . urlencode ($ location );
162
157
}
163
158
0 commit comments