From a0d5a835a95e66a426887f5dc8c5ca3c27a83b3f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Jul 2019 16:45:57 +0200 Subject: [PATCH] Add a new column to record who joined a call This makes sure users that only joined the chat are not listed in the call summary Signed-off-by: Joas Schilling --- appinfo/info.xml | 2 +- lib/Activity/Listener.php | 2 +- lib/Manager.php | 40 ++++++++++++++- .../Version7000Date20190717141457.php | 51 +++++++++++++++++++ lib/Participant.php | 13 ++++- lib/Room.php | 15 ++++-- 6 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 lib/Migration/Version7000Date20190717141457.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 4b2e17891..c7499f98b 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 ]]> - 7.0.0-dev.0 + 7.0.0-dev.1 agpl Daniel Calviño Sánchez diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index dadd5f625..32deaef52 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -112,7 +112,7 @@ class Listener { } $duration = $this->timeFactory->getTime() - $activeSince->getTimestamp(); - $userIds = $room->getParticipantUserIds($activeSince->getTimestamp()); + $userIds = $room->getParticipantUserIds($activeSince); if (empty($userIds) || (\count($userIds) === 1 && $room->getActiveGuests() === 0)) { // Single user pinged or guests only => no activity diff --git a/lib/Manager.php b/lib/Manager.php index 473482225..de9ce758e 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -126,7 +126,26 @@ class Manager { ])); } - return new Room($this, $this->db, $this->secureRandom, $this->dispatcher, $this->timeFactory, $this->hasher, (int) $row['id'], (int) $row['type'], (int) $row['read_only'], $row['token'], $row['name'], $row['password'], (int) $row['active_guests'], $activeSince, $lastActivity, $lastMessage, (string) $row['object_type'], (string) $row['object_id']); + return new Room( + $this, + $this->db, + $this->secureRandom, + $this->dispatcher, + $this->timeFactory, + $this->hasher, + (int) $row['id'], + (int) $row['type'], + (int) $row['read_only'], + $row['token'], + $row['name'], + $row['password'], + (int) $row['active_guests'], + $activeSince, + $lastActivity, + $lastMessage, + (string) $row['object_type'], + (string) $row['object_id'] + ); } /** @@ -140,7 +159,24 @@ class Manager { $lastMention = $this->timeFactory->getDateTime($row['last_mention']); } - return new Participant($this->db, $room, (string) $row['user_id'], (int) $row['participant_type'], (int) $row['last_ping'], (string) $row['session_id'], (int) $row['in_call'], (int) $row['notification_level'], (bool) $row['favorite'], $lastMention); + $lastJoinedCall = null; + if (!empty($row['last_joined_call'])) { + $lastJoinedCall = $this->timeFactory->getDateTime($row['last_joined_call']); + } + + return new Participant( + $this->db, + $room, + (string) $row['user_id'], + (int) $row['participant_type'], + (int) $row['last_ping'], + (string) $row['session_id'], + (int) $row['in_call'], + (int) $row['notification_level'], + (bool) $row['favorite'], + $lastMention, + $lastJoinedCall + ); } /** diff --git a/lib/Migration/Version7000Date20190717141457.php b/lib/Migration/Version7000Date20190717141457.php new file mode 100644 index 000000000..26be39bb0 --- /dev/null +++ b/lib/Migration/Version7000Date20190717141457.php @@ -0,0 +1,51 @@ + + * + * @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\Spreed\Migration; + +use Closure; +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version7000Date20190717141457 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) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('talk_participants'); + if (!$table->hasColumn('last_joined_call')) { + $table->addColumn('last_joined_call', Type::DATETIME, [ + 'notnull' => false, + ]); + } + + return $schema; + } +} diff --git a/lib/Participant.php b/lib/Participant.php index 1b94fc3d7..da7170234 100644 --- a/lib/Participant.php +++ b/lib/Participant.php @@ -65,6 +65,8 @@ class Participant { private $isFavorite; /** @var \DateTime|null */ private $lastMention; + /** @var \DateTime|null */ + private $lastJoinedCall; public function __construct(IDBConnection $db, Room $room, @@ -75,7 +77,8 @@ class Participant { int $inCall, int $notificationLevel, bool $isFavorite, - \DateTime $lastMention = null) { + \DateTime $lastMention = null, + \DateTime $lastJoinedCall = null) { $this->db = $db; $this->room = $room; $this->user = $user; @@ -86,6 +89,7 @@ class Participant { $this->notificationLevel = $notificationLevel; $this->isFavorite = $isFavorite; $this->lastMention = $lastMention; + $this->lastJoinedCall = $lastJoinedCall; } public function getUser(): string { @@ -127,6 +131,13 @@ class Participant { return $this->lastMention; } + /** + * @return \DateTime|null + */ + public function getJoinedCall(): ?\DateTime { + return $this->lastJoinedCall; + } + public function isFavorite(): bool { return $this->isFavorite; } diff --git a/lib/Room.php b/lib/Room.php index 4a0dffd61..de597bfb6 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -813,6 +813,13 @@ class Room { ->set('in_call', $query->createNamedParameter($flags, IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('session_id', $query->createNamedParameter($sessionId))) ->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); + + if ($flags !== Participant::FLAG_DISCONNECTED) { + $query->set('last_joined_call', $query->createNamedParameter( + $this->timeFactory->getDateTime(), IQueryBuilder::PARAM_DATE + )); + } + $query->execute(); if ($flags !== Participant::FLAG_DISCONNECTED) { @@ -949,18 +956,18 @@ class Room { } /** - * @param int $lastPing When the last ping is older than the given timestamp, the user is ignored + * @param null|\DateTime $maxLastJoined When the "last joined call" is older than the given DateTime, the user is ignored * @return string[] */ - public function getParticipantUserIds(int $lastPing = 0): array { + public function getParticipantUserIds(\DateTime $maxLastJoined = null): array { $query = $this->db->getQueryBuilder(); $query->select('user_id') ->from('talk_participants') ->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->nonEmptyString('user_id')); - if ($lastPing > 0) { - $query->andWhere($query->expr()->gt('last_ping', $query->createNamedParameter($lastPing, IQueryBuilder::PARAM_INT))); + if ($maxLastJoined instanceof \DateTimeInterface) { + $query->andWhere($query->expr()->gt('last_joined_call', $query->createNamedParameter($maxLastJoined, IQueryBuilder::PARAM_DATE))); } $result = $query->execute();