/** * Determine if the client has room ban right * * @param Client $client The client to check the right on * * @return bool True if the client has room ban right, false otherwise */ public function hasBanRight(Client $client) : bool { $userManager = new UserManager($client->getUser()); return $userManager->hasRoomBanRight($this->room); }
/** * Change a user right in a room to display it in the admin panel * * @param Room $room The room where the right has been updated * @param Client $client The client who got a right changed * * @return \Generator */ public function changeUserRight(Room $room, Client $client) { $clientRight = $client->getUser()->getRoomRight()->getEntityById($room->id)->__toArray(); foreach ($room->getClients() as $roomClient) { if ($roomClient->isRegistered()) { (yield $roomClient->getConnection()->send(json_encode(['service' => $this->serviceName, 'action' => 'updateRoom', 'roomId' => $room->id, 'changedRight' => $clientRight]))); } } }
/** * Update the client user * * @param array $data JSON decoded client data * @param Client $client The client object */ private function updateUser(array $data, Client $client) { $client->setUser(new User($data['user'])); $client->getUser()->setRight(new UserRight($data['user']['right'])); if (count($data['user']['roomRight']) > 0) { $roomRightCollection = new RoomRightCollection(); foreach ($data['user']['roomRight'] as $userChatRightInfo) { $roomRightCollection->add(new RoomRight($userChatRightInfo)); } $client->getUser()->setChatRight($roomRightCollection); } }
/** * Get a room historic for a specific room ID and with message date lower than the given value * * @param int $roomId The room ID to search messages in * @param Client $client The client who asked the historic * @param string $from The maximum message published date in UNIX micro timestamp (string) DEFAULT null * * @return array The list of messages found */ private function getRoomHistoric(int $roomId, Client $client, string $from = null) { $es = EsClientBuilder::create()->build(); $from = $from ?? static::microtimeAsInt(); $userIp = $client->getConnection()->getRemoteAddress(); $userId = -1; if ($client->getUser() !== null) { $userId = $client->getUser()->id; } return static::filterEsHitsByArray($es->search(['index' => $this->esIndex . '_read', 'type' => 'message', 'sort' => 'date:desc', 'fields' => 'pseudonym,message,type,date', 'size' => $this->historicStep, 'body' => ['query' => ['filtered' => ['filter' => ['bool' => ['must' => [['range' => ['date' => ['lt' => $from]]], ['term' => ['room' => $roomId]], ['bool' => ['should' => [['term' => ['type' => 'public']], ['bool' => ['should' => [['term' => ['userTo.id' => $userId]], ['term' => ['userTo.ip' => $userIp]]]]]]]]]]]]]]])); }