diff options
author | Julien Veyssier <eneiluj@posteo.net> | 2020-11-19 12:34:47 +0100 |
---|---|---|
committer | Julien Veyssier <eneiluj@posteo.net> | 2020-11-27 10:55:07 +0100 |
commit | ab16e924363912896db13e0a996f340ad2964afa (patch) | |
tree | bf5295e4b58e836f2b2aaa6eaffb438f8fd2438f /lib/MatterbridgeManager.php | |
parent | 10ba04b3c81cf2322720d65a86567fab2c3375db (diff) |
remove bridge bot from room when bridge is disabled
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'lib/MatterbridgeManager.php')
-rw-r--r-- | lib/MatterbridgeManager.php | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/MatterbridgeManager.php b/lib/MatterbridgeManager.php index c279a4c7f..7b13d0a08 100644 --- a/lib/MatterbridgeManager.php +++ b/lib/MatterbridgeManager.php @@ -281,10 +281,10 @@ class MatterbridgeManager { * and to generate a new app token (used to connect via matterbridge) * * @param Room $room the room - * @param bool $create whether we should generate a new app token or not + * @param bool $isBridgeEnabled whether we should add the bot and generate a new app token or remove the bot from the room * @return array Bot user information (username and app token). token is an empty string if creation was not asked. */ - private function checkBotUser(Room $room, bool $create): array { + private function checkBotUser(Room $room, bool $isBridgeEnabled): array { $botUserId = 'bridge-bot'; // check if user exists and create it if necessary if (!$this->userManager->userExists($botUserId)) { @@ -299,15 +299,20 @@ class MatterbridgeManager { $botUser = $this->userManager->get($botUserId); } - // check user is member of the room + // check if the bot user is member of the room and add or remove it try { $participant = $room->getParticipant($botUserId); + if (!$isBridgeEnabled) { + $this->participantService->removeUser($room, $botUser, Room::PARTICIPANT_REMOVED); + } } catch (ParticipantNotFoundException $e) { - $this->participantService->addUsers($room, [[ - 'actorType' => Attendee::ACTOR_USERS, - 'actorId' => $botUserId, - 'participantType' => Participant::USER, - ]]); + if ($isBridgeEnabled) { + $this->participantService->addUsers($room, [[ + 'actorType' => Attendee::ACTOR_USERS, + 'actorId' => $botUserId, + 'participantType' => Participant::USER, + ]]); + } } // delete old bot app tokens for this room @@ -319,7 +324,7 @@ class MatterbridgeManager { } } - if ($create) { + if ($isBridgeEnabled) { // generate app token for the bot $appToken = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); $botPassword = $this->config->getAppValue('spreed', 'bridge_bot_password', ''); |