diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2020-11-23 18:33:02 +0300 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2020-11-26 16:37:40 +0300 |
commit | cd9d4a47d6d74a0872e21153cfdf8007436ca30a (patch) | |
tree | 5a12b40802b1d0c0eea8a408636ce0837cd0ff28 | |
parent | a1e4b8f1afc38f5c167466f4e3e8e029389c78ef (diff) |
Fix previous drafts not being deleted from the cache
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
-rw-r--r-- | lib/Listener/DeleteDraftListener.php | 13 | ||||
-rw-r--r-- | tests/Unit/Listener/DeleteDraftListenerTest.php | 22 |
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/Listener/DeleteDraftListener.php b/lib/Listener/DeleteDraftListener.php index 87f46b47a..469ef070b 100644 --- a/lib/Listener/DeleteDraftListener.php +++ b/lib/Listener/DeleteDraftListener.php @@ -32,11 +32,13 @@ use OCA\Mail\Db\Mailbox; use OCA\Mail\Db\MailboxMapper; use OCA\Mail\Db\Message; use OCA\Mail\Events\DraftSavedEvent; +use OCA\Mail\Events\MessageDeletedEvent; use OCA\Mail\Events\MessageSentEvent; use OCA\Mail\IMAP\IMAPClientFactory; use OCA\Mail\IMAP\MessageMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; use Psr\Log\LoggerInterface; @@ -54,14 +56,19 @@ class DeleteDraftListener implements IEventListener { /** @var LoggerInterface */ private $logger; + /** @var IEventDispatcher */ + private $eventDispatcher; + public function __construct(IMAPClientFactory $imapClientFactory, MailboxMapper $mailboxMapper, MessageMapper $messageMapper, - LoggerInterface $logger) { + LoggerInterface $logger, + IEventDispatcher $eventDispatcher) { $this->imapClientFactory = $imapClientFactory; $this->mailboxMapper = $mailboxMapper; $this->messageMapper = $messageMapper; $this->logger = $logger; + $this->eventDispatcher = $eventDispatcher; } public function handle(Event $event): void { @@ -105,6 +112,10 @@ class DeleteDraftListener implements IEventListener { 'exception' => $e, ]); } + + $this->eventDispatcher->dispatchTyped( + new MessageDeletedEvent($account, $draftsMailbox, $draft->getUid()) + ); } /** diff --git a/tests/Unit/Listener/DeleteDraftListenerTest.php b/tests/Unit/Listener/DeleteDraftListenerTest.php index 774c42588..96503bdf2 100644 --- a/tests/Unit/Listener/DeleteDraftListenerTest.php +++ b/tests/Unit/Listener/DeleteDraftListenerTest.php @@ -32,6 +32,7 @@ use OCA\Mail\Db\Mailbox; use OCA\Mail\Db\MailboxMapper; use OCA\Mail\Db\Message; use OCA\Mail\Events\DraftSavedEvent; +use OCA\Mail\Events\MessageDeletedEvent; use OCA\Mail\Events\MessageSentEvent; use OCA\Mail\IMAP\IMAPClientFactory; use OCA\Mail\IMAP\MessageMapper; @@ -41,6 +42,7 @@ use OCA\Mail\Model\NewMessageData; use OCA\Mail\Model\RepliedMessageData; use OCP\AppFramework\Db\DoesNotExistException; use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -59,6 +61,9 @@ class DeleteDraftListenerTest extends TestCase { /** @var LoggerInterface|MockObject */ private $logger; + /** @var IEventDispatcher|MockObject */ + private $eventDispatcher; + /** @var IEventListener */ private $listener; @@ -69,12 +74,14 @@ class DeleteDraftListenerTest extends TestCase { $this->mailboxMapper = $this->createMock(MailboxMapper::class); $this->messageMapper = $this->createMock(MessageMapper::class); $this->logger = $this->createMock(LoggerInterface::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->listener = new DeleteDraftListener( $this->imapClientFactory, $this->mailboxMapper, $this->messageMapper, - $this->logger + $this->logger, + $this->eventDispatcher ); } @@ -100,6 +107,8 @@ class DeleteDraftListenerTest extends TestCase { ->method('addFlag'); $this->logger->expects($this->never()) ->method('error'); + $this->eventDispatcher->expects($this->never()) + ->method('dispatchTyped'); $this->listener->handle($event); } @@ -181,6 +190,8 @@ class DeleteDraftListenerTest extends TestCase { ->method('addFlag'); $this->logger->expects($this->never()) ->method('error'); + $this->eventDispatcher->expects($this->never()) + ->method('dispatchTyped'); $this->listener->handle($event); } @@ -236,6 +247,15 @@ class DeleteDraftListenerTest extends TestCase { $this->logger->expects($this->never()) ->method('error'); + $messageDeletedEvent = new MessageDeletedEvent( + $account, + $mailbox, + $draft->getUid() + ); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with($messageDeletedEvent); + $this->listener->handle($event); } } |