diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index a152a8106a620..c2dbbfd8b2063 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -89,10 +89,17 @@ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?i // Search by status if there is no filter and statuses are available if (!empty($recentStatuses)) { $allContacts = array_filter(array_map(function(UserStatus $userStatus) use ($options) { + // UID is ambiguous with federation. We have to use the federated cloud ID to an exact match of + // A local user + $user = $this->userManager->get($userStatus->getUserId()); + if ($user === null) { + return null; + } + $contact = $this->contactsManager->search( - $userStatus->getUserId(), + $user->getCloudId(), [ - 'UID', + 'CLOUD', ], array_merge( $options, diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php index 00c026dd9cc97..99439a6266443 100644 --- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php +++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php @@ -985,18 +985,30 @@ public function testGetRecentStatusFirst(): void { $status1, $status2, ]); + $user1 = $this->createMock(IUser::class); + $user1->method('getCloudId')->willReturn('user1@localcloud'); + $user2 = $this->createMock(IUser::class); + $user2->method('getCloudId')->willReturn('user2@localcloud'); + $this->userManager->expects(self::exactly(2)) + ->method('get') + ->willReturnCallback(function($uid) use ($user1, $user2) { + return match($uid) { + 'user1' => $user1, + 'user2' => $user2, + }; + }); $this->contactsManager ->expects(self::exactly(3)) ->method('search') ->willReturnCallback(function($uid, $searchProps, $options) { return match ([$uid, $options['limit'] ?? null]) { - ['user1', 1] => [ + ['user1@localcloud', 1] => [ [ 'UID' => 'user1', 'URI' => 'user1.vcf', ], ], - ['user2' => [], 1], // Simulate not found + ['user2@localcloud' => [], 1], // Simulate not found ['', 4] => [ [ 'UID' => 'contact1',