From 9e55a41e0880219eb993c5690198f159120ccdd5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Feb 2021 09:03:41 +0100 Subject: Count guests from attendees instead of the fixed value which bumps up on reconnects Signed-off-by: Joas Schilling --- lib/Activity/Listener.php | 5 ++--- lib/Model/AttendeeMapper.php | 24 ++++++++++++++++++++++++ lib/Room.php | 4 ++++ lib/Service/ParticipantService.php | 14 ++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index 6b39bc3de..5e62e3c0c 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -120,15 +120,14 @@ class Listener { $duration = $this->timeFactory->getTime() - $activeSince->getTimestamp(); $userIds = $this->participantService->getParticipantUserIds($room, $activeSince); + $numGuests = $this->participantService->getGuestCount($room, $activeSince); - if ((\count($userIds) + $room->getActiveGuests()) === 1) { + if ((\count($userIds) + $numGuests) === 1) { // Single user pinged or guests only => no summary/activity $room->resetActiveSince(); return false; } - $numGuests = $room->getActiveGuests(); - if (!$room->resetActiveSince()) { // Race-condition, the room was already reset. return false; diff --git a/lib/Model/AttendeeMapper.php b/lib/Model/AttendeeMapper.php index 13d7d6d07..8bce0422f 100644 --- a/lib/Model/AttendeeMapper.php +++ b/lib/Model/AttendeeMapper.php @@ -77,6 +77,30 @@ class AttendeeMapper extends QBMapper { return $this->findEntities($query); } + /** + * @param int $roomId + * @param string $actorType + * @param int|null $lastJoinedCall + * @return int + */ + public function getActorsCountByType(int $roomId, string $actorType, ?int $lastJoinedCall = null): int { + $query = $this->db->getQueryBuilder(); + $query->select($query->func()->count('*', 'num_actors')) + ->from($this->getTableName()) + ->where($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT))) + ->andWhere($query->expr()->eq('actor_type', $query->createNamedParameter($actorType))); + + if ($lastJoinedCall !== null) { + $query->andWhere($query->expr()->gte('last_joined_call', $query->createNamedParameter($lastJoinedCall, IQueryBuilder::PARAM_INT))); + } + + $result = $query->execute(); + $count = (int) $result->fetchOne(); + $result->closeCursor(); + + return $count; + } + /** * @param int $roomId * @param int[] $participantType diff --git a/lib/Room.php b/lib/Room.php index 312d8189e..bd94fc59f 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -318,6 +318,10 @@ class Room { return $this->description; } + /** + * @deprecated Use ParticipantService::getGuestCount() instead + * @return int + */ public function getActiveGuests(): int { return $this->activeGuests; } diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 6e1d99588..6c515f9e2 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -704,6 +704,20 @@ class ParticipantService { }, $attendees); } + /** + * @param Room $room + * @param \DateTime|null $maxLastJoined + * @return int + */ + public function getGuestCount(Room $room, \DateTime $maxLastJoined = null): int { + $maxLastJoinedTimestamp = null; + if ($maxLastJoined !== null) { + $maxLastJoinedTimestamp = $maxLastJoined->getTimestamp(); + } + + return $this->attendeeMapper->getActorsCountByType($room->getId(), Attendee::ACTOR_GUESTS, $maxLastJoinedTimestamp); + } + /** * @param Room $room * @return string[] -- cgit v1.2.3