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 @@ -772,14 +772,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()))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: Can skip this query when we did the deleteByAttendeeId above, but might not have a big impact

$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 @@ -253,18 +253,15 @@ public static function notifyAfterRoomDisconected(ParticipantEvent $event): void
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
37 changes: 33 additions & 4 deletions tests/php/Signaling/BackendNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -35,8 +36,10 @@
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\BreakoutRoomService;
use OCA\Talk\Service\MembershipService;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\RoomService;
use OCA\Talk\Service\SessionService;
use OCA\Talk\Signaling\BackendNotifier;
use OCA\Talk\TalkSession;
use OCA\Talk\Webinary;
Expand All @@ -45,6 +48,7 @@
use OCP\BackgroundJob\IJobList;
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 @@ -91,6 +95,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 @@ -115,7 +121,7 @@ public function setUp(): void {
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$groupManager = $this->createMock(IGroupManager::class);
$userManager = $this->createMock(IUserManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$config = \OC::$server->getConfig();
$this->signalingSecret = 'the-signaling-secret';
$this->baseUrl = 'https://localhost/signaling';
Expand All @@ -128,19 +134,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, $userManager, $this->urlGenerator, $this->timeFactory, $this->dispatcher);
$this->config = new Config($config, $this->secureRandom, $groupManager, $this->userManager, $this->urlGenerator, $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 @@ -490,6 +513,12 @@ public function testRoomDisinviteOnLeaveOfSelfJoinedUser() {
$room = $this->manager->createRoom(Room::TYPE_PUBLIC);
$participant = $this->participantService->joinRoom($roomService, $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