diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index a0a14cd9cbd0e..429aab3bf966d 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -100,6 +100,9 @@ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?i $userId = $user->getUID(); $contacts = array_filter($allContacts, function ($contact) use ($userId) { // When searching for multiple results, we strip out the current user + if (array_key_exists('X-NEXTCLOUD-UID', $contact)) { + return $contact['X-NEXTCLOUD-UID'] !== $userId; + } if (array_key_exists('UID', $contact)) { return $contact['UID'] !== $userId; } @@ -239,7 +242,7 @@ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry switch ($shareType) { case 0: case 6: - $filter = ['UID']; + $filter = ['X-NEXTCLOUD-UID', 'UID']; break; case 4: $filter = ['EMAIL']; @@ -262,7 +265,8 @@ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry } if ($shareType === 0 || $shareType === 6) { $isLocal = $contact['isLocalSystemBook'] ?? false; - if ($contact['UID'] === $shareWith && $isLocal === true) { + $uid = $contact['X-NEXTCLOUD-UID'] ?? ($contact['UID'] ?? null); + if ($uid === $shareWith && $isLocal === true) { $match = $contact; break; } @@ -284,8 +288,8 @@ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry private function contactArrayToEntry(array $contact): Entry { $entry = new Entry(); - if (isset($contact['UID'])) { - $uid = $contact['UID']; + $uid = $contact['X-NEXTCLOUD-UID'] ?? ($contact['UID'] ?? null); + if ($uid !== null) { $entry->setId($uid); $avatar = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $uid, 'size' => 64]); $entry->setAvatar($avatar); @@ -307,13 +311,12 @@ private function contactArrayToEntry(array $contact): Entry { } // Provide profile parameters for core/src/OC/contactsmenu/contact.handlebars template - if (isset($contact['UID']) && isset($contact['FN'])) { - $targetUserId = $contact['UID']; - $targetUser = $this->userManager->get($targetUserId); - if (!empty($targetUser)) { + if ($uid !== null && isset($contact['FN'])) { + $targetUser = $this->userManager->get($uid); + if ($targetUser instanceof IUser) { if ($this->profileManager->isProfileEnabled($targetUser)) { $entry->setProfileTitle($this->l10nFactory->get('lib')->t('View profile')); - $entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId])); + $entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $uid])); } } } diff --git a/lib/private/Contacts/ContactsMenu/Entry.php b/lib/private/Contacts/ContactsMenu/Entry.php index 3bbe679e99947..1b13da6576d01 100644 --- a/lib/private/Contacts/ContactsMenu/Entry.php +++ b/lib/private/Contacts/ContactsMenu/Entry.php @@ -132,6 +132,10 @@ private function sortActions(): void { * @param array $contact key-value array containing additional properties */ public function setProperties(array $contact): void { + if (isset($contact['X-NEXTCLOUD-UID'])) { + $contact['UID'] = $contact['X-NEXTCLOUD-UID']; + unset($contact['X-NEXTCLOUD-UID']); + } $this->properties = $contact; } diff --git a/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php b/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php index 17e30e89c3771..83dc04d6539e0 100644 --- a/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php +++ b/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php @@ -33,6 +33,7 @@ use OCP\IConfig; use OCP\IDateTimeFormatter; use OCP\IURLGenerator; +use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory as IL10NFactory; @@ -68,8 +69,12 @@ public function __construct( */ public function process(IEntry $entry) { $targetUserId = $entry->getProperty('UID'); + if ($targetUserId === null) { + return; + } + $targetUser = $this->userManager->get($targetUserId); - if (!empty($targetUser)) { + if ($targetUser instanceof IUser) { $timezone = $this->config->getUserValue($targetUser->getUID(), 'core', 'timezone') ?: date_default_timezone_get(); $dateTimeZone = new \DateTimeZone($timezone); $localTime = $this->dateTimeFormatter->formatTime($this->timeFactory->getDateTime(), 'short', $dateTimeZone); diff --git a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php index af941fd7fd1fe..dc0fd5c08ff17 100644 --- a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php +++ b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php @@ -29,6 +29,7 @@ use OCP\Contacts\ContactsMenu\IEntry; use OCP\Contacts\ContactsMenu\IProvider; use OCP\IURLGenerator; +use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory as IL10NFactory; @@ -58,8 +59,12 @@ public function __construct( */ public function process(IEntry $entry) { $targetUserId = $entry->getProperty('UID'); + if ($targetUserId === null) { + return; + } + $targetUser = $this->userManager->get($targetUserId); - if (!empty($targetUser)) { + if ($targetUser instanceof IUser) { if ($this->profileManager->isProfileEnabled($targetUser)) { $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/profile.svg')); $profileActionText = $this->l10nFactory->get('lib')->t('View profile'); diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php index a038058069e71..111030c1ec19c 100644 --- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php +++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php @@ -871,7 +871,7 @@ public function testFindOneUser() { $user = $this->createMock(IUser::class); $this->contactsManager->expects($this->once()) ->method('search') - ->with($this->equalTo('a567'), $this->equalTo(['UID'])) + ->with($this->equalTo('a567'), $this->equalTo(['X-NEXTCLOUD-UID', 'UID'])) ->willReturn([ [ 'UID' => 123, @@ -942,7 +942,7 @@ public function testFindOneNoMatches() { $user = $this->createMock(IUser::class); $this->contactsManager->expects($this->once()) ->method('search') - ->with($this->equalTo('a567'), $this->equalTo(['UID'])) + ->with($this->equalTo('a567'), $this->equalTo(['X-NEXTCLOUD-UID', 'UID'])) ->willReturn([ [ 'UID' => 123,