fix: add missing listener

Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
pull/54805/head
SebastianKrupinski 2025-08-27 11:27:00 +07:00 committed by Andy Scherzinger
parent 47362fa87e
commit 6825548de3
5 changed files with 50 additions and 0 deletions

@ -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',
);

@ -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',
);

@ -27,11 +27,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';
@ -42,6 +44,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 {

@ -128,4 +128,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();
}
}

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\ContactsInteraction\Listeners;
use OCA\ContactsInteraction\Db\RecentContactMapper;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserDeletedEvent;
/**
* @template-implements IEventListener<Event|UserDeletedEvent>
*/
class UserDeletedListener implements IEventListener {
public function __construct(
private RecentContactMapper $recentContactMapper,
) {
}
#[\Override]
public function handle(Event $event): void {
if (!($event instanceof UserDeletedEvent)) {
return;
}
$this->recentContactMapper->deleteByUserId($event->getUser()->getUID());
}
}