Move more functions to the services

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-10-26 15:17:22 +01:00
parent 696bb5e609
commit 3c61bd4749
No known key found for this signature in database
GPG key ID: 7076EA9751AACDDA
10 changed files with 224 additions and 290 deletions

View file

@ -165,7 +165,7 @@ class Notifier {
* @param string[] $alreadyNotifiedUsers
*/
public function notifyOtherParticipant(Room $chat, IComment $comment, array $alreadyNotifiedUsers): void {
$participants = $chat->getParticipantsByNotificationLevel(Participant::NOTIFY_ALWAYS);
$participants = $this->participantService->getParticipantsByNotificationLevel($chat, Participant::NOTIFY_ALWAYS);
$notification = $this->createNotification($chat, $comment, 'chat');
foreach ($participants as $participant) {
@ -179,7 +179,7 @@ class Notifier {
// Also notify default participants in one2one chats or when the admin default is "always"
if ($this->getDefaultGroupNotification() === Participant::NOTIFY_ALWAYS || $chat->getType() === Room::ONE_TO_ONE_CALL) {
$participants = $chat->getParticipantsByNotificationLevel(Participant::NOTIFY_DEFAULT);
$participants = $this->participantService->getParticipantsByNotificationLevel($chat, Participant::NOTIFY_DEFAULT);
foreach ($participants as $participant) {
if (!$this->shouldParticipantBeNotified($participant, $comment, $alreadyNotifiedUsers)) {
continue;

View file

@ -1057,7 +1057,7 @@ class RoomController extends AEnvironmentAwareController {
}
if ($result['lastPing'] > 0 && $result['lastPing'] <= $maxPingAge) {
$this->room->leaveRoom($userId);
$this->participantService->leaveRoomAsSession($this->room, $participant);
}
$result['userId'] = $participant->getAttendee()->getActorId();
@ -1303,7 +1303,7 @@ class RoomController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
$this->room->removeParticipantBySession($targetParticipant, Room::PARTICIPANT_REMOVED);
$this->participantService->removeAttendee($this->room, $targetParticipant, Room::PARTICIPANT_REMOVED);
return new DataResponse([]);
}

View file

@ -562,10 +562,8 @@ class SignalingController extends OCSController {
$this->sessionService->updateLastPing($participant->getSession(), $this->timeFactory->getTime());
}
} elseif ($action === 'leave') {
if (!empty($userId)) {
$room->leaveRoom($userId, $sessionId);
} elseif ($participant instanceof Participant) {
$room->removeParticipantBySession($participant, Room::PARTICIPANT_LEFT);
if ($participant instanceof Participant) {
$this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_LEFT);
}
}

View file

@ -26,6 +26,9 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use OCA\Talk\Config;
use OCA\Talk\Participant;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Webinary;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
@ -35,15 +38,19 @@ class WebinarController extends AEnvironmentAwareController {
/** @var ITimeFactory */
protected $timeFactory;
/** @var ParticipantService */
protected $participantService;
/** @var Config */
protected $talkConfig;
public function __construct(string $appName,
IRequest $request,
ITimeFactory $timeFactory,
ParticipantService $participantService,
Config $talkConfig) {
parent::__construct($appName, $request);
$this->timeFactory = $timeFactory;
$this->participantService = $participantService;
$this->talkConfig = $talkConfig;
}
@ -70,6 +77,17 @@ class WebinarController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
if ($state === Webinary::LOBBY_NON_MODERATORS) {
$participants = $this->participantService->getParticipantsInCall($this->room);
foreach ($participants as $participant) {
if ($participant->hasModeratorPermissions()) {
continue;
}
$this->participantService->changeInCall($this->room, $participant, Participant::FLAG_DISCONNECTED);
}
}
return new DataResponse();
}

View file

@ -240,7 +240,7 @@ class Manager {
$result = $query->execute();
while ($row = $result->fetch()) {
$room = $this->createRoomObject($row);
if (!$room->hasActiveSessions()) {
if (!$this->participantService->hasActiveSessions($room)) {
$room->setAssignedSignalingServer(null);
$cache->remove($room->getToken());
}

View file

@ -678,17 +678,6 @@ class Room {
$this->dispatcher->dispatch(self::EVENT_AFTER_LOBBY_STATE_SET, $event);
if ($newState === Webinary::LOBBY_NON_MODERATORS) {
$participants = $this->getParticipantsInCall();
foreach ($participants as $participant) {
if ($participant->hasModeratorPermissions()) {
continue;
}
$this->changeInCall($participant, Participant::FLAG_DISCONNECTED);
}
}
return true;
}
@ -730,31 +719,6 @@ class Room {
return true;
}
/**
* @param Participant $participant
* @param int $participantType
*/
public function setParticipantType(Participant $participant, int $participantType): void {
$event = new ModifyParticipantEvent($this, $participant, 'type', $participantType, $participant->getParticipantType());
$this->dispatcher->dispatch(self::EVENT_BEFORE_PARTICIPANT_TYPE_SET, $event);
$query = $this->db->getQueryBuilder();
$query->update('talk_attendees')
->set('participant_type', $query->createNamedParameter($participantType, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('actor_id', $query->createNamedParameter($participant->getUser())))
->andWhere($query->expr()->eq('actor_type', $query->createNamedParameter('users')));
if ($participant->getUser() === '') {
// FIXME
$query->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())));
}
$query->execute();
$this->dispatcher->dispatch(self::EVENT_AFTER_PARTICIPANT_TYPE_SET, $event);
}
/**
* @param IUser $user
* @param string $reason
@ -779,77 +743,6 @@ class Room {
$this->dispatcher->dispatch(self::EVENT_AFTER_USER_REMOVE, $event);
}
/**
* @param Participant $participant
* @param string $reason
*/
public function removeParticipantBySession(Participant $participant, string $reason): void {
$event = new RemoveParticipantEvent($this, $participant, $reason);
$this->dispatcher->dispatch(self::EVENT_BEFORE_PARTICIPANT_REMOVE, $event);
$query = $this->db->getQueryBuilder();
$query->delete('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())));
$query->execute();
$this->dispatcher->dispatch(self::EVENT_AFTER_PARTICIPANT_REMOVE, $event);
}
/**
* @param string $userId
* @param string|null $sessionId
*/
public function leaveRoom(string $userId, ?string $sessionId = null): void {
try {
$participant = $this->getParticipant($userId);
} catch (ParticipantNotFoundException $e) {
return;
}
$this->leaveRoomAsParticipant($participant, $sessionId);
}
/**
* @param Participant $participant
* @param string|null $sessionId
*/
public function leaveRoomAsParticipant(Participant $participant, ?string $sessionId = null): void {
$event = new ParticipantEvent($this, $participant);
$this->dispatcher->dispatch(self::EVENT_BEFORE_ROOM_DISCONNECT, $event);
// Reset session when leaving a normal room
$query = $this->db->getQueryBuilder();
$query->update('talk_participants')
->set('session_id', $query->createNamedParameter('0'))
->set('in_call', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('user_id', $query->createNamedParameter($participant->getUser())))
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->neq('participant_type', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
if ($sessionId !== null && $sessionId !== '0') {
$query->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)));
} elseif ($participant->getSessionId() !== '0') {
$query->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())));
}
$query->execute();
// And kill session when leaving a self joined room
$query = $this->db->getQueryBuilder();
$query->delete('talk_attendees')
->where($query->expr()->eq('actor_id', $query->createNamedParameter($participant->getUser())))
->andWhere($query->expr()->eq('actor_type', $query->createNamedParameter('users')))
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('participant_type', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
if ($sessionId !== null && $sessionId !== '0') {
$query->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)));
} elseif ($participant->getSessionId() !== '0') {
$query->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())));
}
$query->execute();
$this->dispatcher->dispatch(self::EVENT_AFTER_ROOM_DISCONNECT, $event);
}
/**
* @param string $password
* @return array
@ -907,128 +800,6 @@ class Room {
return $participants;
}
/**
* @return Participant[]
*/
public function getParticipantsInCall(): array {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->neq('in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED)));
$result = $query->execute();
$participants = [];
while ($row = $result->fetch()) {
$participants[] = $this->manager->createParticipantObject($this, $row);
}
$result->closeCursor();
return $participants;
}
/**
* @param int $lastPing When the last ping is older than the given timestamp, the user is ignored
* @return array[] Array of users with [users => [userId => [lastPing, sessionId]], guests => [[lastPing, sessionId]]]
* @deprecated Use self::getParticipants() instead
*/
public function getParticipantsLegacy(int $lastPing = 0): array {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
if ($lastPing > 0) {
$query->andWhere($query->expr()->gt('last_ping', $query->createNamedParameter($lastPing, IQueryBuilder::PARAM_INT)));
}
$result = $query->execute();
$users = $guests = [];
while ($row = $result->fetch()) {
if ($row['user_id'] !== '' && $row['user_id'] !== null) {
$users[$row['user_id']] = [
'inCall' => (int) $row['in_call'],
'lastPing' => (int) $row['last_ping'],
'sessionId' => $row['session_id'],
'participantType' => (int) $row['participant_type'],
];
} else {
$guests[] = [
'inCall' => (int) $row['in_call'],
'lastPing' => (int) $row['last_ping'],
'participantType' => (int) $row['participant_type'],
'sessionId' => $row['session_id'],
];
}
}
$result->closeCursor();
return [
'users' => $users,
'guests' => $guests,
];
}
/**
* @param int $notificationLevel
* @return Participant[] Array of participants
*/
public function getParticipantsByNotificationLevel(int $notificationLevel): array {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('notification_level', $query->createNamedParameter($notificationLevel, IQueryBuilder::PARAM_INT)));
$result = $query->execute();
$participants = [];
while ($row = $result->fetch()) {
$participants[] = $this->manager->createParticipantObject($this, $row);
}
$result->closeCursor();
return $participants;
}
/**
* @return bool
*/
public function hasActiveSessions(): bool {
$query = $this->db->getQueryBuilder();
$query->select('room_id')
->from('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->neq('session_id', $query->createNamedParameter('0')))
->setMaxResults(1);
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
return (bool) $row;
}
/**
* @return string[]
*/
public function getActiveSessions(): array {
$query = $this->db->getQueryBuilder();
$query->select('session_id')
->from('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->neq('session_id', $query->createNamedParameter('0')));
$result = $query->execute();
$sessions = [];
while ($row = $result->fetch()) {
$sessions[] = $row['session_id'];
}
$result->closeCursor();
return $sessions;
}
/**
* Get all user ids which are participants in a room but currently not in the call
* @return string[]

View file

@ -267,6 +267,16 @@ class ParticipantService {
}
}
public function removeAttendee(Room $room, Participant $participant, string $reason): void {
$event = new RemoveParticipantEvent($room, $participant, $reason);
$this->dispatcher->dispatch(Room::EVENT_BEFORE_PARTICIPANT_REMOVE, $event);
$this->sessionMapper->deleteByAttendeeId($participant->getAttendee()->getId());
$this->attendeeMapper->delete($participant->getAttendee());
$this->dispatcher->dispatch(Room::EVENT_AFTER_PARTICIPANT_REMOVE, $event);
}
public function removeUser(Room $room, IUser $user, string $reason): void {
try {
$participant = $room->getParticipant($user->getUID());
@ -396,6 +406,41 @@ class ParticipantService {
return $participants;
}
/**
* @param Room $room
* @return Participant[]
*/
public function getParticipantsWithSession(Room $room): array {
$query = $this->connection->getQueryBuilder();
$query->select('a.*')
->selectAlias('a.id', 'a_id')
->addSelect('s.*')
->selectAlias('s.id', 's_id')
->from('talk_attendees', 'a')
->leftJoin(
'a', 'talk_sessions', 's',
$query->expr()->eq('s.attendee_id', 'a.id')
)
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->isNotNull('s.id'));
$participants = [];
$result = $query->execute();
while ($row = $result->fetch()) {
$attendee = $this->attendeeMapper->createAttendeeFromRow($row);
$session = $this->sessionMapper->createSessionFromRow($row);
$participants[] = new Participant(
\OC::$server->getDatabaseConnection(), // FIXME
\OC::$server->getConfig(), // FIXME
$room, $attendee, $session);
}
$result->closeCursor();
return $participants;
}
/**
* @param Room $room
* @return Participant[]
@ -431,6 +476,42 @@ class ParticipantService {
return $participants;
}
/**
* @param Room $room
* @param int $notificationLevel
* @return Participant[]
*/
public function getParticipantsByNotificationLevel(Room $room, int $notificationLevel): array {
$query = $this->connection->getQueryBuilder();
$query->select('a.*')
->selectAlias('a.id', 'a_id')
->addSelect('s.*')
->selectAlias('s.id', 's_id')
->from('talk_sessions', 's')
->leftJoin(
's', 'talk_attendees', 'a',
$query->expr()->eq('s.attendee_id', 'a.id')
)
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('notification_level', $query->createNamedParameter($notificationLevel, IQueryBuilder::PARAM_INT)));
$participants = [];
$result = $query->execute();
while ($row = $result->fetch()) {
$attendee = $this->attendeeMapper->createAttendeeFromRow($row);
$session = $this->sessionMapper->createSessionFromRow($row);
$participants[] = new Participant(
\OC::$server->getDatabaseConnection(), // FIXME
\OC::$server->getConfig(), // FIXME
$room, $attendee, $session);
}
$result->closeCursor();
return $participants;
}
/**
* @param Room $room
* @param \DateTime|null $maxLastJoined
@ -479,4 +560,25 @@ class ParticipantService {
public function getNumberOfActors(Room $room): int {
return $this->attendeeMapper->countActorsByParticipantType($room->getId(), []);
}
/**
* @param Room $room
* @return bool
*/
public function hasActiveSessions(Room $room): bool {
$query = $this->connection->getQueryBuilder();
$query->select('a.room_id')
->from('talk_attendees', 'a')
->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq(
'a.id', 's.attendee_id'
))
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->isNotNull('s.id'))
->setMaxResults(1);
$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
return (bool) $row;
}
}

View file

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\Talk\Signaling;
use OCA\Talk\Config;
use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
@ -223,12 +224,11 @@ class BackendNotifier {
* The given room has been deleted.
*
* @param Room $room
* @param array $participants
* @param string[] $userIds
* @throws \Exception
*/
public function roomDeleted(Room $room, array $participants): void {
public function roomDeleted(Room $room, array $userIds): void {
$this->logger->info('Room deleted: ' . $room->getToken());
$userIds = array_keys($participants['users']);
$this->backendRequest($room, [
'type' => 'delete',
'delete' => [
@ -248,29 +248,45 @@ class BackendNotifier {
$this->logger->info('Room participants modified: ' . $room->getToken() . ' ' . print_r($sessionIds, true));
$changed = [];
$users = [];
$participants = $room->getParticipantsLegacy();
foreach ($participants['users'] as $userId => $participant) {
$participant['userId'] = $userId;
$users[] = $participant;
if (\in_array($participant['sessionId'], $sessionIds, true)) {
$participant['permissions'] = ['publish-media', 'publish-screen'];
if ($participant['participantType'] === Participant::OWNER ||
$participant['participantType'] === Participant::MODERATOR) {
$participant['permissions'][] = 'control';
$participants = $this->participantService->getParticipantsForRoom($room);
foreach ($participants as $participant) {
$attendee = $participant->getAttendee();
if ($attendee->getActorType() !== 'users'
&& $attendee->getActorType() !== 'guests') {
continue;
}
$data = [
'inCall' => Participant::FLAG_DISCONNECTED,
'lastPing' => 0,
'sessionId' => '0',
'participantType' => $attendee->getParticipantType(),
];
if ($attendee->getActorType() !== 'users') {
$data['userId'] = $attendee->getActorId();
}
$users[] = $data;
$session = $participant->getSession();
if ($session instanceof Session) {
$data['inCall'] = $session->getInCall();
$data['lastPing'] = $session->getLastPing();
$data['sessionId'] = $session->getSessionId();
$users[] = $data;
if (\in_array($session->getSessionId(), $sessionIds, true)) {
$data['permissions'] = ['publish-media', 'publish-screen'];
if ($attendee->getParticipantType() === Participant::OWNER ||
$attendee->getParticipantType() === Participant::MODERATOR) {
$data['permissions'][] = 'control';
}
$changed[] = $data;
}
$changed[] = $participant;
}
}
foreach ($participants['guests'] as $participant) {
if (!isset($participant['participantType'])) {
$participant['participantType'] = Participant::GUEST;
}
$users[] = $participant;
if (\in_array($participant['sessionId'], $sessionIds, true)) {
$participant['permissions'] = ['publish-media', 'publish-screen'];
$changed[] = $participant;
} else {
$users[] = $data;
}
}
$this->backendRequest($room, [
'type' => 'participants',
'participants' => [
@ -292,25 +308,38 @@ class BackendNotifier {
$this->logger->info('Room in-call status changed: ' . $room->getToken() . ' ' . $flags . ' ' . print_r($sessionIds, true));
$changed = [];
$users = [];
$participants = $room->getParticipantsLegacy();
foreach ($participants['users'] as $userId => $participant) {
$participant['userId'] = $userId;
if ($participant['inCall'] !== Participant::FLAG_DISCONNECTED) {
$users[] = $participant;
$participants = $this->participantService->getParticipantsForRoom($room);
foreach ($participants as $participant) {
$attendee = $participant->getAttendee();
if ($attendee->getActorType() !== 'users'
&& $attendee->getActorType() !== 'guests') {
continue;
}
if (\in_array($participant['sessionId'], $sessionIds, true)) {
$changed[] = $participant;
$data = [
'inCall' => Participant::FLAG_DISCONNECTED,
'lastPing' => 0,
'sessionId' => '0',
'participantType' => $attendee->getParticipantType(),
];
if ($attendee->getActorType() !== 'users') {
$data['userId'] = $attendee->getActorId();
}
}
foreach ($participants['guests'] as $participant) {
if (!isset($participant['participantType'])) {
$participant['participantType'] = Participant::GUEST;
}
if ($participant['inCall'] !== Participant::FLAG_DISCONNECTED) {
$users[] = $participant;
}
if (\in_array($participant['sessionId'], $sessionIds, true)) {
$changed[] = $participant;
$session = $participant->getSession();
if ($session instanceof Session) {
$data['inCall'] = $session->getInCall();
$data['lastPing'] = $session->getLastPing();
$data['sessionId'] = $session->getSessionId();
if ($session->getInCall() !== Participant::FLAG_DISCONNECTED) {
$users[] = $data;
}
if (\in_array($session->getSessionId(), $sessionIds, true)) {
$changed[] = $data;
}
}
}

View file

@ -37,6 +37,7 @@ use OCA\Talk\GuestManager;
use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\EventDispatcher\IEventDispatcher;
class Listener {
@ -99,12 +100,15 @@ class Listener {
/** @var Messages $messages */
$messages = \OC::$server->query(Messages::class);
$participants = $room->getParticipantsLegacy();
foreach ($participants['users'] as $participant) {
$messages->addMessage($participant['sessionId'], $participant['sessionId'], 'refresh-participant-list');
}
foreach ($participants['guests'] as $participant) {
$messages->addMessage($participant['sessionId'], $participant['sessionId'], 'refresh-participant-list');
/** @var ParticipantService $participantService */
$participantService = \OC::$server->query(ParticipantService::class);
$participants = $participantService->getParticipantsForRoom($room);
foreach ($participants as $participant) {
$session = $participant->getSession();
if ($session instanceof Session) {
$messages->addMessage($session->getSessionId(), $session->getSessionId(), 'refresh-participant-list');
}
}
};
$dispatcher->addListener(Room::EVENT_BEFORE_ROOM_DELETE, $listener);
@ -167,10 +171,11 @@ class Listener {
/** @var BackendNotifier $notifier */
$notifier = \OC::$server->query(BackendNotifier::class);
/** @var ParticipantService $participantService */
$participantService = \OC::$server->query(ParticipantService::class);
$room = $event->getRoom();
$participants = $room->getParticipantsLegacy();
$notifier->roomDeleted($room, $participants);
$notifier->roomDeleted($room, $participantService->getParticipantUserIds($room));
});
$dispatcher->addListener(Room::EVENT_AFTER_USER_REMOVE, static function (RemoveUserEvent $event) {
if (self::isUsingInternalSignaling()) {

View file

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace OCA\Talk\Signaling;
use OCA\Talk\Model\Session;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
@ -33,12 +35,17 @@ class Messages {
/** @var IDBConnection */
protected $db;
/** @var ParticipantService */
protected $participantService;
/** @var ITimeFactory */
protected $timeFactory;
public function __construct(IDBConnection $db,
ParticipantService $participantService,
ITimeFactory $timeFactory) {
$this->db = $db;
$this->participantService = $participantService;
$this->timeFactory = $timeFactory;
}
@ -88,10 +95,14 @@ class Messages {
]
);
foreach ($room->getActiveSessions() as $sessionId) {
$query->setParameter('sender', $sessionId)
->setParameter('recipient', $sessionId)
->execute();
$participants = $this->participantService->getParticipantsWithSession($room);
foreach ($participants as $participant) {
$session = $participant->getSession();
if ($session instanceof Session) {
$query->setParameter('sender', $session->getSessionId())
->setParameter('recipient', $session->getSessionId())
->execute();
}
}
}