diff --git a/appinfo/info.xml b/appinfo/info.xml index a5c36531a..9bb262650 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m ]]> - 12.0.0-dev.2 + 12.0.0-dev.3 agpl Daniel Calviño Sánchez diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index 474496067..6b39bc3de 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -28,6 +28,7 @@ use OCA\Talk\Events\AddParticipantsEvent; use OCA\Talk\Events\ModifyParticipantEvent; use OCA\Talk\Events\RoomEvent; use OCA\Talk\Model\Attendee; +use OCA\Talk\Participant; use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\Activity\IManager; @@ -75,7 +76,7 @@ class Listener { $listener = static function (ModifyParticipantEvent $event) { /** @var self $listener */ $listener = \OC::$server->query(self::class); - $listener->setActive($event->getRoom()); + $listener->setActive($event->getRoom(), $event->getParticipant()); }; $dispatcher->addListener(Room::EVENT_AFTER_SESSION_JOIN_CALL, $listener); @@ -97,8 +98,12 @@ class Listener { $dispatcher->addListener(Room::EVENT_AFTER_USERS_ADD, $listener); } - public function setActive(Room $room): void { - $room->setActiveSince($this->timeFactory->getDateTime(), !$this->userSession->isLoggedIn()); + public function setActive(Room $room, Participant $participant): void { + $room->setActiveSince( + $this->timeFactory->getDateTime(), + $participant->getSession() ? $participant->getSession()->getInCall() : Participant::FLAG_DISCONNECTED, + $participant->getAttendee()->getActorType() !== Attendee::ACTOR_USERS + ); } /** diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 92a5d1855..839ad2572 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -586,6 +586,7 @@ class RoomController extends AEnvironmentAwareController { 'description' => '', 'lastCommonReadMessage' => 0, 'listable' => Room::LISTABLE_NONE, + 'callFlag' => Participant::FLAG_DISCONNECTED, ]); } @@ -614,6 +615,7 @@ class RoomController extends AEnvironmentAwareController { 'readOnly' => $room->getReadOnly(), 'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface, 'lastActivity' => $lastActivity, + 'callFlag' => $room->getCallFlag(), 'lobbyState' => $room->getLobbyState(), 'lobbyTimer' => $lobbyTimer, 'sipEnabled' => $room->getSIPEnabled(), @@ -637,6 +639,7 @@ class RoomController extends AEnvironmentAwareController { 'readOnly' => $room->getReadOnly(), 'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface, 'lastActivity' => $lastActivity, + 'callFlag' => $room->getCallFlag(), 'isFavorite' => $attendee->isFavorite(), 'notificationLevel' => $attendee->getNotificationLevel(), 'lobbyState' => $room->getLobbyState(), diff --git a/lib/Manager.php b/lib/Manager.php index a32729f43..a7c529c3f 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -187,6 +187,7 @@ class Manager { (string) $row['description'], (string) $row['password'], (int) $row['active_guests'], + (int) $row['call_flag'], $activeSince, $lastActivity, (int) $row['last_message'], diff --git a/lib/Migration/Version11001Date20210211111527.php b/lib/Migration/Version11001Date20210211111527.php new file mode 100644 index 000000000..ee4a47d51 --- /dev/null +++ b/lib/Migration/Version11001Date20210211111527.php @@ -0,0 +1,54 @@ + + * + * @author Joas Schilling + * + * @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 . + * + */ + +namespace OCA\Talk\Migration; + +use Closure; +use Doctrine\DBAL\Types\Types; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version11001Date20210211111527 extends SimpleMigrationStep { + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('talk_rooms'); + if (!$table->hasColumn('call_flag')) { + $table->addColumn('call_flag', Types::INTEGER, [ + 'default' => 0, + ]); + return $schema; + } + return null; + } +} diff --git a/lib/Model/SelectHelper.php b/lib/Model/SelectHelper.php index 48973cacc..ade976f5c 100644 --- a/lib/Model/SelectHelper.php +++ b/lib/Model/SelectHelper.php @@ -42,6 +42,7 @@ class SelectHelper { ->addSelect($alias . 'password') ->addSelect($alias . 'active_guests') ->addSelect($alias . 'active_since') + ->addSelect($alias . 'call_flag') ->addSelect($alias . 'last_activity') ->addSelect($alias . 'last_message') ->addSelect($alias . 'lobby_timer') diff --git a/lib/Room.php b/lib/Room.php index d0a594910..312d8189e 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -168,6 +168,8 @@ class Room { private $password; /** @var int */ private $activeGuests; + /** @var int */ + private $callFlag; /** @var \DateTime|null */ private $activeSince; /** @var \DateTime|null */ @@ -204,6 +206,7 @@ class Room { string $description, string $password, int $activeGuests, + int $callFlag, \DateTime $activeSince = null, \DateTime $lastActivity = null, int $lastMessageId, @@ -229,6 +232,7 @@ class Room { $this->description = $description; $this->password = $password; $this->activeGuests = $activeGuests; + $this->callFlag = $callFlag; $this->activeSince = $activeSince; $this->lastActivity = $lastActivity; $this->lastMessageId = $lastMessageId; @@ -318,6 +322,10 @@ class Room { return $this->activeGuests; } + public function getCallFlag(): int { + return $this->callFlag; + } + public function getActiveSince(): ?\DateTime { return $this->activeSince; } @@ -662,18 +670,32 @@ class Room { /** * @param \DateTime $since + * @param int $callFlag * @param bool $isGuest * @return bool */ - public function setActiveSince(\DateTime $since, bool $isGuest): bool { + public function setActiveSince(\DateTime $since, int $callFlag, bool $isGuest): bool { if ($isGuest && $this->getType() === self::PUBLIC_CALL) { $query = $this->db->getQueryBuilder(); $query->update('talk_rooms') ->set('active_guests', $query->createFunction($query->getColumnName('active_guests') . ' + 1')) + ->set( + 'call_flag', + $query->expr()->bitwiseOr('call_flag', $callFlag) + ) ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); $query->execute(); $this->activeGuests++; + } elseif (!$isGuest) { + $query = $this->db->getQueryBuilder(); + $query->update('talk_rooms') + ->set( + 'call_flag', + $query->expr()->bitwiseOr('call_flag', $callFlag) + ) + ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); + $query->execute(); } if ($this->activeSince instanceof \DateTime) { @@ -682,7 +704,7 @@ class Room { $query = $this->db->getQueryBuilder(); $query->update('talk_rooms') - ->set('active_since', $query->createNamedParameter($since, 'datetime')) + ->set('active_since', $query->createNamedParameter($since, IQueryBuilder::PARAM_DATE)) ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->isNull('active_since')); $query->execute(); @@ -703,8 +725,9 @@ class Room { public function resetActiveSince(): bool { $query = $this->db->getQueryBuilder(); $query->update('talk_rooms') - ->set('active_guests', $query->createNamedParameter(0)) - ->set('active_since', $query->createNamedParameter(null, 'datetime')) + ->set('active_guests', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)) + ->set('active_since', $query->createNamedParameter(null, IQueryBuilder::PARAM_DATE)) + ->set('call_flag', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->isNotNull('active_since')); diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 4ccad6689..948658422 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -270,6 +270,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { if (isset($expectedRoom['sipEnabled'])) { $data['sipEnabled'] = (string) $room['sipEnabled']; } + if (isset($expectedRoom['callFlag'])) { + $data['callFlag'] = (int) $room['callFlag']; + } if (isset($expectedRoom['attendeePin'])) { $data['attendeePin'] = $room['attendeePin'] ? '**PIN**' : ''; } diff --git a/tests/integration/features/callapi/group.feature b/tests/integration/features/callapi/group.feature index 18969c72d..ed46e4d87 100644 --- a/tests/integration/features/callapi/group.feature +++ b/tests/integration/features/callapi/group.feature @@ -23,14 +23,21 @@ Feature: callapi/group Then user "participant1" sees 0 peers in call "room" with 200 And user "participant2" sees 0 peers in call "room" with 200 Then user "participant1" joins call "room" with 200 + | flags | 1 | Then user "participant1" sees 1 peers in call "room" with 200 And user "participant2" sees 1 peers in call "room" with 200 + Then user "participant1" is participant of the following rooms (v3) + | id | type | callFlag | + | room | 2 | 1 | Then user "participant2" joins room "room" with 200 Then user "participant1" sees 1 peers in call "room" with 200 And user "participant2" sees 1 peers in call "room" with 200 And user "participant2" joins call "room" with 200 Then user "participant1" sees 2 peers in call "room" with 200 And user "participant2" sees 2 peers in call "room" with 200 + Then user "participant1" is participant of the following rooms (v3) + | id | type | callFlag | + | room | 2 | 7 | Then user "participant1" leaves call "room" with 200 Then user "participant1" sees 1 peers in call "room" with 200 And user "participant2" sees 1 peers in call "room" with 200 diff --git a/tests/php/RoomTest.php b/tests/php/RoomTest.php index 5c710c4f4..960ec0111 100644 --- a/tests/php/RoomTest.php +++ b/tests/php/RoomTest.php @@ -25,6 +25,7 @@ namespace OCA\Talk\Tests\php; use OC\EventDispatcher\EventDispatcher; use OCA\Talk\Events\VerifyRoomPasswordEvent; use OCA\Talk\Manager; +use OCA\Talk\Participant; use OCA\Talk\Room; use OCA\Talk\Webinary; use OCP\AppFramework\Utility\ITimeFactory; @@ -72,6 +73,7 @@ class RoomTest extends TestCase { 'description', 'passy', 0, + Participant::FLAG_DISCONNECTED, null, null, 0