diff --git a/lib/Room.php b/lib/Room.php index 18213c0a527..1e1a6565680 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -394,11 +394,12 @@ public function setParticipant(?string $userId, Participant $participant): void $this->participant = $participant; } - public function setActiveSince(\DateTime $since, int $callFlag): void { - if (!$this->activeSince) { - $this->activeSince = $since; - } - $this->callFlag |= $callFlag; + public function setActiveSince(?\DateTime $activeSince): void { + $this->activeSince = $activeSince; + } + + public function setCallFlag(int $callFlag): void { + $this->callFlag = $callFlag; } public function getBreakoutRoomMode(): int { diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index d0352113bd6..f1ec619bca1 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -1202,7 +1202,7 @@ public function setActiveSince(Room $room, ?Participant $participant, \DateTime if ($room->getActiveSince() instanceof \DateTime) { // Call is already active, just someone upgrading the call flags - $room->setActiveSince($room->getActiveSince(), $callFlag); + $room->setCallFlag($callFlag); $event = new RoomModifiedEvent($room, ARoomModifiedEvent::PROPERTY_IN_CALL, $callFlag, $oldCallFlag); $this->dispatcher->dispatchTyped($event); @@ -1217,7 +1217,8 @@ public function setActiveSince(Room $room, ?Participant $participant, \DateTime ->andWhere($update->expr()->isNull('active_since')); $result = (bool)$update->executeStatement(); - $room->setActiveSince($since, $callFlag); + $room->setActiveSince($since); + $room->setCallFlag($callFlag); if (!$result) { // Lost the race, someone else updated the database diff --git a/tests/php/RoomTest.php b/tests/php/RoomTest.php index e88a62c175e..f204ee761dc 100644 --- a/tests/php/RoomTest.php +++ b/tests/php/RoomTest.php @@ -67,4 +67,31 @@ public function testGetLobbyTimerIsPure(): void { $this->assertEquals($timer, $room->getLobbyTimer()); $this->assertEquals($timer, $room->getLobbyTimer()); } + + public function testSetActiveSinceSetsValue(): void { + $room = $this->createRoom(); + $since = new \DateTime(); + $room->setActiveSince($since); + $this->assertSame($since, $room->getActiveSince()); + } + + public function testSetActiveSinceAcceptsNull(): void { + $room = $this->createRoom(); + $room->setActiveSince(new \DateTime()); + $room->setActiveSince(null); + $this->assertNull($room->getActiveSince()); + } + + public function testSetCallFlagSetsValue(): void { + $room = $this->createRoom(); + $room->setCallFlag(Participant::FLAG_WITH_VIDEO); + $this->assertSame(Participant::FLAG_WITH_VIDEO, $room->getCallFlag()); + } + + public function testSetCallFlagReplacesValue(): void { + $room = $this->createRoom(); + $room->setCallFlag(Participant::FLAG_IN_CALL); + $room->setCallFlag(Participant::FLAG_WITH_VIDEO); + $this->assertSame(Participant::FLAG_WITH_VIDEO, $room->getCallFlag()); + } } diff --git a/tests/php/Service/RoomServiceTest.php b/tests/php/Service/RoomServiceTest.php index f28fb51454b..68ed6290860 100644 --- a/tests/php/Service/RoomServiceTest.php +++ b/tests/php/Service/RoomServiceTest.php @@ -424,4 +424,59 @@ public function testVerifyPassword(): void { $this->assertSame($verificationResult, ['result' => false, 'url' => 'https://test']); $this->assertSame('passy', $room->getPassword()); } + + public function testSetActiveSinceNoOpWhenFlagsUnchanged(): void { + $since = new \DateTime(); + $room = $this->createMock(Room::class); + $room->method('getActiveSince')->willReturn($since); + $room->method('getCallFlag')->willReturn(Participant::FLAG_WITH_VIDEO); + $room->expects($this->never())->method('setActiveSince'); + $room->expects($this->never())->method('setCallFlag'); + + $result = $this->service->setActiveSince($room, null, $since, Participant::FLAG_WITH_VIDEO, false); + + $this->assertFalse($result); + } + + public function testSetActiveSinceUpgradesCallFlagOnly(): void { + $since = new \DateTime(); + $room = $this->createMock(Room::class); + $room->method('getActiveSince')->willReturn($since); + $room->method('getCallFlag')->willReturn(Participant::FLAG_IN_CALL); + $room->method('getId')->willReturn(0); + $room->expects($this->never())->method('setActiveSince'); + $room->expects($this->once())->method('setCallFlag') + ->with(Participant::FLAG_IN_CALL | Participant::FLAG_WITH_VIDEO); + + $result = $this->service->setActiveSince($room, null, $since, Participant::FLAG_WITH_VIDEO, false); + + $this->assertFalse($result); + } + + public function testSetActiveSinceSetsActiveSinceAndCallFlagOnFreshCall(): void { + $since = new \DateTime(); + $room = $this->createMock(Room::class); + $room->method('getActiveSince')->willReturn(null); + $room->method('getCallFlag')->willReturn(Participant::FLAG_DISCONNECTED); + $room->method('getId')->willReturn(0); + $room->expects($this->once())->method('setActiveSince')->with($since); + $room->expects($this->once())->method('setCallFlag')->with(Participant::FLAG_WITH_VIDEO); + + $this->service->setActiveSince($room, null, $since, Participant::FLAG_WITH_VIDEO, false); + } + + public function testSetActiveSinceMergesExistingFlagOnFreshCall(): void { + // Verifies that flag merging (previously $this->callFlag |= $callFlag in Room) + // is preserved after moving to $callFlag |= $oldCallFlag in RoomService. + $since = new \DateTime(); + $room = $this->createMock(Room::class); + $room->method('getActiveSince')->willReturn(null); + $room->method('getCallFlag')->willReturn(Participant::FLAG_IN_CALL); + $room->method('getId')->willReturn(0); + $room->expects($this->once())->method('setActiveSince')->with($since); + $room->expects($this->once())->method('setCallFlag') + ->with(Participant::FLAG_IN_CALL | Participant::FLAG_WITH_VIDEO); + + $this->service->setActiveSince($room, null, $since, Participant::FLAG_WITH_VIDEO, false); + } }