Remove groups as participants when deleted

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-05-27 15:44:40 +02:00
Родитель 4b2ef5c08a
Коммит 1b6eae491b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
1 изменённых файлов: 20 добавлений и 1 удалений

Просмотреть файл

@ -23,6 +23,10 @@ declare(strict_types=1);
namespace OCA\Talk\Listener; namespace OCA\Talk\Listener;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\EventDispatcher\Event; use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener; use OCP\EventDispatcher\IEventListener;
use OCP\Group\Events\GroupDeletedEvent; use OCP\Group\Events\GroupDeletedEvent;
@ -32,9 +36,17 @@ class GroupDeletedListener implements IEventListener {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var Manager */
private $manager;
/** @var ParticipantService */
private $participantService;
public function __construct(IConfig $config) { public function __construct(IConfig $config,
Manager $manager,
ParticipantService $participantService) {
$this->config = $config; $this->config = $config;
$this->manager = $manager;
$this->participantService = $participantService;
} }
public function handle(Event $event): void { public function handle(Event $event): void {
@ -48,6 +60,13 @@ class GroupDeletedListener implements IEventListener {
$this->removeGroupFromConfig('sip_bridge_groups', $gid); $this->removeGroupFromConfig('sip_bridge_groups', $gid);
$this->removeGroupFromConfig('start_conversations', $gid); $this->removeGroupFromConfig('start_conversations', $gid);
$this->removeGroupFromConfig('allowed_groups', $gid); $this->removeGroupFromConfig('allowed_groups', $gid);
// Remove the group itself from being a participant
$rooms = $this->manager->getRoomsForActor(Attendee::ACTOR_GROUPS, $gid);
foreach ($rooms as $room) {
$participant = $room->getParticipantByActor(Attendee::ACTOR_GROUPS, $gid);
$this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_REMOVED);
}
} }
protected function removeGroupFromConfig(string $configKey, string $removeGroupId): void { protected function removeGroupFromConfig(string $configKey, string $removeGroupId): void {