зеркало из https://github.com/nextcloud/spreed.git
Merge pull request #4189 from nextcloud/feature/noid/less-participant-queries
Less participant queries
This commit is contained in:
Коммит
5bd5779d35
|
@ -54,8 +54,9 @@ class ConversationProvider implements IProvider {
|
|||
|
||||
public function getResourceRichObject(IResource $resource): array {
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($resource->getId());
|
||||
$user = $this->userSession->getUser();
|
||||
$userId = $user instanceof IUser ? $user->getUID() : '';
|
||||
$room = $this->manager->getRoomByToken($resource->getId(), $userId);
|
||||
|
||||
$iconURL = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('spreed', 'app-dark.svg'));
|
||||
/**
|
||||
|
@ -68,7 +69,7 @@ class ConversationProvider implements IProvider {
|
|||
return [
|
||||
'type' => 'room',
|
||||
'id' => $resource->getId(),
|
||||
'name' => $room->getDisplayName($user instanceof IUser ? $user->getUID() : ''),
|
||||
'name' => $room->getDisplayName($userId),
|
||||
'call-type' => $this->getRoomType($room),
|
||||
'iconUrl' => $iconURL,
|
||||
'link' => $this->urlGenerator->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()])
|
||||
|
|
|
@ -185,7 +185,7 @@ class PageController extends Controller {
|
|||
if ($token !== '') {
|
||||
$room = null;
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($token);
|
||||
$room = $this->manager->getRoomByToken($token, $this->userId);
|
||||
$notification = $this->notificationManager->createNotification();
|
||||
$shouldFlush = $this->notificationManager->defer();
|
||||
try {
|
||||
|
|
|
@ -505,7 +505,7 @@ class SignalingController extends OCSController {
|
|||
$action = !empty($roomRequest['action']) ? $roomRequest['action'] : 'join';
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($roomId);
|
||||
$room = $this->manager->getRoomByToken($roomId, $userId);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
return new DataResponse([
|
||||
'type' => 'error',
|
||||
|
|
|
@ -446,14 +446,25 @@ class Manager {
|
|||
|
||||
/**
|
||||
* @param string $token
|
||||
* @param string|null $preloadParticipant Load this participants information if possible
|
||||
* @return Room
|
||||
* @throws RoomNotFoundException
|
||||
*/
|
||||
public function getRoomByToken(string $token): Room {
|
||||
public function getRoomByToken(string $token, ?string $preloadParticipant = null): Room {
|
||||
$preloadParticipant = $preloadParticipant === '' ? null : $preloadParticipant;
|
||||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('talk_rooms')
|
||||
->where($query->expr()->eq('token', $query->createNamedParameter($token)));
|
||||
$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')
|
||||
));
|
||||
}
|
||||
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
|
@ -468,7 +479,12 @@ class Manager {
|
|||
throw new RoomNotFoundException();
|
||||
}
|
||||
|
||||
return $this->createRoomObject($row);
|
||||
$room = $this->createRoomObject($row);
|
||||
if ($preloadParticipant !== null && isset($row['user_id'])) {
|
||||
$room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
|
||||
}
|
||||
|
||||
return $room;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -124,10 +124,11 @@ class Notifier implements INotifier {
|
|||
|
||||
/**
|
||||
* @param string $objectId
|
||||
* @param string $userId
|
||||
* @return Room
|
||||
* @throws RoomNotFoundException
|
||||
*/
|
||||
protected function getRoom(string $objectId): Room {
|
||||
protected function getRoom(string $objectId, string $userId): Room {
|
||||
if (array_key_exists($objectId, $this->rooms)) {
|
||||
if ($this->rooms[$objectId] === null) {
|
||||
throw new RoomNotFoundException('Room does not exist');
|
||||
|
@ -137,10 +138,16 @@ class Notifier implements INotifier {
|
|||
}
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($objectId);
|
||||
$room = $this->manager->getRoomByToken($objectId, $userId);
|
||||
$this->rooms[$objectId] = $room;
|
||||
return $room;
|
||||
} catch (RoomNotFoundException $e) {
|
||||
if (!is_numeric($objectId)) {
|
||||
// Room does not exist
|
||||
$this->rooms[$objectId] = null;
|
||||
throw $e;
|
||||
}
|
||||
|
||||
try {
|
||||
// Before 3.2.3 the id was passed in notifications
|
||||
$room = $this->manager->getRoomById((int) $objectId);
|
||||
|
@ -206,7 +213,7 @@ class Notifier implements INotifier {
|
|||
}
|
||||
|
||||
try {
|
||||
$room = $this->getRoom($notification->getObjectId());
|
||||
$room = $this->getRoom($notification->getObjectId(), $userId);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
// Room does not exist
|
||||
throw new AlreadyProcessedException();
|
||||
|
|
|
@ -64,7 +64,7 @@ class DeletedShareAPIController {
|
|||
$result = [];
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith());
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith(), $this->userId);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ class ShareAPIController {
|
|||
$result = [];
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith());
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith(), $this->userId);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
return $result;
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ class ShareAPIController {
|
|||
*/
|
||||
public function canAccessShare(IShare $share, string $user): bool {
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith());
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith(), $user);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ class RoomShareProvider implements IShareProvider {
|
|||
*/
|
||||
public function create(IShare $share): IShare {
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith());
|
||||
$room = $this->manager->getRoomByToken($share->getSharedWith(), $share->getSharedBy());
|
||||
} catch (RoomNotFoundException $e) {
|
||||
throw new GenericShareException('Room not found', $this->l->t('Conversation not found'), 404);
|
||||
}
|
||||
|
|
|
@ -1023,6 +1023,7 @@ class NotifierTest extends \Test\TestCase {
|
|||
return [
|
||||
['Incorrect app', 'invalid-app', null, null, null, null, null],
|
||||
'User can not use Talk' => [AlreadyProcessedException::class, 'spreed', true, null, null, null, null],
|
||||
'Invalid room' => [AlreadyProcessedException::class, 'spreed', false, false, null, null, null, '12345'],
|
||||
'Invalid room' => [AlreadyProcessedException::class, 'spreed', false, false, null, null, null],
|
||||
['Unknown subject', 'spreed', false, true, 'invalid-subject', null, null],
|
||||
['Unknown object type', 'spreed', false, true, 'invitation', null, 'invalid-object-type'],
|
||||
|
@ -1041,8 +1042,9 @@ class NotifierTest extends \Test\TestCase {
|
|||
* @param string|null $subject
|
||||
* @param array|null $params
|
||||
* @param string|null $objectType
|
||||
* @param string $token
|
||||
*/
|
||||
public function testPrepareThrows($message, $app, $isDisabledForUser, $validRoom, $subject, $params, $objectType) {
|
||||
public function testPrepareThrows($message, $app, $isDisabledForUser, $validRoom, $subject, $params, $objectType, $token = 'roomToken') {
|
||||
/** @var INotification|MockObject $n */
|
||||
$n = $this->createMock(INotification::class);
|
||||
$l = $this->createMock(IL10N::class);
|
||||
|
@ -1056,20 +1058,20 @@ class NotifierTest extends \Test\TestCase {
|
|||
->method('getType');
|
||||
$n->expects($this->once())
|
||||
->method('getObjectId')
|
||||
->willReturn('roomToken');
|
||||
->willReturn($token);
|
||||
$this->manager->expects($this->once())
|
||||
->method('getRoomByToken')
|
||||
->with('roomToken')
|
||||
->with($token)
|
||||
->willReturn($room);
|
||||
} elseif ($validRoom === false) {
|
||||
$n->expects($this->once())
|
||||
->method('getObjectId')
|
||||
->willReturn('roomToken');
|
||||
->willReturn($token);
|
||||
$this->manager->expects($this->once())
|
||||
->method('getRoomByToken')
|
||||
->with('roomToken')
|
||||
->with($token)
|
||||
->willThrowException(new RoomNotFoundException());
|
||||
$this->manager->expects($this->once())
|
||||
$this->manager->expects($token !== 'roomToken' ? $this->once() : $this->never())
|
||||
->method('getRoomById')
|
||||
->willThrowException(new RoomNotFoundException());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче