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 <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-07-17 16:45:57 +02:00
Родитель 9702156de8
Коммит a0d5a835a9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
6 изменённых файлов: 114 добавлений и 9 удалений

Просмотреть файл

@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
]]></description>
<version>7.0.0-dev.0</version>
<version>7.0.0-dev.1</version>
<licence>agpl</licence>
<author>Daniel Calviño Sánchez</author>

Просмотреть файл

@ -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

Просмотреть файл

@ -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
);
}
/**

Просмотреть файл

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Joas Schilling <coding@schilljs.com>
*
* @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\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;
}
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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();