summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-03-12 17:41:20 +0100
committerJoas Schilling <coding@schilljs.com>2024-03-13 10:51:19 +0100
commitb2a7e4193348da6f28e7258859879cf5799e43ce (patch)
tree25a7068108192cd28e596cc19a98e8ec4b53286b /lib
parenta2ee00c94ce775495bdfbe692076fd48b9e1fe38 (diff)
fix(federation): Remove queued retry OCM notifications on attendee removal
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php2
-rw-r--r--lib/Federation/Proxy/TalkV1/Notifier/CancelRetryOCMListener.php55
-rw-r--r--lib/Model/RetryNotificationMapper.php7
3 files changed, 64 insertions, 0 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 88b40cbb1..c627779fe 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -84,6 +84,7 @@ use OCA\Talk\Events\SystemMessageSentEvent;
use OCA\Talk\Events\SystemMessagesMultipleSentEvent;
use OCA\Talk\Events\UserJoinedRoomEvent;
use OCA\Talk\Federation\CloudFederationProviderTalk;
+use OCA\Talk\Federation\Proxy\TalkV1\Notifier\CancelRetryOCMListener as TalkV1CancelRetryOCMListener;
use OCA\Talk\Federation\Proxy\TalkV1\Notifier\MessageSentListener as TalkV1MessageSentListener;
use OCA\Talk\Federation\Proxy\TalkV1\Notifier\RoomModifiedListener as TalkV1RoomModifiedListener;
use OCA\Talk\Files\Listener as FilesListener;
@@ -284,6 +285,7 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(ChatMessageSentEvent::class, TalkV1MessageSentListener::class);
$context->registerEventListener(SystemMessageSentEvent::class, TalkV1MessageSentListener::class);
$context->registerEventListener(SystemMessagesMultipleSentEvent::class, TalkV1MessageSentListener::class);
+ $context->registerEventListener(AttendeeRemovedEvent::class, TalkV1CancelRetryOCMListener::class);
// Signaling listeners (External)
$context->registerEventListener(AttendeesAddedEvent::class, SignalingListener::class);
diff --git a/lib/Federation/Proxy/TalkV1/Notifier/CancelRetryOCMListener.php b/lib/Federation/Proxy/TalkV1/Notifier/CancelRetryOCMListener.php
new file mode 100644
index 000000000..a924ecbf1
--- /dev/null
+++ b/lib/Federation/Proxy/TalkV1/Notifier/CancelRetryOCMListener.php
@@ -0,0 +1,55 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2024 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Talk\Federation\Proxy\TalkV1\Notifier;
+
+use OCA\Talk\Events\AttendeeRemovedEvent;
+use OCA\Talk\Model\Attendee;
+use OCA\Talk\Model\RetryNotificationMapper;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+/**
+ * @template-implements IEventListener<Event>
+ */
+class CancelRetryOCMListener implements IEventListener {
+ public function __construct(
+ protected RetryNotificationMapper $retryNotificationMapper,
+ ) {
+ }
+
+ public function handle(Event $event): void {
+ if (!$event instanceof AttendeeRemovedEvent) {
+ return;
+ }
+
+ $attendee = $event->getAttendee();
+ if ($attendee->getActorType() !== Attendee::ACTOR_FEDERATED_USERS) {
+ return;
+ }
+
+ $this->retryNotificationMapper->deleteByProviderId(
+ (string) $event->getAttendee()->getId()
+ );
+ }
+}
diff --git a/lib/Model/RetryNotificationMapper.php b/lib/Model/RetryNotificationMapper.php
index fe518593a..0395dd80e 100644
--- a/lib/Model/RetryNotificationMapper.php
+++ b/lib/Model/RetryNotificationMapper.php
@@ -59,4 +59,11 @@ class RetryNotificationMapper extends QBMapper {
return $this->findEntities($query);
}
+
+ public function deleteByProviderId($providerId): void {
+ $query = $this->db->getQueryBuilder();
+ $query->delete($this->getTableName())
+ ->where($query->expr()->eq('provider_id', $query->createNamedParameter($providerId)));
+ $query->executeStatement();
+ }
}