diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index d28e2a74077..35f94d0b7e1 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -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 @@ -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); } @@ -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(); @@ -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()) { @@ -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()); } diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index 7acf7996289..ccf69c939d8 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -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; @@ -23,6 +24,7 @@ public function __construct( protected SessionMapper $sessionMapper, protected IDBConnection $connection, protected ISecureRandom $secureRandom, + protected ITimeFactory $timeFactory, ) { } @@ -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); diff --git a/tests/php/Service/SessionServiceTest.php b/tests/php/Service/SessionServiceTest.php index 7138a356654..08e8a0c9007 100644 --- a/tests/php/Service/SessionServiceTest.php +++ b/tests/php/Service/SessionServiceTest.php @@ -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; @@ -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'; @@ -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, ); }