2021-02-15 16:35:45 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-06-21 16:58:11 +03:00
|
|
|
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2021-02-15 16:35:45 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Mail\Controller;
|
|
|
|
|
2023-01-25 17:40:41 +03:00
|
|
|
use OCA\Mail\Http\TrapError;
|
2021-02-15 16:35:45 +03:00
|
|
|
use OCA\Mail\Service\ContactIntegration\ContactIntegrationService;
|
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http;
|
2024-07-30 13:09:10 +03:00
|
|
|
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
2021-02-15 16:35:45 +03:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
2024-07-30 13:09:10 +03:00
|
|
|
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
2021-02-15 16:35:45 +03:00
|
|
|
class ContactIntegrationController extends Controller {
|
2022-10-01 23:01:07 +03:00
|
|
|
private ContactIntegrationService $service;
|
2021-02-15 16:35:45 +03:00
|
|
|
|
|
|
|
public function __construct(string $appName,
|
2023-06-28 15:44:08 +03:00
|
|
|
IRequest $request,
|
|
|
|
ContactIntegrationService $service) {
|
2021-02-15 16:35:45 +03:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
|
|
|
$this->service = $service;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $mail
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
2023-01-25 17:40:41 +03:00
|
|
|
#[TrapError]
|
2021-02-15 16:35:45 +03:00
|
|
|
public function match(string $mail): JSONResponse {
|
2022-09-21 14:58:14 +03:00
|
|
|
return (new JSONResponse($this->service->findMatches($mail)))->cacheFor(60 * 60, false, true);
|
2021-02-15 16:35:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $uid
|
|
|
|
* @param string $mail
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
2023-01-25 17:40:41 +03:00
|
|
|
#[TrapError]
|
2024-02-28 16:17:50 +03:00
|
|
|
public function addMail(?string $uid = null, ?string $mail = null): JSONResponse {
|
2021-02-15 16:35:45 +03:00
|
|
|
$res = $this->service->addEMailToContact($uid, $mail);
|
|
|
|
if ($res === null) {
|
|
|
|
return new JSONResponse([], Http::STATUS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
return new JSONResponse($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
2023-01-25 17:40:41 +03:00
|
|
|
#[TrapError]
|
2024-02-28 16:17:50 +03:00
|
|
|
public function newContact(?string $contactName = null, ?string $mail = null): JSONResponse {
|
2021-02-15 16:35:45 +03:00
|
|
|
$res = $this->service->newContact($contactName, $mail);
|
|
|
|
if ($res === null) {
|
|
|
|
return new JSONResponse([], Http::STATUS_NOT_ACCEPTABLE);
|
|
|
|
}
|
|
|
|
return new JSONResponse($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $term
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
2023-01-25 17:40:41 +03:00
|
|
|
#[TrapError]
|
2021-02-15 16:35:45 +03:00
|
|
|
public function autoComplete(string $term): JSONResponse {
|
|
|
|
$res = $this->service->autoComplete($term);
|
2022-09-21 14:58:14 +03:00
|
|
|
return (new JSONResponse($res))->cacheFor(60 * 60, false, true);
|
2021-02-15 16:35:45 +03:00
|
|
|
}
|
|
|
|
}
|