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
12 changes: 6 additions & 6 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,14 @@ public function leaveRoomAsSession(Room $room, Participant $participant, bool $d
$this->sessionMapper->deleteByAttendeeId($participant->getAttendee()->getId());
}

if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
$this->attendeeMapper->delete($participant->getAttendee());
$this->dispatcher->dispatch(Room::EVENT_AFTER_ROOM_DISCONNECT, $event);

$attendeeEvent = new AttendeesRemovedEvent($room, [$participant->getAttendee()]);
$this->dispatcher->dispatchTyped($attendeeEvent);
}
if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED
&& empty($this->sessionMapper->findByAttendeeId($participant->getAttendee()->getId()))) {
$user = $this->userManager->get($participant->getAttendee()->getActorId());

$this->dispatcher->dispatch(Room::EVENT_AFTER_ROOM_DISCONNECT, $event);
$this->removeUser($room, $user, Room::PARTICIPANT_LEFT);
}
}

public function removeAttendee(Room $room, Participant $participant, string $reason, bool $attendeeEventIsTriggeredAlready = false): void {
Expand Down
7 changes: 2 additions & 5 deletions lib/Signaling/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,15 @@ protected static function registerExternalSignaling(IEventDispatcher $dispatcher
if ($event->getParticipant()->getSession()) {
// If a previous duplicated session is being removed it must be
// notified to the external signaling server. Otherwise only for
// guests and self-joined users disconnecting is "leaving" and
// therefor should trigger a disinvite.
// guests disconnecting is "leaving" and therefor should trigger
// a disinvite.
$attendeeParticipantType = $event->getParticipant()->getAttendee()->getParticipantType();
if ($event instanceof DuplicatedParticipantEvent
|| $attendeeParticipantType === Participant::GUEST
|| $attendeeParticipantType === Participant::GUEST_MODERATOR) {
$sessionIds[] = $event->getParticipant()->getSession()->getSessionId();
$notifier->roomSessionsRemoved($event->getRoom(), $sessionIds);
}
if ($attendeeParticipantType === Participant::USER_SELF_JOINED) {
$notifier->roomsDisinvited($event->getRoom(), [$event->getParticipant()->getAttendee()->getActorId()]);
}
}
});

Expand Down
34 changes: 32 additions & 2 deletions tests/php/Signaling/BackendNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@
use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Config;
use OCA\Talk\Events\SignalingRoomPropertiesEvent;
use OCA\Talk\Federation\Notifications;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\AttendeeMapper;
use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\MembershipService;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\SessionService;
use OCA\Talk\Signaling\BackendNotifier;
use OCA\Talk\TalkSession;
use OCA\Talk\Webinary;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Http\Client\IClientService;
use OCP\ICacheFactory;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -84,6 +88,8 @@ class BackendNotifierTest extends TestCase {
private $signalingManager;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var IUserManager|MockObject */
private $userManager;
private ?\OCA\Talk\Tests\php\Signaling\CustomBackendNotifier $controller = null;

private ?Manager $manager = null;
Expand All @@ -104,6 +110,7 @@ public function setUp(): void {
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$config = \OC::$server->getConfig();
$this->signalingSecret = 'the-signaling-secret';
$this->baseUrl = 'https://localhost/signaling';
Expand All @@ -116,19 +123,36 @@ public function setUp(): void {
],
]));

$this->participantService = \OC::$server->get(ParticipantService::class);
$this->signalingManager = $this->createMock(\OCA\Talk\Signaling\Manager::class);
$this->signalingManager->expects($this->any())
->method('getSignalingServerForConversation')
->willReturn(['server' => $this->baseUrl]);

$this->dispatcher = \OC::$server->get(IEventDispatcher::class);
$this->config = new Config($config, $this->secureRandom, $groupManager, $this->timeFactory, $this->dispatcher);

$dbConnection = \OC::$server->getDatabaseConnection();
$this->participantService = new ParticipantService(
$config,
$this->config,
\OC::$server->get(AttendeeMapper::class),
\OC::$server->get(SessionMapper::class),
\OC::$server->get(SessionService::class),
$this->secureRandom,
$dbConnection,
$this->dispatcher,
$this->userManager,
$groupManager,
\OC::$server->get(MembershipService::class),
\OC::$server->get(Notifications::class),
$this->timeFactory,
\OC::$server->get(ICacheFactory::class)
);

$this->recreateBackendNotifier();

$this->overwriteService(BackendNotifier::class, $this->controller);

$dbConnection = \OC::$server->getDatabaseConnection();
$this->manager = new Manager(
$dbConnection,
$config,
Expand Down Expand Up @@ -403,6 +427,12 @@ public function testRoomDisinviteOnLeaveOfSelfJoinedUser() {
$room = $this->manager->createRoom(Room::TYPE_PUBLIC);
$participant = $this->participantService->joinRoom($room, $testUser, '');
$this->controller->clearRequests();

$this->userManager->expects($this->once())
->method('get')
->with($this->userId)
->willReturn($testUser);

$this->participantService->leaveRoomAsSession($room, $participant);

$this->assertMessageWasSent($room, [
Expand Down