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:
-rw-r--r--lib/Command/ActiveCalls.php3
-rw-r--r--lib/Controller/RoomController.php2
-rw-r--r--lib/Manager.php172
-rw-r--r--tests/integration/spreedcheats/lib/Controller/ApiController.php5
4 files changed, 83 insertions, 99 deletions
diff --git a/lib/Command/ActiveCalls.php b/lib/Command/ActiveCalls.php
index f79e3c876..49282d167 100644
--- a/lib/Command/ActiveCalls.php
+++ b/lib/Command/ActiveCalls.php
@@ -68,9 +68,8 @@ class ActiveCalls extends Base {
$query = $this->connection->getQueryBuilder();
$query->select($query->func()->count('*', 'num_participants'))
- ->from('talk_participants')
+ ->from('talk_sessions')
->where($query->expr()->gt('in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED)))
- ->andWhere($query->expr()->neq('session_id', $query->createNamedParameter('0')))
->andWhere($query->expr()->gt('last_ping', $query->createNamedParameter(time() - 60)));
$result = $query->execute();
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 16dd8a53b..54e1edda6 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -180,7 +180,7 @@ class RoomController extends AEnvironmentAwareController {
}
}
- $rooms = $this->manager->getRoomsForParticipant($this->userId, true);
+ $rooms = $this->manager->getRoomsForUser($this->userId, true);
$return = [];
foreach ($rooms as $room) {
diff --git a/lib/Manager.php b/lib/Manager.php
index 1df220f7d..091c70368 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -182,11 +182,11 @@ class Manager {
$this->db,
$this->config,
$room,
- (string) $row['user_id'],
+ (string) $row['actor_id'],
(int) $row['participant_type'],
- (int) $row['last_ping'],
- (string) $row['session_id'],
- (int) $row['in_call'],
+ 0, // FIXME this is in talk_sessions now (int) $row['last_ping'],
+ '0', // FIXME this is in talk_sessions now (string) $row['session_id'],
+ Participant::FLAG_DISCONNECTED, // FIXME this is in talk_sessions now (int) $row['in_call'],
(int) $row['notification_level'],
(bool) $row['favorite'],
(int) $row['last_read_message'],
@@ -242,8 +242,8 @@ class Manager {
/**
* @param string $searchToken
- * @param int $limit
- * @param int $offset
+ * @param int|null $limit
+ * @param int|null $offset
* @return Room[]
*/
public function searchRoomsByToken(string $searchToken = '', int $limit = null, int $offset = null): array {
@@ -283,14 +283,23 @@ class Manager {
* @return Room[]
*/
public function getRoomsForParticipant(string $participant, bool $includeLastMessage = false): array {
+ return [];
+ }
+
+ /**
+ * @param string $userId
+ * @param bool $includeLastMessage
+ * @return Room[]
+ */
+ public function getRoomsForUser(string $userId, bool $includeLastMessage = false): array {
$query = $this->db->getQueryBuilder();
- $query->select('r.*')->addSelect('p.*')
+ $query->select('r.*')->addSelect('a.*')
->from('talk_rooms', 'r')
- ->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
- $query->expr()->eq('p.user_id', $query->createNamedParameter($participant)),
- $query->expr()->eq('p.room_id', 'r.id')
- ))
- ->where($query->expr()->isNotNull('p.user_id'));
+ ->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
+ $query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)),
+ $query->expr()->eq('a.actor_type', $query->createNamedParameter('users')),
+ $query->expr()->eq('a.room_id', 'r.id')
+ ));
if ($includeLastMessage) {
$this->loadLastMessageInfo($query);
@@ -305,8 +314,8 @@ class Manager {
}
$room = $this->createRoomObject($row);
- if ($participant !== null && isset($row['user_id'])) {
- $room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
+ if ($userId !== null && isset($row['actor_id'])) {
+ $room->setParticipant($row['actor_id'], $this->createParticipantObject($room, $row));
}
$rooms[] = $room;
}
@@ -324,18 +333,30 @@ class Manager {
* @throws RoomNotFoundException
*/
public function getRoomForParticipant(int $roomId, ?string $participant): Room {
+ throw new RoomNotFoundException();
+ }
+
+ /**
+ * Does *not* return public rooms for participants that have not been invited
+ *
+ * @param int $roomId
+ * @param string|null $userId
+ * @return Room
+ * @throws RoomNotFoundException
+ */
+ public function getRoomForUser(int $roomId, ?string $userId): Room {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('talk_rooms', 'r')
->where($query->expr()->eq('r.id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
- if ($participant !== null) {
+ if ($userId !== null) {
// Non guest user
- $query->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
- $query->expr()->eq('p.user_id', $query->createNamedParameter($participant)),
- $query->expr()->eq('p.room_id', 'r.id')
- ))
- ->andWhere($query->expr()->isNotNull('p.user_id'));
+ $query->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
+ $query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)),
+ $query->expr()->eq('a.actor_type', $query->createNamedParameter('users')),
+ $query->expr()->eq('a.room_id', 'r.id')
+ ));
}
$result = $query->execute();
@@ -352,11 +373,11 @@ class Manager {
}
$room = $this->createRoomObject($row);
- if ($participant !== null && isset($row['user_id'])) {
- $room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
+ if ($userId !== null && isset($row['actor_id'])) {
+ $room->setParticipant($row['actor_id'], $this->createParticipantObject($room, $row));
}
- if ($participant === null && $room->getType() !== Room::PUBLIC_CALL) {
+ if ($userId === null && $room->getType() !== Room::PUBLIC_CALL) {
throw new RoomNotFoundException();
}
@@ -374,18 +395,33 @@ class Manager {
* @throws RoomNotFoundException
*/
public function getRoomForParticipantByToken(string $token, ?string $participant, bool $includeLastMessage = false): Room {
+ throw new RoomNotFoundException();
+ }
+
+ /**
+ * Also returns public rooms for participants that have not been invited,
+ * so they can join.
+ *
+ * @param string $token
+ * @param string|null $userId
+ * @param bool $includeLastMessage
+ * @return Room
+ * @throws RoomNotFoundException
+ */
+ public function getRoomForUserByToken(string $token, ?string $userId, bool $includeLastMessage = false): Room {
$query = $this->db->getQueryBuilder();
$query->select('r.*')
->from('talk_rooms', 'r')
->where($query->expr()->eq('r.token', $query->createNamedParameter($token)))
->setMaxResults(1);
- if ($participant !== null) {
+ if ($userId !== null) {
// Non guest user
$query->addSelect('p.*')
- ->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
- $query->expr()->eq('p.user_id', $query->createNamedParameter($participant)),
- $query->expr()->eq('p.room_id', 'r.id')
+ ->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
+ $query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)),
+ $query->expr()->eq('a.actor_type', $query->createNamedParameter('users')),
+ $query->expr()->eq('a.room_id', 'r.id')
));
}
@@ -407,15 +443,15 @@ class Manager {
}
$room = $this->createRoomObject($row);
- if ($participant !== null && isset($row['user_id'])) {
- $room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
+ if ($userId !== null && isset($row['actor_id'])) {
+ $room->setParticipant($row['actor_id'], $this->createParticipantObject($room, $row));
}
if ($room->getType() === Room::PUBLIC_CALL) {
return $room;
}
- if ($participant !== null && $row['user_id'] === $participant) {
+ if ($userId !== null && $row['actor_id'] === $userId) {
return $room;
}
@@ -451,23 +487,24 @@ class Manager {
/**
* @param string $token
- * @param string|null $preloadParticipant Load this participants information if possible
+ * @param string|null $preloadUserId Load this participants information if possible
* @return Room
* @throws RoomNotFoundException
*/
- public function getRoomByToken(string $token, ?string $preloadParticipant = null): Room {
- $preloadParticipant = $preloadParticipant === '' ? null : $preloadParticipant;
+ public function getRoomByToken(string $token, ?string $preloadUserId = null): Room {
+ $preloadUserId = $preloadUserId === '' ? null : $preloadUserId;
$query = $this->db->getQueryBuilder();
$query->select('r.*')
->from('talk_rooms', 'r')
->where($query->expr()->eq('r.token', $query->createNamedParameter($token)));
- if ($preloadParticipant !== null) {
- $query->addSelect('p.*')
- ->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
- $query->expr()->eq('p.user_id', $query->createNamedParameter($preloadParticipant)),
- $query->expr()->eq('p.room_id', 'r.id')
+ if ($preloadUserId !== null) {
+ $query->addSelect('a.*')
+ ->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
+ $query->expr()->eq('a.actor_id', $query->createNamedParameter($preloadUserId)),
+ $query->expr()->eq('a.actor_type', $query->createNamedParameter('users')),
+ $query->expr()->eq('a.room_id', 'r.id')
));
}
@@ -485,8 +522,8 @@ class Manager {
}
$room = $this->createRoomObject($row);
- if ($preloadParticipant !== null && isset($row['user_id'])) {
- $room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
+ if ($preloadUserId !== null && isset($row['actor_id'])) {
+ $room->setParticipant($row['actor_id'], $this->createParticipantObject($room, $row));
}
return $room;
@@ -671,61 +708,6 @@ class Manager {
return $room;
}
- /**
- * @param string|null $userId
- * @return string|null
- */
- public function getCurrentSessionId(?string $userId): ?string {
- if (empty($userId)) {
- return null;
- }
-
- $query = $this->db->getQueryBuilder();
- $query->select('*')
- ->from('talk_participants')
- ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)))
- ->andWhere($query->expr()->neq('session_id', $query->createNamedParameter('0')))
- ->orderBy('last_ping', 'DESC')
- ->setMaxResults(1);
- $result = $query->execute();
- $row = $result->fetch();
- $result->closeCursor();
-
- if ($row === false) {
- return null;
- }
-
- return $row['session_id'];
- }
-
- /**
- * @param string $userId
- * @return string[]
- */
- public function getSessionIdsForUser(?string $userId): array {
- if (!is_string($userId) || $userId === '') {
- // No deleting messages for guests
- return [];
- }
-
- // Delete all messages from or to the current user
- $query = $this->db->getQueryBuilder();
- $query->select('session_id')
- ->from('talk_participants')
- ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
- $result = $query->execute();
-
- $sessionIds = [];
- while ($row = $result->fetch()) {
- if ($row['session_id'] !== '0') {
- $sessionIds[] = $row['session_id'];
- }
- }
- $result->closeCursor();
-
- return $sessionIds;
- }
-
public function resolveRoomDisplayName(Room $room, string $userId): string {
if ($room->getObjectType() === 'share:password') {
return $this->l->t('Password request: %s', [$room->getName()]);
diff --git a/tests/integration/spreedcheats/lib/Controller/ApiController.php b/tests/integration/spreedcheats/lib/Controller/ApiController.php
index 8a14f21e7..358dbafb2 100644
--- a/tests/integration/spreedcheats/lib/Controller/ApiController.php
+++ b/tests/integration/spreedcheats/lib/Controller/ApiController.php
@@ -57,7 +57,10 @@ class ApiController extends OCSController {
$query->delete('talk_rooms')->execute();
$query = $this->db->getQueryBuilder();
- $query->delete('talk_participants')->execute();
+ $query->delete('talk_attendees')->execute();
+
+ $query = $this->db->getQueryBuilder();
+ $query->delete('talk_sessions')->execute();
$query = $this->db->getQueryBuilder();
$query->delete('share')