Skip to content

Commit db84413

Browse files
committed
feat: allow to filter contacts by team
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent d9d1d04 commit db84413

File tree

4 files changed

+253
-135
lines changed

4 files changed

+253
-135
lines changed

core/Controller/ContactsMenuController.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
1414
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1515
use OCP\AppFramework\Http\JSONResponse;
16+
use OCP\Contacts\ContactsMenu\IEntry;
1617
use OCP\IRequest;
1718
use OCP\IUserSession;
19+
use OCP\Teams\ITeamManager;
1820

1921
class ContactsMenuController extends Controller {
2022
public function __construct(
2123
IRequest $request,
2224
private IUserSession $userSession,
2325
private Manager $manager,
26+
private ITeamManager $teamManager,
2427
) {
2528
parent::__construct('core', $request);
2629
}
@@ -31,8 +34,18 @@ public function __construct(
3134
*/
3235
#[NoAdminRequired]
3336
#[FrontpageRoute(verb: 'POST', url: '/contactsmenu/contacts')]
34-
public function index(?string $filter = null): array {
35-
return $this->manager->getEntries($this->userSession->getUser(), $filter);
37+
public function index(?string $filter = null, ?string $teamId = null): array {
38+
$entries = $this->manager->getEntries($this->userSession->getUser(), $filter);
39+
if ($teamId !== null) {
40+
/** @var \OC\Teams\ITeamManager */
41+
$teamManager = $this->teamManager;
42+
$memberIds = $teamManager->getMembersOfTeam($teamId, $this->userSession->getUser()->getUID());
43+
$entries['contacts'] = array_filter(
44+
$entries['contacts'],
45+
fn (IEntry $entry) => in_array($entry->getProperty('UID'), $memberIds, true)
46+
);
47+
}
48+
return $entries;
3649
}
3750

3851
/**
@@ -49,4 +62,13 @@ public function findOne(int $shareType, string $shareWith) {
4962
}
5063
return new JSONResponse([], Http::STATUS_NOT_FOUND);
5164
}
65+
66+
/**
67+
* @return \JsonSerializable[]
68+
*/
69+
#[NoAdminRequired]
70+
#[FrontpageRoute(verb: 'GET', url: '/contactsmenu/teams')]
71+
public function getTeams(): array {
72+
return $this->teamManager->getTeamsForUser($this->userSession->getUser()->getUID());
73+
}
5274
}

0 commit comments

Comments
 (0)