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
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m

]]></description>

<version>12.0.0-dev.2</version>
<version>12.0.0-dev.3</version>
<licence>agpl</licence>

<author>Daniel Calviño Sánchez</author>
Expand Down
11 changes: 8 additions & 3 deletions lib/Activity/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -75,7 +76,7 @@ public static function register(IEventDispatcher $dispatcher): void {
$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);

Expand All @@ -97,8 +98,12 @@ public static function register(IEventDispatcher $dispatcher): void {
$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
);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ protected function formatRoomV2andV3(Room $room, ?Participant $currentParticipan
'description' => '',
'lastCommonReadMessage' => 0,
'listable' => Room::LISTABLE_NONE,
'callFlag' => Participant::FLAG_DISCONNECTED,
]);
}

Expand Down Expand Up @@ -614,6 +615,7 @@ protected function formatRoomV2andV3(Room $room, ?Participant $currentParticipan
'readOnly' => $room->getReadOnly(),
'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface,
'lastActivity' => $lastActivity,
'callFlag' => $room->getCallFlag(),
'lobbyState' => $room->getLobbyState(),
'lobbyTimer' => $lobbyTimer,
'sipEnabled' => $room->getSIPEnabled(),
Expand All @@ -637,6 +639,7 @@ protected function formatRoomV2andV3(Room $room, ?Participant $currentParticipan
'readOnly' => $room->getReadOnly(),
'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface,
'lastActivity' => $lastActivity,
'callFlag' => $room->getCallFlag(),
'isFavorite' => $attendee->isFavorite(),
'notificationLevel' => $attendee->getNotificationLevel(),
'lobbyState' => $room->getLobbyState(),
Expand Down
1 change: 1 addition & 0 deletions lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function createRoomObject(array $row): Room {
(string) $row['description'],
(string) $row['password'],
(int) $row['active_guests'],
(int) $row['call_flag'],
$activeSince,
$lastActivity,
(int) $row['last_message'],
Expand Down
54 changes: 54 additions & 0 deletions lib/Migration/Version11001Date20210211111527.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Joas Schilling <[email protected]>
*
* @author Joas Schilling <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

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;
}
}
1 change: 1 addition & 0 deletions lib/Model/SelectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function selectRoomsTable(IQueryBuilder $query, string $alias = 'r'): voi
->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')
Expand Down
31 changes: 27 additions & 4 deletions lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class Room {
private $password;
/** @var int */
private $activeGuests;
/** @var int */
private $callFlag;
/** @var \DateTime|null */
private $activeSince;
/** @var \DateTime|null */
Expand Down Expand Up @@ -204,6 +206,7 @@ public function __construct(Manager $manager,
string $description,
string $password,
int $activeGuests,
int $callFlag,
\DateTime $activeSince = null,
\DateTime $lastActivity = null,
int $lastMessageId,
Expand All @@ -229,6 +232,7 @@ public function __construct(Manager $manager,
$this->description = $description;
$this->password = $password;
$this->activeGuests = $activeGuests;
$this->callFlag = $callFlag;
$this->activeSince = $activeSince;
$this->lastActivity = $lastActivity;
$this->lastMessageId = $lastMessageId;
Expand Down Expand Up @@ -318,6 +322,10 @@ public function getActiveGuests(): int {
return $this->activeGuests;
}

public function getCallFlag(): int {
return $this->callFlag;
}

public function getActiveSince(): ?\DateTime {
return $this->activeSince;
}
Expand Down Expand Up @@ -662,18 +670,32 @@ public function setLastActivity(\DateTime $now): bool {

/**
* @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) {
Expand All @@ -682,7 +704,7 @@ public function setActiveSince(\DateTime $since, bool $isGuest): bool {

$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();
Expand All @@ -703,8 +725,9 @@ public function setLastMessage(IComment $message): void {
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'));

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ private function assertRooms($rooms, TableNode $formData) {
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**' : '';
}
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/features/callapi/group.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/php/RoomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -72,6 +73,7 @@ public function testVerifyPassword() {
'description',
'passy',
0,
Participant::FLAG_DISCONNECTED,
null,
null,
0
Expand Down