зеркало из https://github.com/nextcloud/spreed.git
Add reason for removing participant from room so that hook can determine if the user was removed by moderator.
Signed-off-by: Peter Edens <petere@conceiva.com>
This commit is contained in:
Родитель
5489820cd3
Коммит
4ca16cb2e6
|
@ -891,7 +891,7 @@ class RoomController extends OCSController {
|
|||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
$room->removeUser($targetUser);
|
||||
$room->removeUser($targetUser, Room::PARTICIPANT_REMOVED);
|
||||
return new DataResponse([]);
|
||||
}
|
||||
|
||||
|
@ -919,7 +919,7 @@ class RoomController extends OCSController {
|
|||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
$room->removeUser($currentUser);
|
||||
$room->removeUser($currentUser, Room::PARTICIPANT_LEFT);
|
||||
}
|
||||
|
||||
return new DataResponse([]);
|
||||
|
@ -965,7 +965,7 @@ class RoomController extends OCSController {
|
|||
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
$room->removeParticipantBySession($targetParticipant);
|
||||
$room->removeParticipantBySession($targetParticipant, Room::PARTICIPANT_REMOVED);
|
||||
return new DataResponse([]);
|
||||
}
|
||||
|
||||
|
@ -1110,7 +1110,7 @@ class RoomController extends OCSController {
|
|||
|
||||
if ($this->userId === null) {
|
||||
$participant = $room->getParticipantBySession($sessionId);
|
||||
$room->removeParticipantBySession($participant);
|
||||
$room->removeParticipantBySession($participant, Room::PARTICIPANT_LEFT);
|
||||
} else {
|
||||
$participant = $room->getParticipant($this->userId);
|
||||
$room->leaveRoom($participant->getUser());
|
||||
|
|
|
@ -28,6 +28,7 @@ use OCA\Spreed\Config;
|
|||
use OCA\Spreed\Exceptions\RoomNotFoundException;
|
||||
use OCA\Spreed\Exceptions\ParticipantNotFoundException;
|
||||
use OCA\Spreed\Manager;
|
||||
use OCA\Spreed\Participant;
|
||||
use OCA\Spreed\Room;
|
||||
use OCA\Spreed\Signaling\Messages;
|
||||
use OCA\Spreed\TalkSession;
|
||||
|
@ -399,7 +400,7 @@ class SignalingController extends OCSController {
|
|||
}
|
||||
}
|
||||
|
||||
if ($participant === null) {
|
||||
if (!$participant instanceof Participant) {
|
||||
// User was not invited to the room, check for access to public room.
|
||||
try {
|
||||
$participant = $room->getParticipantBySession($sessionId);
|
||||
|
@ -422,8 +423,8 @@ class SignalingController extends OCSController {
|
|||
} else if ($action === 'leave') {
|
||||
if (!empty($userId)) {
|
||||
$room->leaveRoom($userId);
|
||||
} else if ($participant !== null) {
|
||||
$room->removeParticipantBySession($participant);
|
||||
} else if ($participant instanceof Participant) {
|
||||
$room->removeParticipantBySession($participant, Room::PARTICIPANT_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class Listener {
|
|||
if ($room->getType() === Room::ONE_TO_ONE_CALL || $room->getNumberOfParticipants() === 1) {
|
||||
$room->deleteRoom();
|
||||
} else {
|
||||
$room->removeUser($user);
|
||||
$room->removeUser($user, Room::PARTICIPANT_REMOVED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
lib/Room.php
15
lib/Room.php
|
@ -45,6 +45,9 @@ class Room {
|
|||
public const GROUP_CALL = 2;
|
||||
public const PUBLIC_CALL = 3;
|
||||
|
||||
public const PARTICIPANT_REMOVED = 'remove';
|
||||
public const PARTICIPANT_LEFT = 'leave';
|
||||
|
||||
/** @var Manager */
|
||||
private $manager;
|
||||
/** @var IDBConnection */
|
||||
|
@ -516,8 +519,9 @@ class Room {
|
|||
|
||||
/**
|
||||
* @param IUser $user
|
||||
* @param string $reason
|
||||
*/
|
||||
public function removeUser(IUser $user): void {
|
||||
public function removeUser(IUser $user, string $reason): void {
|
||||
try {
|
||||
$participant = $this->getParticipant($user->getUID());
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
|
@ -527,6 +531,7 @@ class Room {
|
|||
$this->dispatcher->dispatch(self::class . '::preRemoveUser', new GenericEvent($this, [
|
||||
'user' => $user,
|
||||
'participant' => $participant,
|
||||
'reason' => $reason,
|
||||
]));
|
||||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
|
@ -538,15 +543,18 @@ class Room {
|
|||
$this->dispatcher->dispatch(self::class . '::postRemoveUser', new GenericEvent($this, [
|
||||
'user' => $user,
|
||||
'participant' => $participant,
|
||||
'reason' => $reason,
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Participant $participant
|
||||
* @param string $reason
|
||||
*/
|
||||
public function removeParticipantBySession(Participant $participant): void {
|
||||
public function removeParticipantBySession(Participant $participant, string $reason): void {
|
||||
$this->dispatcher->dispatch(self::class . '::preRemoveBySession', new GenericEvent($this, [
|
||||
'participant' => $participant,
|
||||
'reason' => $reason,
|
||||
]));
|
||||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
|
@ -557,6 +565,7 @@ class Room {
|
|||
|
||||
$this->dispatcher->dispatch(self::class . '::postRemoveBySession', new GenericEvent($this, [
|
||||
'participant' => $participant,
|
||||
'reason' => $reason,
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -577,7 +586,7 @@ class Room {
|
|||
$this->dispatcher->dispatch(self::class . '::preJoinRoom', $event);
|
||||
|
||||
if ($event->hasArgument('cancel') && $event->getArgument('cancel') === true) {
|
||||
$this->removeUser($user);
|
||||
$this->removeUser($user, self::PARTICIPANT_LEFT);
|
||||
throw new UnauthorizedException('Participant is not allowed to join');
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ use OCA\Spreed\Chat\CommentsManager;
|
|||
use OCA\Spreed\Config;
|
||||
use OCA\Spreed\Manager;
|
||||
use OCA\Spreed\Participant;
|
||||
use OCA\Spreed\Room;
|
||||
use OCA\Spreed\Signaling\BackendNotifier;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Http\Client\IClientService;
|
||||
|
@ -203,7 +204,7 @@ class BackendNotifierTest extends \Test\TestCase {
|
|||
$testUser->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn($this->userId);
|
||||
$room->removeUser($testUser);
|
||||
$room->removeUser($testUser, Room::PARTICIPANT_REMOVED);
|
||||
|
||||
$requests = $this->controller->getRequests();
|
||||
$bodies = array_map(function($request) use ($room) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче