@@ -33,272 +33,272 @@ |
||
33 | 33 | |
34 | 34 | class Activity implements IProvider { |
35 | 35 | |
36 | - /** @var IFactory */ |
|
37 | - protected $languageFactory; |
|
38 | - |
|
39 | - /** @var IL10N */ |
|
40 | - protected $l; |
|
41 | - |
|
42 | - /** @var IURLGenerator */ |
|
43 | - protected $url; |
|
44 | - |
|
45 | - /** @var IManager */ |
|
46 | - protected $activityManager; |
|
47 | - |
|
48 | - /** @var IUserManager */ |
|
49 | - protected $userManager; |
|
50 | - /** @var IContactsManager */ |
|
51 | - protected $contactsManager; |
|
52 | - |
|
53 | - /** @var array */ |
|
54 | - protected $displayNames = []; |
|
55 | - |
|
56 | - /** @var array */ |
|
57 | - protected $contactNames = []; |
|
58 | - |
|
59 | - const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | - const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IFactory $languageFactory |
|
66 | - * @param IURLGenerator $url |
|
67 | - * @param IManager $activityManager |
|
68 | - * @param IUserManager $userManager |
|
69 | - * @param IContactsManager $contactsManager |
|
70 | - */ |
|
71 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | - $this->languageFactory = $languageFactory; |
|
73 | - $this->url = $url; |
|
74 | - $this->activityManager = $activityManager; |
|
75 | - $this->userManager = $userManager; |
|
76 | - $this->contactsManager = $contactsManager; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $language |
|
81 | - * @param IEvent $event |
|
82 | - * @param IEvent|null $previousEvent |
|
83 | - * @return IEvent |
|
84 | - * @throws \InvalidArgumentException |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | - if ($event->getApp() !== 'sharebymail') { |
|
89 | - throw new \InvalidArgumentException(); |
|
90 | - } |
|
91 | - |
|
92 | - $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | - |
|
94 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | - try { |
|
96 | - return $this->parseShortVersion($event); |
|
97 | - } catch (\InvalidArgumentException $e) { |
|
98 | - // Ignore and simply use the long version... |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - return $this->parseLongVersion($event); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param IEvent $event |
|
107 | - * @return IEvent |
|
108 | - * @throws \InvalidArgumentException |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function parseShortVersion(IEvent $event) { |
|
112 | - $parsedParameters = $this->getParsedParameters($event); |
|
113 | - |
|
114 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | - $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | - $parsedParameters['email']['name'], |
|
117 | - ])) |
|
118 | - ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | - 'email' => $parsedParameters['email'], |
|
120 | - ]) |
|
121 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
122 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
123 | - $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
124 | - $parsedParameters['email']['name'], |
|
125 | - $parsedParameters['actor']['name'], |
|
126 | - ])) |
|
127 | - ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
128 | - 'email' => $parsedParameters['email'], |
|
129 | - 'actor' => $parsedParameters['actor'], |
|
130 | - ]) |
|
131 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
132 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
133 | - $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
134 | - $parsedParameters['email']['name'] |
|
135 | - ])) |
|
136 | - ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
137 | - 'email' => $parsedParameters['email'] |
|
138 | - ]) |
|
139 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
140 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
141 | - $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
142 | - ->setRichSubject($this->l->t('Password for mail share sent to you')) |
|
143 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
144 | - } else { |
|
145 | - throw new \InvalidArgumentException(); |
|
146 | - } |
|
147 | - |
|
148 | - return $event; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param IEvent $event |
|
153 | - * @return IEvent |
|
154 | - * @throws \InvalidArgumentException |
|
155 | - * @since 11.0.0 |
|
156 | - */ |
|
157 | - public function parseLongVersion(IEvent $event) { |
|
158 | - $parsedParameters = $this->getParsedParameters($event); |
|
159 | - |
|
160 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
161 | - $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
162 | - $parsedParameters['file']['path'], |
|
163 | - $parsedParameters['email']['name'], |
|
164 | - ])) |
|
165 | - ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters) |
|
166 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
167 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
168 | - $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
169 | - $parsedParameters['file']['path'], |
|
170 | - $parsedParameters['email']['name'], |
|
171 | - $parsedParameters['actor']['name'], |
|
172 | - ])) |
|
173 | - ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters) |
|
174 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
175 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
176 | - $event->setParsedSubject($this->l->t('Password to access %1$s was send to %2s', [ |
|
177 | - $parsedParameters['file']['path'], |
|
178 | - $parsedParameters['email']['name'] |
|
179 | - ])) |
|
180 | - ->setRichSubject($this->l->t('Password to access {file} was send to {email}'), $parsedParameters) |
|
181 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
182 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
183 | - $event->setParsedSubject( |
|
184 | - $this->l->t('Password to access %1$s was send to you', |
|
185 | - [$parsedParameters['file']['path']])) |
|
186 | - ->setRichSubject($this->l->t('Password to access {file} was send to you'), $parsedParameters) |
|
187 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
188 | - |
|
189 | - } else { |
|
190 | - throw new \InvalidArgumentException(); |
|
191 | - } |
|
192 | - |
|
193 | - return $event; |
|
194 | - } |
|
195 | - |
|
196 | - protected function getParsedParameters(IEvent $event) { |
|
197 | - $subject = $event->getSubject(); |
|
198 | - $parameters = $event->getSubjectParameters(); |
|
199 | - |
|
200 | - switch ($subject) { |
|
201 | - case self::SUBJECT_SHARED_EMAIL_SELF: |
|
202 | - return [ |
|
203 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
204 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
205 | - ]; |
|
206 | - case self::SUBJECT_SHARED_EMAIL_BY: |
|
207 | - return [ |
|
208 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
209 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
210 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
211 | - ]; |
|
212 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
213 | - return [ |
|
214 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
215 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
216 | - ]; |
|
217 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
218 | - return [ |
|
219 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
220 | - ]; |
|
221 | - } |
|
222 | - throw new \InvalidArgumentException(); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @param int $id |
|
227 | - * @param string $path |
|
228 | - * @return array |
|
229 | - */ |
|
230 | - protected function generateFileParameter($id, $path) { |
|
231 | - return [ |
|
232 | - 'type' => 'file', |
|
233 | - 'id' => $id, |
|
234 | - 'name' => basename($path), |
|
235 | - 'path' => trim($path, '/'), |
|
236 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
237 | - ]; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $email |
|
242 | - * @return array |
|
243 | - */ |
|
244 | - protected function generateEmailParameter($email) { |
|
245 | - if (!isset($this->contactNames[$email])) { |
|
246 | - $this->contactNames[$email] = $this->getContactName($email); |
|
247 | - } |
|
248 | - |
|
249 | - return [ |
|
250 | - 'type' => 'email', |
|
251 | - 'id' => $email, |
|
252 | - 'name' => $this->contactNames[$email], |
|
253 | - ]; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @param string $uid |
|
258 | - * @return array |
|
259 | - */ |
|
260 | - protected function generateUserParameter($uid) { |
|
261 | - if (!isset($this->displayNames[$uid])) { |
|
262 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
263 | - } |
|
264 | - |
|
265 | - return [ |
|
266 | - 'type' => 'user', |
|
267 | - 'id' => $uid, |
|
268 | - 'name' => $this->displayNames[$uid], |
|
269 | - ]; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @param string $email |
|
274 | - * @return string |
|
275 | - */ |
|
276 | - protected function getContactName($email) { |
|
277 | - $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
278 | - |
|
279 | - foreach ($addressBookContacts as $contact) { |
|
280 | - if (isset($contact['isLocalSystemBook'])) { |
|
281 | - continue; |
|
282 | - } |
|
283 | - |
|
284 | - if (in_array($email, $contact['EMAIL'])) { |
|
285 | - return $contact['FN']; |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - return $email; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * @param string $uid |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - protected function getDisplayName($uid) { |
|
297 | - $user = $this->userManager->get($uid); |
|
298 | - if ($user instanceof IUser) { |
|
299 | - return $user->getDisplayName(); |
|
300 | - } else { |
|
301 | - return $uid; |
|
302 | - } |
|
303 | - } |
|
36 | + /** @var IFactory */ |
|
37 | + protected $languageFactory; |
|
38 | + |
|
39 | + /** @var IL10N */ |
|
40 | + protected $l; |
|
41 | + |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $url; |
|
44 | + |
|
45 | + /** @var IManager */ |
|
46 | + protected $activityManager; |
|
47 | + |
|
48 | + /** @var IUserManager */ |
|
49 | + protected $userManager; |
|
50 | + /** @var IContactsManager */ |
|
51 | + protected $contactsManager; |
|
52 | + |
|
53 | + /** @var array */ |
|
54 | + protected $displayNames = []; |
|
55 | + |
|
56 | + /** @var array */ |
|
57 | + protected $contactNames = []; |
|
58 | + |
|
59 | + const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | + const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IFactory $languageFactory |
|
66 | + * @param IURLGenerator $url |
|
67 | + * @param IManager $activityManager |
|
68 | + * @param IUserManager $userManager |
|
69 | + * @param IContactsManager $contactsManager |
|
70 | + */ |
|
71 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | + $this->languageFactory = $languageFactory; |
|
73 | + $this->url = $url; |
|
74 | + $this->activityManager = $activityManager; |
|
75 | + $this->userManager = $userManager; |
|
76 | + $this->contactsManager = $contactsManager; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $language |
|
81 | + * @param IEvent $event |
|
82 | + * @param IEvent|null $previousEvent |
|
83 | + * @return IEvent |
|
84 | + * @throws \InvalidArgumentException |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | + if ($event->getApp() !== 'sharebymail') { |
|
89 | + throw new \InvalidArgumentException(); |
|
90 | + } |
|
91 | + |
|
92 | + $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | + |
|
94 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | + try { |
|
96 | + return $this->parseShortVersion($event); |
|
97 | + } catch (\InvalidArgumentException $e) { |
|
98 | + // Ignore and simply use the long version... |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + return $this->parseLongVersion($event); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param IEvent $event |
|
107 | + * @return IEvent |
|
108 | + * @throws \InvalidArgumentException |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function parseShortVersion(IEvent $event) { |
|
112 | + $parsedParameters = $this->getParsedParameters($event); |
|
113 | + |
|
114 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | + $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | + $parsedParameters['email']['name'], |
|
117 | + ])) |
|
118 | + ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | + 'email' => $parsedParameters['email'], |
|
120 | + ]) |
|
121 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
122 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
123 | + $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
124 | + $parsedParameters['email']['name'], |
|
125 | + $parsedParameters['actor']['name'], |
|
126 | + ])) |
|
127 | + ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
128 | + 'email' => $parsedParameters['email'], |
|
129 | + 'actor' => $parsedParameters['actor'], |
|
130 | + ]) |
|
131 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
132 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
133 | + $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
134 | + $parsedParameters['email']['name'] |
|
135 | + ])) |
|
136 | + ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
137 | + 'email' => $parsedParameters['email'] |
|
138 | + ]) |
|
139 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
140 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
141 | + $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
142 | + ->setRichSubject($this->l->t('Password for mail share sent to you')) |
|
143 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
144 | + } else { |
|
145 | + throw new \InvalidArgumentException(); |
|
146 | + } |
|
147 | + |
|
148 | + return $event; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param IEvent $event |
|
153 | + * @return IEvent |
|
154 | + * @throws \InvalidArgumentException |
|
155 | + * @since 11.0.0 |
|
156 | + */ |
|
157 | + public function parseLongVersion(IEvent $event) { |
|
158 | + $parsedParameters = $this->getParsedParameters($event); |
|
159 | + |
|
160 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
161 | + $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
162 | + $parsedParameters['file']['path'], |
|
163 | + $parsedParameters['email']['name'], |
|
164 | + ])) |
|
165 | + ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters) |
|
166 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
167 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
168 | + $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
169 | + $parsedParameters['file']['path'], |
|
170 | + $parsedParameters['email']['name'], |
|
171 | + $parsedParameters['actor']['name'], |
|
172 | + ])) |
|
173 | + ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters) |
|
174 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
175 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
176 | + $event->setParsedSubject($this->l->t('Password to access %1$s was send to %2s', [ |
|
177 | + $parsedParameters['file']['path'], |
|
178 | + $parsedParameters['email']['name'] |
|
179 | + ])) |
|
180 | + ->setRichSubject($this->l->t('Password to access {file} was send to {email}'), $parsedParameters) |
|
181 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
182 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
183 | + $event->setParsedSubject( |
|
184 | + $this->l->t('Password to access %1$s was send to you', |
|
185 | + [$parsedParameters['file']['path']])) |
|
186 | + ->setRichSubject($this->l->t('Password to access {file} was send to you'), $parsedParameters) |
|
187 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
188 | + |
|
189 | + } else { |
|
190 | + throw new \InvalidArgumentException(); |
|
191 | + } |
|
192 | + |
|
193 | + return $event; |
|
194 | + } |
|
195 | + |
|
196 | + protected function getParsedParameters(IEvent $event) { |
|
197 | + $subject = $event->getSubject(); |
|
198 | + $parameters = $event->getSubjectParameters(); |
|
199 | + |
|
200 | + switch ($subject) { |
|
201 | + case self::SUBJECT_SHARED_EMAIL_SELF: |
|
202 | + return [ |
|
203 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
204 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
205 | + ]; |
|
206 | + case self::SUBJECT_SHARED_EMAIL_BY: |
|
207 | + return [ |
|
208 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
209 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
210 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
211 | + ]; |
|
212 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
213 | + return [ |
|
214 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
215 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
216 | + ]; |
|
217 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
218 | + return [ |
|
219 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
220 | + ]; |
|
221 | + } |
|
222 | + throw new \InvalidArgumentException(); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @param int $id |
|
227 | + * @param string $path |
|
228 | + * @return array |
|
229 | + */ |
|
230 | + protected function generateFileParameter($id, $path) { |
|
231 | + return [ |
|
232 | + 'type' => 'file', |
|
233 | + 'id' => $id, |
|
234 | + 'name' => basename($path), |
|
235 | + 'path' => trim($path, '/'), |
|
236 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
237 | + ]; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $email |
|
242 | + * @return array |
|
243 | + */ |
|
244 | + protected function generateEmailParameter($email) { |
|
245 | + if (!isset($this->contactNames[$email])) { |
|
246 | + $this->contactNames[$email] = $this->getContactName($email); |
|
247 | + } |
|
248 | + |
|
249 | + return [ |
|
250 | + 'type' => 'email', |
|
251 | + 'id' => $email, |
|
252 | + 'name' => $this->contactNames[$email], |
|
253 | + ]; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @param string $uid |
|
258 | + * @return array |
|
259 | + */ |
|
260 | + protected function generateUserParameter($uid) { |
|
261 | + if (!isset($this->displayNames[$uid])) { |
|
262 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
263 | + } |
|
264 | + |
|
265 | + return [ |
|
266 | + 'type' => 'user', |
|
267 | + 'id' => $uid, |
|
268 | + 'name' => $this->displayNames[$uid], |
|
269 | + ]; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @param string $email |
|
274 | + * @return string |
|
275 | + */ |
|
276 | + protected function getContactName($email) { |
|
277 | + $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
278 | + |
|
279 | + foreach ($addressBookContacts as $contact) { |
|
280 | + if (isset($contact['isLocalSystemBook'])) { |
|
281 | + continue; |
|
282 | + } |
|
283 | + |
|
284 | + if (in_array($email, $contact['EMAIL'])) { |
|
285 | + return $contact['FN']; |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + return $email; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * @param string $uid |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + protected function getDisplayName($uid) { |
|
297 | + $user = $this->userManager->get($uid); |
|
298 | + if ($user instanceof IUser) { |
|
299 | + return $user->getDisplayName(); |
|
300 | + } else { |
|
301 | + return $uid; |
|
302 | + } |
|
303 | + } |
|
304 | 304 | } |