diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index bc4174d94c2..55a40df0516 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -73,6 +73,7 @@ use OCA\Talk\Share\Listener as ShareListener; use OCA\Talk\Share\RoomShareProvider; use OCA\Talk\Signaling\Listener as SignalingListener; +use OCA\Talk\Status\Listener as StatusListener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -158,6 +159,7 @@ public function boot(IBootContext $context): void { ResourceListener::register($dispatcher); ChangelogListener::register($dispatcher); ShareListener::register($dispatcher); + StatusListener::register($dispatcher); $this->registerRoomActivityHooks($dispatcher); $this->registerChatHooks($dispatcher); diff --git a/lib/Status/Listener.php b/lib/Status/Listener.php new file mode 100644 index 00000000000..a41953ea6ee --- /dev/null +++ b/lib/Status/Listener.php @@ -0,0 +1,69 @@ + + * + * @author Carl Schwan + * @author Joas Schilling + * + * @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 . + * + */ + +namespace OCA\Talk\Status; + +use OCA\Talk\Events\ModifyParticipantEvent; +use OCA\Talk\Model\Attendee; +use OCA\Talk\Room; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\UserStatus\IManager; +use OCP\UserStatus\IUserStatus; + +class Listener { + /** @var IManager $statusManager */ + public $statusManager; + + public function __construct(IManager $statusManager) { + $this->statusManager = $statusManager; + } + + public static function register(IEventDispatcher $dispatcher): void { + $dispatcher->addListener(Room::EVENT_BEFORE_SESSION_JOIN_CALL, static function (ModifyParticipantEvent $event) { + /** @var self $listener */ + $listener = \OC::$server->get(self::class); + $listener->setUserStatus($event); + }); + + $dispatcher->addListener(Room::EVENT_AFTER_SESSION_LEAVE_CALL, static function (ModifyParticipantEvent $event) { + /** @var self $listener */ + $listener = \OC::$server->get(self::class); + $listener->revertUserStatus($event); + }); + } + + public function setUserStatus(ModifyParticipantEvent $event): void { + if ($event->getParticipant()->getAttendee()->getActorType() === Attendee::ACTOR_USERS) { + $this->statusManager->setUserStatus($event->getParticipant()->getAttendee()->getActorId(), 'call', IUserStatus::AWAY, true); + } + } + + public function revertUserStatus(ModifyParticipantEvent $event): void { + if ($event->getParticipant()->getAttendee()->getActorType() === Attendee::ACTOR_USERS) { + $this->statusManager->revertUserStatus($event->getParticipant()->getAttendee()->getActorId(), 'call', IUserStatus::AWAY); + } + } +}