diff --git a/apps/contactsinteraction/composer/composer/autoload_classmap.php b/apps/contactsinteraction/composer/composer/autoload_classmap.php index 6cc1fd7d984..aff453c997d 100644 --- a/apps/contactsinteraction/composer/composer/autoload_classmap.php +++ b/apps/contactsinteraction/composer/composer/autoload_classmap.php @@ -16,5 +16,6 @@ return array( 'OCA\\ContactsInteraction\\Db\\RecentContact' => $baseDir . '/../lib/Db/RecentContact.php', 'OCA\\ContactsInteraction\\Db\\RecentContactMapper' => $baseDir . '/../lib/Db/RecentContactMapper.php', 'OCA\\ContactsInteraction\\Listeners\\ContactInteractionListener' => $baseDir . '/../lib/Listeners/ContactInteractionListener.php', + 'OCA\\ContactsInteraction\\Listeners\\UserDeletedListener' => $baseDir . '/../lib/Listeners/UserDeletedListener.php', 'OCA\\ContactsInteraction\\Migration\\Version010000Date20200304152605' => $baseDir . '/../lib/Migration/Version010000Date20200304152605.php', ); diff --git a/apps/contactsinteraction/composer/composer/autoload_static.php b/apps/contactsinteraction/composer/composer/autoload_static.php index c7cdc26dc68..9cee53ae045 100644 --- a/apps/contactsinteraction/composer/composer/autoload_static.php +++ b/apps/contactsinteraction/composer/composer/autoload_static.php @@ -31,6 +31,7 @@ class ComposerStaticInitContactsInteraction 'OCA\\ContactsInteraction\\Db\\RecentContact' => __DIR__ . '/..' . '/../lib/Db/RecentContact.php', 'OCA\\ContactsInteraction\\Db\\RecentContactMapper' => __DIR__ . '/..' . '/../lib/Db/RecentContactMapper.php', 'OCA\\ContactsInteraction\\Listeners\\ContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listeners/ContactInteractionListener.php', + 'OCA\\ContactsInteraction\\Listeners\\UserDeletedListener' => __DIR__ . '/..' . '/../lib/Listeners/UserDeletedListener.php', 'OCA\\ContactsInteraction\\Migration\\Version010000Date20200304152605' => __DIR__ . '/..' . '/../lib/Migration/Version010000Date20200304152605.php', ); diff --git a/apps/contactsinteraction/lib/AppInfo/Application.php b/apps/contactsinteraction/lib/AppInfo/Application.php index b844ee1699c..6e3c1660ddc 100644 --- a/apps/contactsinteraction/lib/AppInfo/Application.php +++ b/apps/contactsinteraction/lib/AppInfo/Application.php @@ -9,11 +9,13 @@ declare(strict_types=1); namespace OCA\ContactsInteraction\AppInfo; use OCA\ContactsInteraction\Listeners\ContactInteractionListener; +use OCA\ContactsInteraction\Listeners\UserDeletedListener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Contacts\Events\ContactInteractedWithEvent; +use OCP\User\Events\UserDeletedEvent; class Application extends App implements IBootstrap { public const APP_ID = 'contactsinteraction'; @@ -24,6 +26,7 @@ class Application extends App implements IBootstrap { public function register(IRegistrationContext $context): void { $context->registerEventListener(ContactInteractedWithEvent::class, ContactInteractionListener::class); + $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); } public function boot(IBootContext $context): void { diff --git a/apps/contactsinteraction/lib/Db/RecentContactMapper.php b/apps/contactsinteraction/lib/Db/RecentContactMapper.php index 02d2c1e8ea1..984e7fa9d00 100644 --- a/apps/contactsinteraction/lib/Db/RecentContactMapper.php +++ b/apps/contactsinteraction/lib/Db/RecentContactMapper.php @@ -112,4 +112,14 @@ class RecentContactMapper extends QBMapper { $delete->executeStatement(); } + + public function deleteByUserId(string $uid): void { + $qb = $this->db->getQueryBuilder(); + + $delete = $qb + ->delete($this->getTableName()) + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); + + $delete->executeStatement(); + } } diff --git a/apps/contactsinteraction/lib/Listeners/UserDeletedListener.php b/apps/contactsinteraction/lib/Listeners/UserDeletedListener.php new file mode 100644 index 00000000000..91b0a5facec --- /dev/null +++ b/apps/contactsinteraction/lib/Listeners/UserDeletedListener.php @@ -0,0 +1,35 @@ + + */ +class UserDeletedListener implements IEventListener { + + public function __construct( + private readonly RecentContactMapper $recentContactMapper, + ) { + } + + #[\Override] + public function handle(Event $event): void { + if (!($event instanceof UserDeletedEvent)) { + return; + } + + $this->recentContactMapper->deleteByUserId($event->getUser()->getUID()); + } +}