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
2 changes: 1 addition & 1 deletion lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ public function joinRoom(string $token, string $password = '', bool $force = tru
$this->participantService->changeInCall($room, $previousParticipant, Participant::FLAG_DISCONNECTED);
}

$this->participantService->leaveRoomAsSession($room, $previousParticipant);
$this->participantService->leaveRoomAsSession($room, $previousParticipant, true);
}

$user = $this->userManager->get($this->userId);
Expand Down
34 changes: 34 additions & 0 deletions lib/Events/DuplicatedParticipantEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Daniel Calviño Sánchez <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Talk\Events;

use OCA\Talk\Participant;
use OCA\Talk\Room;

class DuplicatedParticipantEvent extends ParticipantEvent {
public function __construct(Room $room,
Participant $participant) {
parent::__construct($room, $participant);
}
}
20 changes: 10 additions & 10 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\Talk\Events\AttendeesAddedEvent;
use OCA\Talk\Events\AttendeesRemovedEvent;
use OCA\Talk\Events\ChatEvent;
use OCA\Talk\Events\DuplicatedParticipantEvent;
use OCA\Talk\Events\EndCallForEveryoneEvent;
use OCA\Talk\Events\JoinRoomGuestEvent;
use OCA\Talk\Events\JoinRoomUserEvent;
Expand Down Expand Up @@ -687,23 +688,22 @@ public function ensureOneToOneRoomIsFilled(Room $room): void {
}
}

public function leaveRoomAsSession(Room $room, Participant $participant): void {
$event = new ParticipantEvent($room, $participant);
public function leaveRoomAsSession(Room $room, Participant $participant, bool $duplicatedParticipant = false): void {
if ($duplicatedParticipant) {
$event = new DuplicatedParticipantEvent($room, $participant);
} else {
$event = new ParticipantEvent($room, $participant);
}
$this->dispatcher->dispatch(Room::EVENT_BEFORE_ROOM_DISCONNECT, $event);

$session = $participant->getSession();
if ($session instanceof Session) {
$dispatchLeaveCallEvents = $session->getInCall() !== Participant::FLAG_DISCONNECTED;
if ($dispatchLeaveCallEvents) {
$event = new ModifyParticipantEvent($room, $participant, 'inCall', Participant::FLAG_DISCONNECTED, $session->getInCall());
$this->dispatcher->dispatch(Room::EVENT_BEFORE_SESSION_LEAVE_CALL, $event);
$isInCall = $session->getInCall() !== Participant::FLAG_DISCONNECTED;
if ($isInCall) {
$this->changeInCall($room, $participant, Participant::FLAG_DISCONNECTED);
}

$this->sessionMapper->delete($session);

if ($dispatchLeaveCallEvents) {
$this->dispatcher->dispatch(Room::EVENT_AFTER_SESSION_LEAVE_CALL, $event);
}
} else {
$this->sessionMapper->deleteByAttendeeId($participant->getAttendee()->getId());
}
Expand Down
9 changes: 7 additions & 2 deletions lib/Signaling/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\Talk\Config;
use OCA\Talk\Events\AddParticipantsEvent;
use OCA\Talk\Events\ChatEvent;
use OCA\Talk\Events\DuplicatedParticipantEvent;
use OCA\Talk\Events\EndCallForEveryoneEvent;
use OCA\Talk\Events\ModifyEveryoneEvent;
use OCA\Talk\Events\ModifyParticipantEvent;
Expand Down Expand Up @@ -252,9 +253,13 @@ protected static function registerExternalSignaling(IEventDispatcher $dispatcher

$sessionIds = [];
if ($event->getParticipant()->getSession()) {
// Only for guests and self-joined users disconnecting is "leaving" and therefor should trigger a disinvite
// 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.
$attendeeParticipantType = $event->getParticipant()->getAttendee()->getParticipantType();
if ($attendeeParticipantType === Participant::GUEST
if ($event instanceof DuplicatedParticipantEvent
|| $attendeeParticipantType === Participant::GUEST
|| $attendeeParticipantType === Participant::GUEST_MODERATOR) {
$sessionIds[] = $event->getParticipant()->getSession()->getSessionId();
$notifier->roomSessionsRemoved($event->getRoom(), $sessionIds);
Expand Down
79 changes: 79 additions & 0 deletions tests/php/Signaling/BackendNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,46 @@ public function testNoRoomDisinviteOnLeaveOfNormalUser() {
$this->assertNoMessageOfTypeWasSent($room, 'disinvite');
}

public function testRoomDisinviteOnLeaveOfNormalUserWithDuplicatedSession() {
/** @var IUser|MockObject $testUser */
$testUser = $this->createMock(IUser::class);
$testUser->expects($this->any())
->method('getUID')
->willReturn($this->userId);

$room = $this->manager->createRoom(Room::TYPE_PUBLIC);
$this->participantService->addUsers($room, [[
'actorType' => 'users',
'actorId' => $this->userId,
]]);
$participant = $this->participantService->joinRoom($room, $testUser, '');
$this->controller->clearRequests();
$this->participantService->leaveRoomAsSession($room, $participant, true);

$this->assertMessageWasSent($room, [
'type' => 'disinvite',
'disinvite' => [
'sessionids' => [
$participant->getSession()->getSessionId(),
],
'alluserids' => [
$this->userId,
],
'properties' => [
'name' => $room->getDisplayName(''),
'type' => $room->getType(),
'lobby-state' => Webinary::LOBBY_NONE,
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'listable' => Room::LISTABLE_NONE,
'active-since' => null,
'sip-enabled' => 0,
'participant-list' => 'refresh',
],
],
]);
}

public function testRoomDisinviteOnLeaveOfSelfJoinedUser() {
/** @var IUser|MockObject $testUser */
$testUser = $this->createMock(IUser::class);
Expand Down Expand Up @@ -697,6 +737,45 @@ public function testRoomInCallChanged() {
]);
}

public function testRoomInCallChangedWhenLeavingConversationWhileInCall() {
/** @var IUser|MockObject $testUser */
$testUser = $this->createMock(IUser::class);
$testUser->expects($this->any())
->method('getUID')
->willReturn($this->userId);

$room = $this->manager->createRoom(Room::TYPE_PUBLIC);
$this->participantService->addUsers($room, [[
'actorType' => 'users',
'actorId' => $this->userId,
]]);
$participant = $this->participantService->joinRoom($room, $testUser, '');
$userSession = $participant->getSession()->getSessionId();
$this->participantService->changeInCall($room, $participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
$this->controller->clearRequests();
$this->participantService->leaveRoomAsSession($room, $participant);

$this->assertMessageWasSent($room, [
'type' => 'incall',
'incall' => [
'incall' => 0,
'changed' => [
[
'inCall' => 0,
'lastPing' => 0,
'sessionId' => $userSession,
'nextcloudSessionId' => $userSession,
'participantType' => Participant::USER,
'participantPermissions' => (Attendee::PERMISSIONS_MAX_DEFAULT ^ Attendee::PERMISSIONS_LOBBY_IGNORE),
'userId' => $this->userId,
],
],
'users' => [
],
],
]);
}

public function testRoomPropertiesEvent(): void {
$listener = static function (SignalingRoomPropertiesEvent $event) {
$room = $event->getRoom();
Expand Down