Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
69 changes: 69 additions & 0 deletions lib/Status/Listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Carl Schwan <[email protected]>
*
* @author Carl Schwan <[email protected]>
* @author Joas Schilling <[email protected]>
*
* @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\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);
}
}
}