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
14 changes: 6 additions & 8 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,8 @@ protected function formatParticipantList(array $participants, bool $includeStatu
if ($session->getLastPing() <= $maxPingAge) {
if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_GUESTS) {
$cleanGuests = true;
} elseif ($participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) {
} elseif ($participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS
|| $participant->getAttendee()->getActorType() === Attendee::ACTOR_FEDERATED_USERS) {
$this->participantService->leaveRoomAsSession($this->room, $participant);
}
// Session expired, ignore
Expand Down Expand Up @@ -1030,7 +1031,7 @@ protected function formatParticipantList(array $participants, bool $includeStatu

if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) {
$userId = $participant->getAttendee()->getActorId();
if ($result['lastPing'] > 0 && $result['lastPing'] <= $maxPingAge) {
if ($participant->getSession() instanceof Session && $participant->getSession()->getLastPing() <= $maxPingAge) {
$this->participantService->leaveRoomAsSession($this->room, $participant);
}

Expand Down Expand Up @@ -1075,6 +1076,9 @@ protected function formatParticipantList(array $participants, bool $includeStatu
} elseif ($participant->getAttendee()->getActorType() === Attendee::ACTOR_CIRCLES) {
$result['displayName'] = $participant->getAttendee()->getDisplayName();
} elseif ($participant->getAttendee()->getActorType() === Attendee::ACTOR_FEDERATED_USERS) {
if ($participant->getSession() instanceof Session && $participant->getSession()->getLastPing() <= $maxPingAge) {
$this->participantService->leaveRoomAsSession($this->room, $participant);
}
$result['displayName'] = $participant->getAttendee()->getDisplayName();
} elseif ($participant->getAttendee()->getActorType() === Attendee::ACTOR_PHONES) {
$result['displayName'] = $participant->getAttendee()->getDisplayName();
Expand Down Expand Up @@ -1640,7 +1644,6 @@ public function joinRoom(string $token, string $password = '', bool $force = tru
$session = $participant->getSession();
if ($session instanceof Session) {
$this->session->setSessionForRoom($token, $session->getSessionId());
$this->sessionService->updateLastPing($session, $this->timeFactory->getTime());
}

if ($room->isFederatedConversation()) {
Expand Down Expand Up @@ -1710,11 +1713,6 @@ public function joinFederatedRoom(string $token, ?string $sessionId): DataRespon

if ($sessionId !== null) {
$participant = $this->participantService->joinRoomAsFederatedUser($room, Attendee::ACTOR_FEDERATED_USERS, $this->federationAuthenticator->getCloudId(), $sessionId);

$session = $participant->getSession();
if ($session instanceof Session) {
$this->sessionService->updateLastPing($session, $this->timeFactory->getTime());
}
} else {
$participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_FEDERATED_USERS, $this->federationAuthenticator->getCloudId());
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/SessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\Talk\Model\Session;
use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Participant;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
Expand All @@ -23,6 +24,7 @@ public function __construct(
protected SessionMapper $sessionMapper,
protected IDBConnection $connection,
protected ISecureRandom $secureRandom,
protected ITimeFactory $timeFactory,
) {
}

Expand Down Expand Up @@ -87,6 +89,7 @@ public function createSessionForAttendee(Attendee $attendee, string $forceSessio
$session = new Session();
$session->setAttendeeId($attendee->getId());
$session->setInCall(Participant::FLAG_DISCONNECTED);
$session->setLastPing($this->timeFactory->getTime());

if ($forceSessionId !== '') {
$session->setSessionId($forceSessionId);
Expand Down
4 changes: 4 additions & 0 deletions tests/php/Service/SessionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Service\SessionService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -22,6 +23,7 @@
class SessionServiceTest extends TestCase {
protected ?SessionMapper $sessionMapper = null;
protected ISecureRandom&MockObject $secureRandom;
protected ITimeFactory&MockObject $timeFactory;
private ?SessionService $service = null;

private const RANDOM_254 = '123456789abcdef0123456789abcdef1123456789abcdef2123456789abcdef3123456789abcdef4123456789abcdef5123456789abcdef6123456789abcdef7123456789abcdef8123456789abcdef9123456789abcdefa123456789abcdefb123456789abcdefc123456789abcdefd123456789abcdefe123456789abcde';
Expand All @@ -33,10 +35,12 @@ public function setUp(): void {

$this->sessionMapper = \OCP\Server::get(SessionMapper::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->service = new SessionService(
$this->sessionMapper,
\OCP\Server::get(IDBConnection::class),
$this->secureRandom,
$this->timeFactory,
);
}

Expand Down