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:
authorVitor Mattos <vitor@php.rio>2022-10-07 15:21:55 +0300
committerGitHub <noreply@github.com>2022-10-07 15:21:55 +0300
commitb6f3890821fd12718c0bc2892b6249e6eaa82a42 (patch)
treecb353b223514d8b426f430d1b451430f38e924bc
parent03961228f64b5e6d0cee9c79135654bac3c5ada9 (diff)
parentc897dcc5cd9392ae79a95389fa1a1fcd0af47047 (diff)
Merge pull request #8106 from nextcloud/bugfix/6235/finish-room-model-clearing
Move getParticipant()
-rw-r--r--lib/Chat/Notifier.php4
-rw-r--r--lib/Collaboration/Collaborators/Listener.php2
-rw-r--r--lib/Collaboration/Collaborators/RoomPlugin.php11
-rw-r--r--lib/Collaboration/Reference/TalkReferenceProvider.php6
-rw-r--r--lib/Collaboration/Resources/ConversationProvider.php6
-rw-r--r--lib/Command/Room/TRoomCommand.php10
-rw-r--r--lib/Controller/PageController.php6
-rw-r--r--lib/Controller/RoomController.php16
-rw-r--r--lib/Controller/SignalingController.php4
-rw-r--r--lib/Dashboard/TalkWidget.php18
-rw-r--r--lib/Files/Listener.php2
-rw-r--r--lib/Flow/Operation.php25
-rw-r--r--lib/Listener/BeforeUserLoggedOutListener.php2
-rw-r--r--lib/Listener/GroupMembershipListener.php2
-rw-r--r--lib/Manager.php4
-rw-r--r--lib/MatterbridgeManager.php2
-rw-r--r--lib/Middleware/InjectionMiddleware.php4
-rw-r--r--lib/Notification/Notifier.php2
-rw-r--r--lib/PublicShareAuth/Listener.php4
-rw-r--r--lib/Room.php1
-rw-r--r--lib/Search/CurrentMessageSearch.php2
-rw-r--r--lib/Search/MessageSearch.php8
-rw-r--r--lib/Service/ParticipantService.php71
-rw-r--r--lib/Share/Helper/ShareAPIController.php16
-rw-r--r--lib/Share/RoomShareProvider.php2
-rw-r--r--tests/php/Chat/NotifierTest.php4
-rw-r--r--tests/php/Collaboration/Collaborators/RoomPluginTest.php105
-rw-r--r--tests/php/Collaboration/Reference/TalkReferenceProviderTest.php5
-rw-r--r--tests/php/Collaboration/Resources/ConversationProviderTest.php17
-rw-r--r--tests/php/Controller/SignalingControllerTest.php26
-rw-r--r--tests/php/Notification/NotifierTest.php8
-rw-r--r--tests/php/Signaling/BackendNotifierTest.php2
32 files changed, 254 insertions, 143 deletions
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index 56f668252..9a9c4e2ed 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -283,7 +283,7 @@ class Notifier {
return;
}
- $participant = $chat->getParticipant($comment->getActorId(), false);
+ $participant = $this->participantService->getParticipant($chat, $comment->getActorId(), false);
$notificationLevel = $participant->getAttendee()->getNotificationLevel();
if ($notificationLevel === Participant::NOTIFY_DEFAULT) {
if ($chat->getType() === Room::TYPE_ONE_TO_ONE) {
@@ -449,7 +449,7 @@ class Notifier {
return false;
}
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
$attendee = $participant->getAttendee();
} else {
$participant = new Participant($room, $attendee, null);
diff --git a/lib/Collaboration/Collaborators/Listener.php b/lib/Collaboration/Collaborators/Listener.php
index af065dae4..2f9603942 100644
--- a/lib/Collaboration/Collaborators/Listener.php
+++ b/lib/Collaboration/Collaborators/Listener.php
@@ -153,7 +153,7 @@ class Listener {
$userId = $result['value']['shareWith'];
try {
- $participant = $this->room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($this->room, $userId, false);
if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
// do list self-joined users so they can be added as permanent participants by moderators
return true;
diff --git a/lib/Collaboration/Collaborators/RoomPlugin.php b/lib/Collaboration/Collaborators/RoomPlugin.php
index cc03429fe..1e92332a3 100644
--- a/lib/Collaboration/Collaborators/RoomPlugin.php
+++ b/lib/Collaboration/Collaborators/RoomPlugin.php
@@ -28,6 +28,7 @@ use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
@@ -35,13 +36,15 @@ use OCP\IUserSession;
use OCP\Share\IShare;
class RoomPlugin implements ISearchPlugin {
- private Manager $manager;
-
- private IUserSession $userSession;
+ protected Manager $manager;
+ protected ParticipantService $participantService;
+ protected IUserSession $userSession;
public function __construct(Manager $manager,
+ ParticipantService $participantService,
IUserSession $userSession) {
$this->manager = $manager;
+ $this->participantService = $participantService;
$this->userSession = $userSession;
}
@@ -64,7 +67,7 @@ class RoomPlugin implements ISearchPlugin {
continue;
}
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
if (!$participant instanceof Participant || !($participant->getPermissions() & Attendee::PERMISSIONS_CHAT)) {
// No chat permissions is like read-only
continue;
diff --git a/lib/Collaboration/Reference/TalkReferenceProvider.php b/lib/Collaboration/Reference/TalkReferenceProvider.php
index f3b0b1ba2..88d448f74 100644
--- a/lib/Collaboration/Reference/TalkReferenceProvider.php
+++ b/lib/Collaboration/Reference/TalkReferenceProvider.php
@@ -33,6 +33,7 @@ use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\Reference;
@@ -45,6 +46,7 @@ use OCP\IURLGenerator;
class TalkReferenceProvider implements IReferenceProvider {
protected IURLGenerator $urlGenerator;
protected Manager $roomManager;
+ protected ParticipantService $participantService;
protected ChatManager $chatManager;
protected MessageParser $messageParser;
protected IL10N $l;
@@ -52,12 +54,14 @@ class TalkReferenceProvider implements IReferenceProvider {
public function __construct(IURLGenerator $urlGenerator,
Manager $manager,
+ ParticipantService $participantService,
ChatManager $chatManager,
MessageParser $messageParser,
IL10N $l,
?string $userId) {
$this->urlGenerator = $urlGenerator;
$this->roomManager = $manager;
+ $this->participantService = $participantService;
$this->chatManager = $chatManager;
$this->messageParser = $messageParser;
$this->l = $l;
@@ -152,7 +156,7 @@ class TalkReferenceProvider implements IReferenceProvider {
$room = $this->roomManager->getRoomForUserByToken($referenceMatch['token'], $this->userId);
try {
- $participant = $room->getParticipant($this->userId);
+ $participant = $this->participantService->getParticipant($room, $this->userId);
} catch (ParticipantNotFoundException $e) {
$participant = null;
}
diff --git a/lib/Collaboration/Resources/ConversationProvider.php b/lib/Collaboration/Resources/ConversationProvider.php
index 591157287..1b9e2b40b 100644
--- a/lib/Collaboration/Resources/ConversationProvider.php
+++ b/lib/Collaboration/Resources/ConversationProvider.php
@@ -28,6 +28,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Resources\IProvider;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
@@ -37,13 +38,16 @@ use OCP\IUserSession;
class ConversationProvider implements IProvider {
protected Manager $manager;
+ protected ParticipantService $participantService;
protected IUserSession $userSession;
protected IURLGenerator $urlGenerator;
public function __construct(Manager $manager,
+ ParticipantService $participantService,
IUserSession $userSession,
IURLGenerator $urlGenerator) {
$this->manager = $manager;
+ $this->participantService = $participantService;
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
}
@@ -89,7 +93,7 @@ class ConversationProvider implements IProvider {
// Logged in users need to have a regular participant,
// before they can do anything with the room.
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
return $participant->getAttendee()->getParticipantType() !== Participant::USER_SELF_JOINED;
} catch (RoomNotFoundException $e) {
throw new ResourceException('Conversation not found');
diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php
index 15991b832..7a34b5db2 100644
--- a/lib/Command/Room/TRoomCommand.php
+++ b/lib/Command/Room/TRoomCommand.php
@@ -201,7 +201,7 @@ trait TRoomCommand {
*/
protected function setRoomOwner(Room $room, string $userId): void {
try {
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
}
@@ -278,7 +278,7 @@ trait TRoomCommand {
}
try {
- $room->getParticipant($user->getUID(), false);
+ $this->participantService->getParticipant($room, $user->getUID(), false);
// nothing to do, user is a participant already
continue;
@@ -306,7 +306,7 @@ trait TRoomCommand {
$users = [];
foreach ($userIds as $userId) {
try {
- $room->getParticipant($userId, false);
+ $this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
}
@@ -333,7 +333,7 @@ trait TRoomCommand {
}
try {
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
}
@@ -358,7 +358,7 @@ trait TRoomCommand {
$participants = [];
foreach ($userIds as $userId) {
try {
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
}
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 4814952e4..6585efcba 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -32,6 +32,7 @@ use OCA\Talk\Config;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\RoomService;
use OCA\Talk\TalkSession;
use OCA\Talk\TInitialState;
@@ -70,6 +71,7 @@ class PageController extends Controller {
private IUserSession $userSession;
private LoggerInterface $logger;
private Manager $manager;
+ private ParticipantService $participantService;
private RoomService $roomService;
private IURLGenerator $url;
private INotificationManager $notificationManager;
@@ -86,6 +88,7 @@ class PageController extends Controller {
?string $UserId,
LoggerInterface $logger,
Manager $manager,
+ ParticipantService $participantService,
RoomService $roomService,
IURLGenerator $url,
INotificationManager $notificationManager,
@@ -104,6 +107,7 @@ class PageController extends Controller {
$this->userId = $UserId;
$this->logger = $logger;
$this->manager = $manager;
+ $this->participantService = $participantService;
$this->roomService = $roomService;
$this->url = $url;
$this->notificationManager = $notificationManager;
@@ -220,7 +224,7 @@ class PageController extends Controller {
if ($room instanceof Room && $room->hasPassword()) {
// If the user joined themselves or is not found, they need the password.
try {
- $participant = $room->getParticipant($this->userId, false);
+ $participant = $this->participantService->getParticipant($room, $this->userId, false);
$requirePassword = $participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED;
} catch (ParticipantNotFoundException $e) {
$requirePassword = true;
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 2fb836562..6a1f4d234 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -226,7 +226,7 @@ class RoomController extends AEnvironmentAwareController {
$return = [];
foreach ($rooms as $room) {
try {
- $return[] = $this->formatRoom($room, $room->getParticipant($this->userId), $statuses);
+ $return[] = $this->formatRoom($room, $this->participantService->getParticipant($room, $this->userId), $statuses);
} catch (RoomNotFoundException $e) {
} catch (ParticipantNotFoundException $e) {
// for example in case the room was deleted concurrently,
@@ -289,7 +289,7 @@ class RoomController extends AEnvironmentAwareController {
$participant = null;
try {
- $participant = $room->getParticipant($this->userId, $sessionId);
+ $participant = $this->participantService->getParticipant($room, $this->userId, $sessionId);
} catch (ParticipantNotFoundException $e) {
try {
$participant = $this->participantService->getParticipantBySession($room, $sessionId);
@@ -695,7 +695,7 @@ class RoomController extends AEnvironmentAwareController {
$room = $this->manager->getOne2OneRoom($currentUser->getUID(), $targetUser->getUID());
$this->participantService->ensureOneToOneRoomIsFilled($room);
return new DataResponse(
- $this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)),
+ $this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)),
Http::STATUS_OK
);
} catch (RoomNotFoundException $e) {
@@ -704,7 +704,7 @@ class RoomController extends AEnvironmentAwareController {
try {
$room = $this->roomService->createOneToOneConversation($currentUser, $targetUser);
return new DataResponse(
- $this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)),
+ $this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)),
Http::STATUS_CREATED
);
} catch (InvalidArgumentException $e) {
@@ -739,7 +739,7 @@ class RoomController extends AEnvironmentAwareController {
$room = $this->roomService->createConversation(Room::TYPE_GROUP, $name, $currentUser);
$this->participantService->addGroup($room, $targetGroup);
- return new DataResponse($this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)), Http::STATUS_CREATED);
+ return new DataResponse($this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)), Http::STATUS_CREATED);
}
/**
@@ -771,7 +771,7 @@ class RoomController extends AEnvironmentAwareController {
$room = $this->roomService->createConversation(Room::TYPE_GROUP, $name, $currentUser);
$this->participantService->addCircle($room, $circle);
- return new DataResponse($this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)), Http::STATUS_CREATED);
+ return new DataResponse($this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)), Http::STATUS_CREATED);
}
/**
@@ -796,7 +796,7 @@ class RoomController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
- return new DataResponse($this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)), Http::STATUS_CREATED);
+ return new DataResponse($this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)), Http::STATUS_CREATED);
}
/**
@@ -1364,7 +1364,7 @@ class RoomController extends AEnvironmentAwareController {
$previousSession = null;
if ($this->userId !== null) {
try {
- $previousParticipant = $room->getParticipant($this->userId, $sessionId);
+ $previousParticipant = $this->participantService->getParticipant($room, $this->userId, $sessionId);
$previousSession = $previousParticipant->getSession();
} catch (ParticipantNotFoundException $e) {
}
diff --git a/lib/Controller/SignalingController.php b/lib/Controller/SignalingController.php
index cce455963..54cdedca4 100644
--- a/lib/Controller/SignalingController.php
+++ b/lib/Controller/SignalingController.php
@@ -373,7 +373,7 @@ class SignalingController extends OCSController {
if ($this->userId) {
// For logged in users we check if they are still part of the public conversation,
// if not they were removed instead of having a conflict.
- $room->getParticipant($this->userId, false);
+ $this->participantService->getParticipant($room, $this->userId, false);
}
// Session was killed, make the UI redirect to an error
@@ -642,7 +642,7 @@ class SignalingController extends OCSController {
} elseif (!empty($userId)) {
// User trying to join room.
try {
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
}
}
diff --git a/lib/Dashboard/TalkWidget.php b/lib/Dashboard/TalkWidget.php
index 3516f7cc3..df8074845 100644
--- a/lib/Dashboard/TalkWidget.php
+++ b/lib/Dashboard/TalkWidget.php
@@ -28,6 +28,7 @@ namespace OCA\Talk\Dashboard;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Manager;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Comments\IComment;
use OCP\Dashboard\IAPIWidget;
use OCP\Dashboard\IButtonWidget;
@@ -41,20 +42,23 @@ use OCP\IURLGenerator;
use OCP\Util;
class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidget {
- private IURLGenerator $url;
- private IL10N $l10n;
- private Manager $manager;
- private MessageParser $messageParser;
+ protected IURLGenerator $url;
+ protected IL10N $l10n;
+ protected Manager $manager;
+ protected ParticipantService $participantService;
+ protected MessageParser $messageParser;
public function __construct(
IURLGenerator $url,
IL10N $l10n,
Manager $manager,
+ ParticipantService $participantService,
MessageParser $messageParser
) {
$this->url = $url;
$this->l10n = $l10n;
$this->manager = $manager;
+ $this->participantService = $participantService;
$this->messageParser = $messageParser;
}
@@ -128,8 +132,8 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
$rooms = $this->manager->getRoomsForUser($userId, [], true);
- $rooms = array_filter($rooms, static function (Room $room) use ($userId) {
- $participant = $room->getParticipant($userId);
+ $rooms = array_filter($rooms, function (Room $room) use ($userId) {
+ $participant = $this->participantService->getParticipant($room, $userId);
$attendee = $participant->getAttendee();
return $room->getLastMessage() && $room->getLastMessage()->getId() > $attendee->getLastReadMessage();
});
@@ -147,7 +151,7 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
}
protected function prepareRoom(Room $room, string $userId): WidgetItem {
- $participant = $room->getParticipant($userId);
+ $participant = $this->participantService->getParticipant($room, $userId);
$subtitle = '';
$lastMessage = $room->getLastMessage();
diff --git a/lib/Files/Listener.php b/lib/Files/Listener.php
index 574b1a029..d42a06a6f 100644
--- a/lib/Files/Listener.php
+++ b/lib/Files/Listener.php
@@ -148,7 +148,7 @@ class Listener {
}
try {
- $room->getParticipant($userId, false);
+ $this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
$user = $this->userManager->get($userId);
diff --git a/lib/Flow/Operation.php b/lib/Flow/Operation.php
index 0555e78e8..e73a33fe3 100644
--- a/lib/Flow/Operation.php
+++ b/lib/Flow/Operation.php
@@ -32,6 +32,7 @@ use OCA\Talk\Manager as TalkManager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\EventDispatcher\Event;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -53,22 +54,25 @@ class Operation implements IOperation {
'ROOM_MENTION' => 3,
];
- private IL10N $l;
- private IURLGenerator $urlGenerator;
- private TalkManager $talkManager;
- private IUserSession $session;
- private ChatManager $chatManager;
+ protected IL10N $l;
+ protected IURLGenerator $urlGenerator;
+ protected TalkManager $talkManager;
+ protected ParticipantService $participantService;
+ protected IUserSession $session;
+ protected ChatManager $chatManager;
public function __construct(
IL10N $l,
IURLGenerator $urlGenerator,
TalkManager $talkManager,
+ ParticipantService $participantService,
IUserSession $session,
ChatManager $chatManager
) {
$this->l = $l;
$this->urlGenerator = $urlGenerator;
$this->talkManager = $talkManager;
+ $this->participantService = $participantService;
$this->session = $session;
$this->chatManager = $chatManager;
}
@@ -122,7 +126,7 @@ class Operation implements IOperation {
continue;
}
- $participant = $this->getParticipant($uid, $room);
+ $participant = $this->participantService->getParticipant($room, $uid, false);
if (!($participant->getPermissions() & Attendee::PERMISSIONS_CHAT)) {
// Ignore conversation because the user has no permissions
continue;
@@ -214,7 +218,7 @@ class Operation implements IOperation {
if ($mode === self::MESSAGE_MODES['ROOM_MENTION']) {
try {
- $participant = $this->getParticipant($uid, $room);
+ $participant = $this->participantService->getParticipant($room, $uid, false);
if (!$participant->hasModeratorPermissions(false)) {
throw new UnexpectedValueException('Not allowed to mention room');
}
@@ -241,11 +245,4 @@ class Operation implements IOperation {
protected function getRoom(string $token, string $uid): Room {
return $this->talkManager->getRoomForUserByToken($token, $uid);
}
-
- /**
- * @throws ParticipantNotFoundException
- */
- protected function getParticipant(string $uid, Room $room): Participant {
- return $room->getParticipant($uid, false);
- }
}
diff --git a/lib/Listener/BeforeUserLoggedOutListener.php b/lib/Listener/BeforeUserLoggedOutListener.php
index 4d145b77f..14c382032 100644
--- a/lib/Listener/BeforeUserLoggedOutListener.php
+++ b/lib/Listener/BeforeUserLoggedOutListener.php
@@ -63,7 +63,7 @@ class BeforeUserLoggedOutListener implements IEventListener {
foreach ($sessionIds as $sessionId) {
try {
$room = $this->manager->getRoomForSession($user->getUID(), $sessionId);
- $participant = $room->getParticipant($user->getUID(), $sessionId);
+ $participant = $this->participantService->getParticipant($room, $user->getUID(), $sessionId);
if ($participant->getSession() && $participant->getSession()->getInCall() !== Participant::FLAG_DISCONNECTED) {
$this->participantService->changeInCall($room, $participant, Participant::FLAG_DISCONNECTED);
}
diff --git a/lib/Listener/GroupMembershipListener.php b/lib/Listener/GroupMembershipListener.php
index 85f426f63..9a398a2c5 100644
--- a/lib/Listener/GroupMembershipListener.php
+++ b/lib/Listener/GroupMembershipListener.php
@@ -47,7 +47,7 @@ class GroupMembershipListener extends AMembershipListener {
foreach ($rooms as $room) {
try {
- $participant = $room->getParticipant($user->getUID());
+ $participant = $this->participantService->getParticipant($room, $user->getUID());
if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
$this->participantService->updateParticipantType($room, $participant, Participant::USER);
}
diff --git a/lib/Manager.php b/lib/Manager.php
index a574aaf00..3b8814ec4 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -889,7 +889,7 @@ class Manager {
$room = $this->createRoomObject($row);
try {
- $room->getParticipant($userId, false);
+ $this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
$user = $this->userManager->get($userId);
$this->participantService->addUsers($room, [[
@@ -1019,7 +1019,7 @@ class Manager {
$sessionId = $this->talkSession->getSessionForRoom($room->getToken());
$this->participantService->getParticipantBySession($room, $sessionId);
} else {
- $room->getParticipant($userId, false);
+ $this->participantService->getParticipant($room, $userId, false);
}
} catch (ParticipantNotFoundException $e) {
// Do not leak the name of rooms the user is not a part of
diff --git a/lib/MatterbridgeManager.php b/lib/MatterbridgeManager.php
index ba57e4a45..53c68d385 100644
--- a/lib/MatterbridgeManager.php
+++ b/lib/MatterbridgeManager.php
@@ -293,7 +293,7 @@ class MatterbridgeManager {
// check if the bot user is member of the room and add or remove it
try {
- $room->getParticipant(self::BRIDGE_BOT_USERID, false);
+ $this->participantService->getParticipant($room, self::BRIDGE_BOT_USERID, false);
if (!$isBridgeEnabled) {
$this->participantService->removeUser($room, $botUser, Room::PARTICIPANT_REMOVED);
}
diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php
index 717c643d5..fc8e4bcad 100644
--- a/lib/Middleware/InjectionMiddleware.php
+++ b/lib/Middleware/InjectionMiddleware.php
@@ -144,7 +144,7 @@ class InjectionMiddleware extends Middleware {
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId);
$controller->setRoom($room);
- $participant = $room->getParticipant($this->userId, $sessionId);
+ $participant = $this->participantService->getParticipant($room, $this->userId, $sessionId);
$controller->setParticipant($participant);
if ($moderatorRequired && !$participant->hasModeratorPermissions(false)) {
@@ -180,7 +180,7 @@ class InjectionMiddleware extends Middleware {
}
if ($participant === null) {
- $participant = $room->getParticipant($this->userId);
+ $participant = $this->participantService->getParticipant($room, $this->userId);
}
$controller->setParticipant($participant);
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index dca997eb4..e22a8cfc3 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -180,7 +180,7 @@ class Notifier implements INotifier {
}
try {
- $participant = $room->getParticipant($userId, false);
+ $participant = $this->participantService->getParticipant($room, $userId, false);
$this->participants[$roomId][$userId] = $participant;
return $participant;
} catch (ParticipantNotFoundException $e) {
diff --git a/lib/PublicShareAuth/Listener.php b/lib/PublicShareAuth/Listener.php
index d955f22ce..93b43a512 100644
--- a/lib/PublicShareAuth/Listener.php
+++ b/lib/PublicShareAuth/Listener.php
@@ -91,15 +91,15 @@ class Listener {
return;
}
+ $participantService = Server::get(ParticipantService::class);
try {
- $participant = $room->getParticipant($userId, false);
+ $participant = $participantService->getParticipant($room, $userId, false);
if ($participant->getAttendee()->getParticipantType() === Participant::OWNER) {
return;
}
} catch (ParticipantNotFoundException $e) {
}
- $participantService = Server::get(ParticipantService::class);
if ($participantService->getNumberOfActors($room) > 1) {
throw new RoomNotFoundException('Only the owner and another participant are allowed in rooms to request the password for a share');
}
diff --git a/lib/Room.php b/lib/Room.php
index 2d7ea3281..3042ebe9f 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -535,6 +535,7 @@ class Room {
* null to try loading "any"
* @return Participant
* @throws ParticipantNotFoundException When the user is not a participant
+ * @deprecated
*/
public function getParticipant(?string $userId, $sessionId = null): Participant {
if (!is_string($userId) || $userId === '') {
diff --git a/lib/Search/CurrentMessageSearch.php b/lib/Search/CurrentMessageSearch.php
index 126099aa5..d15c1a9e5 100644
--- a/lib/Search/CurrentMessageSearch.php
+++ b/lib/Search/CurrentMessageSearch.php
@@ -90,7 +90,7 @@ class CurrentMessageSearch extends MessageSearch {
}
try {
- $participant = $room->getParticipant($user->getUID(), false);
+ $participant = $this->participantService->getParticipant($room, $user->getUID(), false);
} catch (ParticipantNotFoundException $e) {
return SearchResult::complete(
$this->l->t('Messages'),
diff --git a/lib/Search/MessageSearch.php b/lib/Search/MessageSearch.php
index 6ac0dfc3f..e10bfc49d 100644
--- a/lib/Search/MessageSearch.php
+++ b/lib/Search/MessageSearch.php
@@ -31,6 +31,7 @@ use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Manager as RoomManager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Webinary;
use OCP\Comments\IComment;
use OCP\IL10N;
@@ -43,6 +44,7 @@ use OCP\Search\SearchResultEntry;
class MessageSearch implements IProvider {
protected RoomManager $roomManager;
+ protected ParticipantService $participantService;
protected ChatManager $chatManager;
protected MessageParser $messageParser;
protected IURLGenerator $url;
@@ -50,12 +52,14 @@ class MessageSearch implements IProvider {
public function __construct(
RoomManager $roomManager,
+ ParticipantService $participantService,
ChatManager $chatManager,
MessageParser $messageParser,
IURLGenerator $url,
IL10N $l
) {
$this->roomManager = $roomManager;
+ $this->participantService = $participantService;
$this->chatManager = $chatManager;
$this->messageParser = $messageParser;
$this->url = $url;
@@ -122,7 +126,7 @@ class MessageSearch implements IProvider {
}
if ($room->getLobbyState() !== Webinary::LOBBY_NONE) {
- $participant = $room->getParticipant($user->getUID(), false);
+ $participant = $this->participantService->getParticipant($room, $user->getUID(), false);
if (!($participant->getPermissions() & Attendee::PERMISSIONS_LOBBY_IGNORE)) {
continue;
}
@@ -165,7 +169,7 @@ class MessageSearch implements IProvider {
}
protected function commentToSearchResultEntry(Room $room, IUser $user, IComment $comment, ISearchQuery $query): SearchResultEntry {
- $participant = $room->getParticipant($user->getUID(), false);
+ $participant = $this->participantService->getParticipant($room, $user->getUID(), false);
$id = (int) $comment->getId();
$message = $this->messageParser->createMessage($room, $participant, $comment, $this->l);
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index cffbdb323..e6652c1fb 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -91,6 +91,9 @@ class ParticipantService {
private ITimeFactory $timeFactory;
private ICacheFactory $cacheFactory;
+ protected array $userCache;
+ protected array $sessionCache;
+
public function __construct(IConfig $serverConfig,
Config $talkConfig,
AttendeeMapper $attendeeMapper,
@@ -775,7 +778,7 @@ class ParticipantService {
$attendees = [];
foreach ($users as $user) {
try {
- $participant = $room->getParticipant($user->getUID());
+ $participant = $this->getParticipant($room, $user->getUID());
$participantType = $participant->getAttendee()->getParticipantType();
$attendees[] = $participant->getAttendee();
@@ -838,7 +841,7 @@ class ParticipantService {
$attendees = [];
foreach ($users as $user) {
try {
- $participant = $room->getParticipant($user->getUID());
+ $participant = $this->getParticipant($room, $user->getUID());
$participantType = $participant->getAttendee()->getParticipantType();
$attendees[] = $participant->getAttendee();
@@ -856,7 +859,7 @@ class ParticipantService {
public function removeUser(Room $room, IUser $user, string $reason): void {
try {
- $participant = $room->getParticipant($user->getUID(), false);
+ $participant = $this->getParticipant($room, $user->getUID(), false);
} catch (ParticipantNotFoundException $e) {
return;
}
@@ -1497,6 +1500,66 @@ class ParticipantService {
/**
* @param Room $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(Room $room, ?string $userId, $sessionId = null): Participant {
+ if (!is_string($userId) || $userId === '') {
+ throw new ParticipantNotFoundException('Not a user');
+ }
+
+ if (isset($this->userCache[$room->getId()][$userId])) {
+ $participant = $this->userCache[$room->getId()][$userId];
+ if (!$sessionId
+ || ($participant->getSession() instanceof Session
+ && $participant->getSession()->getSessionId() === $sessionId)) {
+ return $participant;
+ }
+ }
+
+ $query = $this->connection->getQueryBuilder();
+ $helper = new SelectHelper();
+ $helper->selectAttendeesTable($query);
+ $query->from('talk_attendees', 'a')
+ ->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($room->getId())))
+ ->setMaxResults(1);
+
+ if ($sessionId !== false) {
+ if ($sessionId !== null) {
+ $helper->selectSessionsTable($query);
+ $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 {
+ $helper->selectSessionsTable($query); // FIXME PROBLEM
+ $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'));
+ }
+ }
+
+ $participant = $this->getParticipantFromQuery($query, $room);
+
+ $this->userCache ??= [];
+ $this->userCache[$room->getId()] ??= [];
+ $this->userCache[$room->getId()][$userId] = $participant;
+ if ($participant->getSession()) {
+ $participantSessionId = $participant->getSession()->getSessionId();
+ $this->sessionCache ??= [];
+ $this->sessionCache[$room->getId()] ??= [];
+ $this->sessionCache[$room->getId()][$participantSessionId] = $participant;
+ }
+
+ return $participant;
+ }
+
+ /**
+ * @param Room $room
* @param string|null $sessionId
* @return Participant
* @throws ParticipantNotFoundException When the user is not a participant
@@ -1564,7 +1627,7 @@ class ParticipantService {
*/
public function getParticipantByActor(Room $room, string $actorType, string $actorId): Participant {
if ($actorType === Attendee::ACTOR_USERS) {
- return $room->getParticipant($actorId, false);
+ return $this->getParticipant($room, $actorId, false);
}
$query = $this->connection->getQueryBuilder();
diff --git a/lib/Share/Helper/ShareAPIController.php b/lib/Share/Helper/ShareAPIController.php
index dd5989907..b1c02cdc4 100644
--- a/lib/Share/Helper/ShareAPIController.php
+++ b/lib/Share/Helper/ShareAPIController.php
@@ -28,6 +28,7 @@ use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N;
@@ -41,21 +42,24 @@ use OCP\Share\IShare;
* actions or checks specific to room shares.
*/
class ShareAPIController {
- private string $userId;
- private Manager $manager;
+ protected string $userId;
+ protected Manager $manager;
+ protected ParticipantService $participantService;
protected ITimeFactory $timeFactory;
- private IL10N $l;
- private IURLGenerator $urlGenerator;
+ protected IL10N $l;
+ protected IURLGenerator $urlGenerator;
public function __construct(
string $UserId,
Manager $manager,
+ ParticipantService $participantService,
ITimeFactory $timeFactory,
IL10N $l10n,
IURLGenerator $urlGenerator
) {
$this->userId = $UserId;
$this->manager = $manager;
+ $this->participantService = $participantService;
$this->timeFactory = $timeFactory;
$this->l = $l10n;
$this->urlGenerator = $urlGenerator;
@@ -80,7 +84,7 @@ class ShareAPIController {
$result['share_with_displayname'] = $room->getDisplayName($this->userId);
try {
- $room->getParticipant($this->userId, false);
+ $this->participantService->getParticipant($room, $this->userId, false);
$result['share_with_link'] = $this->urlGenerator->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]);
} catch (ParticipantNotFoundException $e) {
// Removing the conversation token from the leaked data if not a participant.
@@ -163,7 +167,7 @@ class ShareAPIController {
}
try {
- $room->getParticipant($user, false);
+ $this->participantService->getParticipant($room, $user, false);
} catch (ParticipantNotFoundException $e) {
return false;
}
diff --git a/lib/Share/RoomShareProvider.php b/lib/Share/RoomShareProvider.php
index 500338e84..49f5c985d 100644
--- a/lib/Share/RoomShareProvider.php
+++ b/lib/Share/RoomShareProvider.php
@@ -153,7 +153,7 @@ class RoomShareProvider implements IShareProvider {
}
try {
- $participant = $room->getParticipant($share->getSharedBy(), false);
+ $participant = $this->participantService->getParticipant($room, $share->getSharedBy(), false);
} catch (ParticipantNotFoundException $e) {
// If the sharer is not a participant of the room even if the room
// exists the error is still "Room not found".
diff --git a/tests/php/Chat/NotifierTest.php b/tests/php/Chat/NotifierTest.php
index bf77fb75e..5a5636b24 100644
--- a/tests/php/Chat/NotifierTest.php
+++ b/tests/php/Chat/NotifierTest.php
@@ -129,9 +129,9 @@ class NotifierTest extends TestCase {
/** @var Room|MockObject */
$room = $this->createMock(Room::class);
- $room->expects($this->any())
+ $this->participantService->expects($this->any())
->method('getParticipant')
- ->willReturnCallback(function (string $actorId) use ($room, $settings): Participant {
+ ->willReturnCallback(function (Room $room, string $actorId) use ($settings): Participant {
if ($actorId === 'userNotInOneToOneChat') {
throw new ParticipantNotFoundException();
}
diff --git a/tests/php/Collaboration/Collaborators/RoomPluginTest.php b/tests/php/Collaboration/Collaborators/RoomPluginTest.php
index bb116ffd7..e3adbb595 100644
--- a/tests/php/Collaboration/Collaborators/RoomPluginTest.php
+++ b/tests/php/Collaboration/Collaborators/RoomPluginTest.php
@@ -30,6 +30,7 @@ use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\IUser;
@@ -39,6 +40,8 @@ use Test\TestCase;
class RoomPluginTest extends TestCase {
protected ?Manager $manager = null;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
protected ?IUserSession $userSession = null;
@@ -52,6 +55,7 @@ class RoomPluginTest extends TestCase {
parent::setUp();
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->user = $this->createMock(IUser::class);
$this->user->expects($this->any())
@@ -64,7 +68,11 @@ class RoomPluginTest extends TestCase {
$this->searchResult = $this->createMock(ISearchResult::class);
- $this->plugin = new RoomPlugin($this->manager, $this->userSession);
+ $this->plugin = new RoomPlugin(
+ $this->manager,
+ $this->participantService,
+ $this->userSession
+ );
}
private function newRoom(int $type, string $token, string $name, int $permissions = Attendee::PERMISSIONS_MAX_DEFAULT): Room {
@@ -83,7 +91,7 @@ class RoomPluginTest extends TestCase {
->method('getDisplayName')
->willReturn($name);
- $room->expects($this->any())
+ $this->participantService->expects($this->any())
->method('getParticipant')
->willReturn($participant);
@@ -111,73 +119,73 @@ class RoomPluginTest extends TestCase {
// Empty search term with rooms
['', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Room name')
+ [Room::TYPE_GROUP, 'roomToken', 'Room name'],
], [], [], false],
// Search term with no matches
['Unmatched search term', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Unmatched name')
+ [Room::TYPE_GROUP, 'roomToken', 'Unmatched name'],
], [], [], false],
// Search term with single wide match
['room', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken2', 'Unmatched name')
+ [Room::TYPE_GROUP, 'roomToken', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken2', 'Unmatched name'],
], [], [
- $this->newResult('Room name', 'roomToken')
+ $this->newResult('Room name', 'roomToken'),
], false],
// Chats without chat permission are not returned
['room', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Room name', Attendee::PERMISSIONS_MAX_DEFAULT ^ Attendee::PERMISSIONS_CHAT),
+ [Room::TYPE_GROUP, 'roomToken', 'Room name', Attendee::PERMISSIONS_MAX_DEFAULT ^ Attendee::PERMISSIONS_CHAT],
], [], [], false],
// Search term with single exact match
['room name', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Unmatched name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken2', 'Room name')
+ [Room::TYPE_GROUP, 'roomToken', 'Unmatched name'],
+ [Room::TYPE_GROUP, 'roomToken2', 'Room name'],
], [
- $this->newResult('Room name', 'roomToken2')
+ $this->newResult('Room name', 'roomToken2'),
], [], false],
// Search term with single exact match and single wide match
['room name', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Room name that also matches'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken2', 'Room name')
+ [Room::TYPE_GROUP, 'roomToken', 'Room name that also matches'],
+ [Room::TYPE_GROUP, 'roomToken2', 'Room name'],
], [
- $this->newResult('Room name', 'roomToken2')
+ $this->newResult('Room name', 'roomToken2'),
], [
- $this->newResult('Room name that also matches', 'roomToken')
+ $this->newResult('Room name that also matches', 'roomToken'),
], false],
// Search term matching one-to-one rooms (not possible in practice
// as one-to-one rooms do not have a name, but it would be if they
// had, so it is included here for completeness).
['room name', 2, 0, [
- $this->newRoom(Room::TYPE_ONE_TO_ONE, 'roomToken', 'Room name that also matches'),
- $this->newRoom(Room::TYPE_ONE_TO_ONE, 'roomToken2', 'Room name')
+ [Room::TYPE_ONE_TO_ONE, 'roomToken', 'Room name that also matches'],
+ [Room::TYPE_ONE_TO_ONE, 'roomToken2', 'Room name'],
], [
- $this->newResult('Room name', 'roomToken2')
+ $this->newResult('Room name', 'roomToken2'),
], [
- $this->newResult('Room name that also matches', 'roomToken')
+ $this->newResult('Room name that also matches', 'roomToken'),
], false],
// Search term matching public rooms
['room name', 2, 0, [
- $this->newRoom(Room::TYPE_PUBLIC, 'roomToken', 'Room name that also matches'),
- $this->newRoom(Room::TYPE_PUBLIC, 'roomToken2', 'Room name')
+ [Room::TYPE_PUBLIC, 'roomToken', 'Room name that also matches'],
+ [Room::TYPE_PUBLIC, 'roomToken2', 'Room name'],
], [
- $this->newResult('Room name', 'roomToken2')
+ $this->newResult('Room name', 'roomToken2'),
], [
- $this->newResult('Room name that also matches', 'roomToken')
+ $this->newResult('Room name that also matches', 'roomToken'),
], false],
// Search term with several wide matches
['room', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken2', 'Another room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken3', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken4', 'Another room name')
+ [Room::TYPE_GROUP, 'roomToken', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken2', 'Another room name'],
+ [Room::TYPE_GROUP, 'roomToken3', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken4', 'Another room name'],
], [], [
$this->newResult('Room name', 'roomToken'),
$this->newResult('Another room name', 'roomToken2'),
@@ -187,39 +195,39 @@ class RoomPluginTest extends TestCase {
// Search term with several exact matches
['room name', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken2', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken3', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken4', 'Room name')
+ [Room::TYPE_GROUP, 'roomToken', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken2', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken3', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken4', 'Room name'],
], [
$this->newResult('Room name', 'roomToken'),
$this->newResult('Room name', 'roomToken2'),
$this->newResult('Room name', 'roomToken3'),
- $this->newResult('Room name', 'roomToken4')
+ $this->newResult('Room name', 'roomToken4'),
], [], false],
// Search term with several matches
['room name', 2, 0, [
- $this->newRoom(Room::TYPE_GROUP, 'roomToken', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken2', 'Unmatched name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken3', 'Another room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken4', 'Room name'),
- $this->newRoom(Room::TYPE_ONE_TO_ONE, 'roomToken5', 'Room name'),
- $this->newRoom(Room::TYPE_PUBLIC, 'roomToken6', 'Room name'),
- $this->newRoom(Room::TYPE_GROUP, 'roomToken7', 'Another unmatched name'),
- $this->newRoom(Room::TYPE_ONE_TO_ONE, 'roomToken8', 'Another unmatched name'),
- $this->newRoom(Room::TYPE_PUBLIC, 'roomToken9', 'Another unmatched name'),
- $this->newRoom(Room::TYPE_ONE_TO_ONE, 'roomToken10', 'Another room name'),
- $this->newRoom(Room::TYPE_PUBLIC, 'roomToken11', 'Another room name')
+ [Room::TYPE_GROUP, 'roomToken', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken2', 'Unmatched name'],
+ [Room::TYPE_GROUP, 'roomToken3', 'Another room name'],
+ [Room::TYPE_GROUP, 'roomToken4', 'Room name'],
+ [Room::TYPE_ONE_TO_ONE, 'roomToken5', 'Room name'],
+ [Room::TYPE_PUBLIC, 'roomToken6', 'Room name'],
+ [Room::TYPE_GROUP, 'roomToken7', 'Another unmatched name'],
+ [Room::TYPE_ONE_TO_ONE, 'roomToken8', 'Another unmatched name'],
+ [Room::TYPE_PUBLIC, 'roomToken9', 'Another unmatched name'],
+ [Room::TYPE_ONE_TO_ONE, 'roomToken10', 'Another room name'],
+ [Room::TYPE_PUBLIC, 'roomToken11', 'Another room name'],
], [
$this->newResult('Room name', 'roomToken'),
$this->newResult('Room name', 'roomToken4'),
$this->newResult('Room name', 'roomToken5'),
- $this->newResult('Room name', 'roomToken6')
+ $this->newResult('Room name', 'roomToken6'),
], [
$this->newResult('Another room name', 'roomToken3'),
$this->newResult('Another room name', 'roomToken10'),
- $this->newResult('Another room name', 'roomToken11')
+ $this->newResult('Another room name', 'roomToken11'),
], false],
];
}
@@ -244,10 +252,15 @@ class RoomPluginTest extends TestCase {
array $expectedMatches,
bool $expectedHasMoreResults
) {
+ $rooms = [];
+ foreach ($roomsForParticipant as $roomData) {
+ $rooms[] = call_user_func_array([$this, 'newRoom'], $roomData);
+ }
+
$this->manager->expects($this->any())
->method('getRoomsForUser')
->with('user0')
- ->willReturn($roomsForParticipant);
+ ->willReturn($rooms);
$this->searchResult->expects($this->any())
->method('addResultSet')
diff --git a/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php b/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php
index 08c86db95..a97543059 100644
--- a/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php
+++ b/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php
@@ -28,6 +28,7 @@ use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Collaboration\Reference\TalkReferenceProvider;
use OCA\Talk\Manager;
+use OCA\Talk\Service\ParticipantService;
use OCP\IL10N;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
@@ -38,6 +39,8 @@ class TalkReferenceProviderTest extends TestCase {
protected $urlGenerator;
/** @var Manager|MockObject */
protected $roomManager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var ChatManager|MockObject */
protected $chatManager;
/** @var MessageParser|MockObject */
@@ -51,6 +54,7 @@ class TalkReferenceProviderTest extends TestCase {
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->roomManager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->chatManager = $this->createMock(ChatManager::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->l = $this->createMock(IL10N::class);
@@ -58,6 +62,7 @@ class TalkReferenceProviderTest extends TestCase {
$this->provider = new TalkReferenceProvider(
$this->urlGenerator,
$this->roomManager,
+ $this->participantService,
$this->chatManager,
$this->messageParser,
$this->l,
diff --git a/tests/php/Collaboration/Resources/ConversationProviderTest.php b/tests/php/Collaboration/Resources/ConversationProviderTest.php
index 921019520..29cd68ecb 100644
--- a/tests/php/Collaboration/Resources/ConversationProviderTest.php
+++ b/tests/php/Collaboration/Resources/ConversationProviderTest.php
@@ -30,6 +30,7 @@ use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
use OCP\IURLGenerator;
@@ -41,6 +42,8 @@ use Test\TestCase;
class ConversationProviderTest extends TestCase {
/** @var Manager|MockObject */
protected $manager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var IUserSession|MockObject */
protected $userSession;
/** @var IURLGenerator|MockObject */
@@ -51,11 +54,13 @@ class ConversationProviderTest extends TestCase {
parent::setUp();
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->provider = new ConversationProvider(
$this->manager,
+ $this->participantService,
$this->userSession,
$this->urlGenerator
);
@@ -98,9 +103,9 @@ class ConversationProviderTest extends TestCase {
->method('getId')
->willReturn('token');
$room = $this->createMock(Room::class);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with('uid')
+ ->with($room, 'uid')
->willThrowException(new ParticipantNotFoundException());
$this->manager->expects($this->once())
@@ -132,9 +137,9 @@ class ConversationProviderTest extends TestCase {
->method('getAttendee')
->willReturn($attendee);
$room = $this->createMock(Room::class);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with('uid')
+ ->with($room, 'uid')
->willReturn($participant);
$this->manager->expects($this->once())
@@ -177,9 +182,9 @@ class ConversationProviderTest extends TestCase {
->method('getAttendee')
->willReturn($attendee);
$room = $this->createMock(Room::class);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with('uid')
+ ->with($room, 'uid')
->willReturn($participant);
$this->manager->expects($this->once())
diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php
index d4821ba5a..dbec77c19 100644
--- a/tests/php/Controller/SignalingControllerTest.php
+++ b/tests/php/Controller/SignalingControllerTest.php
@@ -403,9 +403,9 @@ class SignalingControllerTest extends TestCase {
$participant->expects($this->any())
->method('getPermissions')
->willReturn(Attendee::PERMISSIONS_MAX_CUSTOM);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with($this->userId)
+ ->with($room, $this->userId)
->willReturn($participant);
$room->expects($this->once())
->method('getToken')
@@ -464,9 +464,9 @@ class SignalingControllerTest extends TestCase {
$participant->expects($this->any())
->method('getPermissions')
->willReturn(Attendee::PERMISSIONS_MAX_CUSTOM);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with($this->userId)
+ ->with($room, $this->userId)
->willReturn($participant);
$room->expects($this->once())
->method('getToken')
@@ -529,9 +529,9 @@ class SignalingControllerTest extends TestCase {
->method('hasModeratorPermissions')
->with(false)
->willReturn(true);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with($this->userId)
+ ->with($room, $this->userId)
->willReturn($participant);
$room->expects($this->once())
->method('getToken')
@@ -734,9 +734,9 @@ class SignalingControllerTest extends TestCase {
$participant->expects($this->any())
->method('getPermissions')
->willReturn($permissions);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with($this->userId)
+ ->with($room, $this->userId)
->willReturn($participant);
$room->expects($this->once())
->method('getToken')
@@ -829,9 +829,9 @@ class SignalingControllerTest extends TestCase {
$participant->expects($this->any())
->method('getPermissions')
->willReturn(Attendee::PERMISSIONS_MAX_CUSTOM);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with($this->userId)
+ ->with($room, $this->userId)
->willReturn($participant);
$room->expects($this->atLeastOnce())
->method('getToken')
@@ -1020,7 +1020,7 @@ class SignalingControllerTest extends TestCase {
'action' => 'join',
],
]);
- $participant = $room->getParticipant($this->userId, $oldSessionId);
+ $participant = $participantService->getParticipant($room, $this->userId, $oldSessionId);
$this->assertEquals($oldSessionId, $participant->getSession()->getSessionId());
// The user is reloading the browser which will join him with another
@@ -1038,7 +1038,7 @@ class SignalingControllerTest extends TestCase {
]);
// Now the new session id is stored in the database.
- $participant = $room->getParticipant($this->userId, $newSessionId);
+ $participant = $participantService->getParticipant($room, $this->userId, $newSessionId);
$this->assertEquals($newSessionId, $participant->getSession()->getSessionId());
// Leaving the old session id...
@@ -1053,7 +1053,7 @@ class SignalingControllerTest extends TestCase {
]);
// ...will keep the new session id in the database.
- $participant = $room->getParticipant($this->userId, $newSessionId);
+ $participant = $participantService->getParticipant($room, $this->userId, $newSessionId);
$this->assertEquals($newSessionId, $participant->getSession()->getSessionId());
}
}
diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php
index 54e1e50ec..96026c575 100644
--- a/tests/php/Notification/NotifierTest.php
+++ b/tests/php/Notification/NotifierTest.php
@@ -247,9 +247,9 @@ class NotifierTest extends TestCase {
->willReturn($room);
$participant = $this->createMock(Participant::class);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with('recipient')
+ ->with($room, 'recipient')
->willReturn($participant);
$this->lFactory->expects($this->exactly($numNotifications))
@@ -868,9 +868,9 @@ class NotifierTest extends TestCase {
->willReturn($roomName);
$participant = $this->createMock(Participant::class);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('getParticipant')
- ->with('recipient')
+ ->with($room, 'recipient')
->willReturn($participant);
if ($roomName !== '') {
diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php
index 28322a918..f20e37dd3 100644
--- a/tests/php/Signaling/BackendNotifierTest.php
+++ b/tests/php/Signaling/BackendNotifierTest.php
@@ -985,7 +985,7 @@ class BackendNotifierTest extends TestCase {
'actorId' => $notJoinedUserId,
]]);
- $notJoinedParticipant = $room->getParticipant($notJoinedUserId);
+ $notJoinedParticipant = $this->participantService->getParticipant($room, $notJoinedUserId);
$this->participantService->updateParticipantType($room, $notJoinedParticipant, Participant::MODERATOR);
$this->assertMessageWasSent($room, [