diff --git a/application/src/Controller/MatrixController.php b/application/src/Controller/MatrixController.php index 936ac62..0413d96 100644 --- a/application/src/Controller/MatrixController.php +++ b/application/src/Controller/MatrixController.php @@ -9,6 +9,7 @@ use App\Entity\Users; use App\Traits\GeneralTrait; use App\Traits\MatrixSynapseTrait; +use stdClass; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Annotation\Route; @@ -17,14 +18,14 @@ /** * API Controller to serve a mock of the Matrix API. * - * @Route("/{serverID}/_matrix/client/r0") + * @Route("/{serverID}/_matrix/client") */ class MatrixController extends AbstractController { use GeneralTrait, MatrixSynapseTrait; /** - * @Route("", name="endpoint") + * @Route("/r0", name="endpoint") */ public function endpoint(): JsonResponse { @@ -37,7 +38,7 @@ public function endpoint(): JsonResponse /** * Login a user. * - * @Route("/login", name="login") + * @Route("/r0/login", name="login") * @param string $serverID * @param Request $request * @return JsonResponse @@ -117,7 +118,7 @@ public function login(string $serverID, Request $request) : JsonResponse { /** * Refresh the tokens. * - * @Route("/refresh", name="refresh") + * @Route("/r0/refresh", name="refresh") * @param string $serverID * @param Request $request * @return JsonResponse @@ -154,7 +155,7 @@ public function refresh(string $serverID, Request $request) : JsonResponse { /** * Create Matrix room. * - * @Route("/createRoom", name="createRoom") + * @Route("/r0/createRoom", name="createRoom") * @param string $serverID * @param Request $request * @return JsonResponse @@ -207,7 +208,7 @@ public function createRoom(string $serverID, Request $request) : JsonResponse { /** * Create Matrix room. * - * @Route("/rooms/{roomID}/kick", name="kick") + * @Route("/r0/rooms/{roomID}/kick", name="kick") * @param Request $request * @return JsonResponse */ @@ -245,8 +246,8 @@ public function kick(string $roomID, Request $request) : JsonResponse { /** * Update various room state components. * - * @Route("/rooms/{roomID}/state/{eventType}") - * @Route("/rooms/{roomID}/state/{eventType}/") + * @Route("/r0/rooms/{roomID}/state/{eventType}") + * @Route("/r0/rooms/{roomID}/state/{eventType}/") * @param string $serverID * @param string $eventType * @param Request $request @@ -312,65 +313,43 @@ public function roomState(string $serverID, string $roomID, string $eventType, R } /** - * Invite user into a room. + * Gets all joined members of a group. * - * @Route("/rooms/{roomID}/invite", name="inviteUser") + * @Route("/r0/rooms/{roomID}/joined_members", name="getJoinedMembers") * @param string $serverID + * @param string $roomID * @param Request $request * @return JsonResponse */ - public function inviteUser(string $serverID, string $roomID, Request $request) : JsonResponse { + public function getJoinedMembers(string $serverID, string $roomID, Request $request) : JsonResponse { // 1. Check call auth. // 2. Check HTTP method is accepted. - $accessCheck = $this->authHttpCheck(['POST'], $request); + $accessCheck = $this->authHttpCheck(['GET'], $request); if (!$accessCheck['status']) { return $accessCheck['message']; } - // Check if room exists. - $this->roomExists($roomID); - - $payload = json_decode($request->getContent()); - $userID = $payload->userid; + // Get all joined members. + $room_members = $this->getDoctrine() + ->getRepository(Roommembers::class) + ->findBy(['roomid' => $roomID, 'serverid' => $serverID]); - // Check if the user has already been invited. - $check = $this->isUserInvited($roomID, $userID); - if (!$check['status']) { - return $check['message']; - } + $joined_members = new stdClass(); + foreach ($room_members as $member) { + $userid = $member->getUserid(); - // Check if the user is banned from the group. - $check = $this->isUserBanned($roomID, $userID); - if (!$check['status']) { - return $check['message']; - } + $user = $this->getDoctrine() + ->getRepository(Users::class) + ->findBy(['userid' => $userid, 'serverid' => $serverID])[0]; - // Check if "currentuserid" is sent with the body. - if (!isset($payload->currentuserid)) { - return new JsonResponse((object) [ - 'errcode' => 'M_BAD_JSON', - 'message' => '"currentuserid" has not been sent as part of the body' - ], 400); + $userdetail = new stdClass(); + $userdetail->avatar_url = $user->getAvatarurl(); + $userdetail->display_name = $user->getDisplayname(); + $joined_members->{$userid} = $userdetail; } - // Check if the inviter is a member of the group. - $this->validateRoomInviter($roomID, $payload->currentuserid); - - // Store the room member in the DB. - $entityManager = $this->getDoctrine()->getManager(); - $roomMember = new Roommembers(); - - $roomMember->setRoomid($roomID); - $roomMember->setReason($payload->reason); - $roomMember->setUserid($userID); - $roomMember->setAccepted(); - $roomMember->setServerid($serverID); - - $entityManager->persist($roomMember); - $entityManager->flush(); - return new JsonResponse((object) [ - 'message' => 'The user has been invited to join the room' + 'joined' => $joined_members ], 200); } } diff --git a/application/src/Controller/SynapseController.php b/application/src/Controller/SynapseController.php index 8ce93f7..ef2d236 100644 --- a/application/src/Controller/SynapseController.php +++ b/application/src/Controller/SynapseController.php @@ -244,7 +244,7 @@ private function upsertUser(string $serverID, string $userID, Request $request, /** * Invite user into a room. * - * @Route("/v2/join/{roomID}", name="inviteUser") + * @Route("/v1/join/{roomID}", name="inviteUser") * @param string $serverID * @param Request $request * @return JsonResponse diff --git a/application/src/Entity/Users.php b/application/src/Entity/Users.php index 9e95333..6f1967e 100644 --- a/application/src/Entity/Users.php +++ b/application/src/Entity/Users.php @@ -64,6 +64,11 @@ class Users */ private $passwords; + /** + * @ORM\Column(type="text", nullable=true) + */ + private $avatarurl; + public function __construct() { $this->threepids = new ArrayCollection(); @@ -167,6 +172,18 @@ public function setPasswordpattern(string $passwordpattern = null): self return $this; } + public function getAvatarurl(): ?string + { + return $this->avatarurl; + } + + public function setAvatarurl(string $avatarurl = null): self + { + $this->avatarurl = $avatarurl; + + return $this; + } + /** * @return Collection */