Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-02-17 18:48:15 +0300
committerJoas Schilling <coding@schilljs.com>2021-03-08 13:56:17 +0300
commit4031c182dfde9b2d70f4a1f37b39a39b763fe6aa (patch)
tree0158816d8a4e159d381db6caeed9986098777cea /lib/Room.php
parent6d9c838071eaeac4485ec3ad19b7d058d2e66368 (diff)
Prepare selecting the correct session in case there are multiple
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Room.php')
-rw-r--r--lib/Room.php69
1 files changed, 57 insertions, 12 deletions
diff --git a/lib/Room.php b/lib/Room.php
index c91c80857..d85214910 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -35,6 +35,7 @@ use OCA\Talk\Events\VerifyRoomPasswordEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\SelectHelper;
+use OCA\Talk\Model\Session;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
@@ -402,28 +403,46 @@ class Room {
/**
* @param string|null $userId
+ * @param string|null|false $sessionId Set to false if you don't want to load a session (and save resources),
+ * string to try loading a specific session
+ * null to try loading "any"
* @return Participant
* @throws ParticipantNotFoundException When the user is not a participant
*/
- public function getParticipant(?string $userId): Participant {
+ public function getParticipant(?string $userId, $sessionId = null): Participant {
if (!is_string($userId) || $userId === '') {
throw new ParticipantNotFoundException('Not a user');
}
if ($this->currentUser === $userId && $this->participant instanceof Participant) {
- return $this->participant;
+ if (!$sessionId
+ || ($this->participant->getSession() instanceof Session
+ && $this->participant->getSession()->getSessionId() === $sessionId)) {
+ return $this->participant;
+ }
}
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
- $helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
- ->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->where($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
->andWhere($query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);
+
+ if ($sessionId !== false) {
+ $helper->selectSessionsTable($query);
+ if ($sessionId !== null) {
+ $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
+ $query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
+ $query->expr()->eq('a.id', 's.attendee_id')
+ ));
+ } else {
+ $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'));
+ }
+ }
+
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
@@ -479,9 +498,7 @@ class Room {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
- $helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
- ->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->andWhere($query->expr()->eq('a.pin', $query->createNamedParameter($pin)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);
@@ -498,19 +515,33 @@ class Room {
/**
* @param int $attendeeId
+ * @param string|null|false $sessionId Set to false if you don't want to load a session (and save resources),
+ * string to try loading a specific session
+ * null to try loading "any"
* @return Participant
* @throws ParticipantNotFoundException When the pin is not valid (has no participant assigned)
*/
- public function getParticipantByAttendeeId(int $attendeeId): Participant {
+ public function getParticipantByAttendeeId(int $attendeeId, $sessionId = null): Participant {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
- $helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
- ->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->andWhere($query->expr()->eq('a.id', $query->createNamedParameter($attendeeId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);
+
+ if ($sessionId !== false) {
+ $helper->selectSessionsTable($query);
+ if ($sessionId !== null) {
+ $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
+ $query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
+ $query->expr()->eq('a.id', 's.attendee_id')
+ ));
+ } else {
+ $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'));
+ }
+ }
+
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
@@ -525,24 +556,38 @@ class Room {
/**
* @param string $actorType
* @param string $actorId
+ * @param string|null|false $sessionId Set to false if you don't want to load a session (and save resources),
+ * string to try loading a specific session
+ * null to try loading "any"
* @return Participant
* @throws ParticipantNotFoundException When the pin is not valid (has no participant assigned)
*/
- public function getParticipantByActor(string $actorType, string $actorId): Participant {
+ public function getParticipantByActor(string $actorType, string $actorId, $sessionId = null): Participant {
if ($actorType === Attendee::ACTOR_USERS) {
return $this->getParticipant($actorId);
}
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
- $helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
- ->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->andWhere($query->expr()->eq('a.actor_type', $query->createNamedParameter($actorType)))
->andWhere($query->expr()->eq('a.actor_id', $query->createNamedParameter($actorId)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);
+
+ if ($sessionId !== false) {
+ $helper->selectSessionsTable($query);
+ if ($sessionId !== null) {
+ $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
+ $query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
+ $query->expr()->eq('a.id', 's.attendee_id')
+ ));
+ } else {
+ $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'));
+ }
+ }
+
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();