summaryrefslogtreecommitdiffstats
path: root/lib/Notification/Listener.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-03-29 17:11:41 +0200
committerJoas Schilling <coding@schilljs.com>2022-05-17 10:13:40 +0200
commitc15f9d831872e6be4a8214d7bac1c0725eacd119 (patch)
treefc32c70fa3c15d618d076f45a3b892b789ed93af /lib/Notification/Listener.php
parent43a4e291e278eb3580a54f0d611ee827e0163c23 (diff)
Allow to "Send call notifications"
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Listener.php')
-rw-r--r--lib/Notification/Listener.php31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php
index c4da4e2fe..5ca34f052 100644
--- a/lib/Notification/Listener.php
+++ b/lib/Notification/Listener.php
@@ -26,11 +26,14 @@ namespace OCA\Talk\Notification;
use OCA\Talk\Events\AddParticipantsEvent;
use OCA\Talk\Events\JoinRoomUserEvent;
use OCA\Talk\Events\RoomEvent;
+use OCA\Talk\Events\SendCallNotificationEvent;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\EventDispatcher\IEventListener;
use OCP\IDBConnection;
use OCP\Notification\IManager;
use OCP\IUser;
@@ -38,7 +41,7 @@ use OCP\IUserSession;
use OCP\Server;
use Psr\Log\LoggerInterface;
-class Listener {
+class Listener implements IEventListener {
protected IDBConnection $connection;
protected IManager $notificationManager;
protected ParticipantService $participantsService;
@@ -288,4 +291,30 @@ class Listener {
return;
}
}
+
+ public function handle(Event $event): void {
+ if ($event instanceof SendCallNotificationEvent) {
+ $this->sendCallNotification($event->getRoom(), $event->getActor()->getAttendee(), $event->getTarget()->getAttendee());
+ }
+ }
+
+ public function sendCallNotification(Room $room, Attendee $actor, Attendee $target): void {
+ try {
+ // Remove previous call notifications
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('spreed')
+ ->setObject('call', $room->getToken())
+ ->setUser($target->getActorId());
+ $this->notificationManager->markProcessed($notification);
+
+ $dateTime = $this->timeFactory->getDateTime();
+ $notification->setSubject('call', [
+ 'callee' => $actor->getActorId(),
+ ])
+ ->setDateTime($dateTime);
+ $this->notificationManager->notify($notification);
+ } catch (\InvalidArgumentException $e) {
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
+ }
+ }
}