зеркало из https://github.com/nextcloud/spreed.git
Allow to preload a user when getting the room by token
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
64c66e7ba1
Коммит
9a599f12ce
|
@ -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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче