Skip to content
Open
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
11 changes: 6 additions & 5 deletions lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tests/php/RoomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
55 changes: 55 additions & 0 deletions tests/php/Service/RoomServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading