Skip to content

Commit

Permalink
fixup! feat(contactsmenu): Sort by user status
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Nov 8, 2023
1 parent f471ca6 commit ab9bbe2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
Expand Up @@ -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',
Expand Down

0 comments on commit ab9bbe2

Please sign in to comment.