From e8cff4fb7556a8811226e96bb5b7c7312f428e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 22 Jul 2024 08:53:54 +0200 Subject: [PATCH] refactor: Extract generalized getter with parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- lib/Model/AttendeeMapper.php | 20 ++++++++++++++++++++ lib/Service/ParticipantService.php | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Model/AttendeeMapper.php b/lib/Model/AttendeeMapper.php index 4c09cb97f5..e7a4497084 100644 --- a/lib/Model/AttendeeMapper.php +++ b/lib/Model/AttendeeMapper.php @@ -101,6 +101,26 @@ class AttendeeMapper extends QBMapper { return $this->findEntities($query); } + /** + * @param int $roomId + * @param array $actorTypes + * @param int|null $lastJoinedCall + * @return Attendee[] + */ + public function getActorsByTypes(int $roomId, array $actorTypes, ?int $lastJoinedCall = null): array { + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->from($this->getTableName()) + ->where($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT))) + ->andWhere($query->expr()->in('actor_type', $query->createNamedParameter($actorTypes, IQueryBuilder::PARAM_STR_ARRAY))); + + if ($lastJoinedCall !== null) { + $query->andWhere($query->expr()->gte('last_joined_call', $query->createNamedParameter($lastJoinedCall, IQueryBuilder::PARAM_INT))); + } + + return $this->findEntities($query); + } + /** * @param int $roomId * @param array $participantType diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index ff6d38d167..5a2fcfb1e9 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -1619,11 +1619,18 @@ class ParticipantService { * @return string[] */ public function getParticipantUserIds(Room $room, ?\DateTime $maxLastJoined = null): array { + return $this->getParticipantActorIdsByActorType($room, [Attendee::ACTOR_USERS], $maxLastJoined); + } + + /** + * @return string[] + */ + public function getParticipantActorIdsByActorType(Room $room, array $actorTypes, ?\DateTime $maxLastJoined = null): array { $maxLastJoinedTimestamp = null; if ($maxLastJoined !== null) { $maxLastJoinedTimestamp = $maxLastJoined->getTimestamp(); } - $attendees = $this->attendeeMapper->getActorsByType($room->getId(), Attendee::ACTOR_USERS, $maxLastJoinedTimestamp); + $attendees = $this->attendeeMapper->getActorsByTypes($room->getId(), $actorTypes, $maxLastJoinedTimestamp); return array_map(static function (Attendee $attendee) { return $attendee->getActorId();