diff --git a/lib/Controller/DraftsController.php b/lib/Controller/DraftsController.php index f29dee3954..6697116b63 100644 --- a/lib/Controller/DraftsController.php +++ b/lib/Controller/DraftsController.php @@ -172,7 +172,7 @@ public function update(int $id, ?string $inReplyToMessageId = null, ?int $smimeCertificateId = null, ?int $sendAt = null): JsonResponse { - $message = $this->service->getMessage($id, $this->userId, LocalMessage::TYPE_DRAFT); + $message = $this->service->getMessage($id, $this->userId); $account = $this->accountService->find($this->userId, $accountId); ($sendAt !== null) @@ -208,7 +208,7 @@ public function update(int $id, */ #[TrapError] public function destroy(int $id): JsonResponse { - $message = $this->service->getMessage($id, $this->userId, LocalMessage::TYPE_DRAFT); + $message = $this->service->getMessage($id, $this->userId); $this->accountService->find($this->userId, $message->getAccountId()); $this->service->deleteMessage($this->userId, $message); @@ -223,7 +223,7 @@ public function destroy(int $id): JsonResponse { */ #[TrapError] public function move(int $id): JsonResponse { - $message = $this->service->getMessage($id, $this->userId, LocalMessage::TYPE_DRAFT); + $message = $this->service->getMessage($id, $this->userId); $account = $this->accountService->find($this->userId, $message->getAccountId()); $this->service->sendMessage($message, $account); diff --git a/lib/Controller/OutboxController.php b/lib/Controller/OutboxController.php index 8c21b9a244..69695cb926 100644 --- a/lib/Controller/OutboxController.php +++ b/lib/Controller/OutboxController.php @@ -32,7 +32,6 @@ use OCA\Mail\Http\JsonResponse; use OCA\Mail\Http\TrapError; use OCA\Mail\Service\AccountService; -use OCA\Mail\Service\DraftsService; use OCA\Mail\Service\OutboxService; use OCA\Mail\Service\SmimeService; use OCP\AppFramework\Controller; @@ -156,8 +155,8 @@ public function create( * @return JsonResponse */ #[TrapError] - public function createFromDraft(DraftsService $draftsService, int $id, int $sendAt = null): JsonResponse { - $draftMessage = $draftsService->getMessage($id, $this->userId, LocalMessage::TYPE_OUTGOING); + public function createFromDraft(int $id, int $sendAt = null): JsonResponse { + $draftMessage = $this->service->getMessage($id, $this->userId); // Locate the account to check authorization $this->accountService->find($this->userId, $draftMessage->getAccountId()); diff --git a/lib/Service/DraftsService.php b/lib/Service/DraftsService.php index 1a817fe68d..2d7f996471 100644 --- a/lib/Service/DraftsService.php +++ b/lib/Service/DraftsService.php @@ -204,12 +204,11 @@ public function sendMessage(LocalMessage $message, Account $account): void { * * @param int $id * @param string $userId - * @param int $type * @return LocalMessage * @throws DoesNotExistException */ - public function getMessage(int $id, string $userId, int $type): LocalMessage { - return $this->mapper->findById($id, $userId, $type); + public function getMessage(int $id, string $userId): LocalMessage { + return $this->mapper->findById($id, $userId, LocalMessage::TYPE_DRAFT); } /** diff --git a/tests/Integration/Service/DraftServiceIntegrationTest.php b/tests/Integration/Service/DraftServiceIntegrationTest.php index 122ffabf18..b31ec7cabb 100644 --- a/tests/Integration/Service/DraftServiceIntegrationTest.php +++ b/tests/Integration/Service/DraftServiceIntegrationTest.php @@ -153,7 +153,7 @@ public function testSaveAndGetMessage(): void { $this->assertNotEmpty($message->getRecipients()); $this->assertEmpty($message->getAttachments()); - $retrieved = $this->service->getMessage($message->getId(), $this->user->getUID(), LocalMessage::TYPE_DRAFT); + $retrieved = $this->service->getMessage($message->getId(), $this->user->getUID()); $this->assertNotEmpty($message->getRecipients()); $this->assertEmpty($message->getAttachments()); @@ -180,7 +180,7 @@ public function testSaveAndDeleteMessage(): void { $this->service->deleteMessage($this->user->getUID(), $saved); $this->expectException(DoesNotExistException::class); - $this->service->getMessage($message->getId(), $this->user->getUID(), LocalMessage::TYPE_DRAFT); + $this->service->getMessage($message->getId(), $this->user->getUID()); } public function testSaveAndUpdateMessage(): void { @@ -267,6 +267,6 @@ public function testSaveAndSendMessage(): void { $this->service->sendMessage($saved, new Account($this->account)); $this->expectException(DoesNotExistException::class); - $this->service->getMessage($message->getId(), $this->user->getUID(), LocalMessage::TYPE_DRAFT); + $this->service->getMessage($message->getId(), $this->user->getUID()); } } diff --git a/tests/Unit/Service/DraftsServiceTest.php b/tests/Unit/Service/DraftsServiceTest.php index aa3032cef5..03720867ae 100644 --- a/tests/Unit/Service/DraftsServiceTest.php +++ b/tests/Unit/Service/DraftsServiceTest.php @@ -127,7 +127,7 @@ public function testGetMessage(): void { ->with(1, $this->userId) ->willReturn($message); - $this->draftsService->getMessage(1, $this->userId, LocalMessage::TYPE_DRAFT); + $this->draftsService->getMessage(1, $this->userId); } public function testNoMessage(): void { @@ -137,7 +137,7 @@ public function testNoMessage(): void { ->willThrowException(new DoesNotExistException('Could not fetch any messages')); $this->expectException(DoesNotExistException::class); - $this->draftsService->getMessage(1, $this->userId, LocalMessage::TYPE_DRAFT); + $this->draftsService->getMessage(1, $this->userId); } public function testDeleteMessage(): void {