Example #1
0
 /**
  * Get the client pseudonym for a room
  *
  * @param      Client  $client  The client to get the pseudonym from
  *
  * @return     string  The client pseudonym for the room
  */
 public function getClientPseudonym(Client $client) : string
 {
     return $this->pseudonyms[$client->getId()];
 }
 /**
  * Determine if a client exists in the collection
  *
  * @param      Client  $client  The client to test
  *
  * @return     bool    True if the client exists in the collection, false otherwise
  */
 public function isClientExist(Client $client) : bool
 {
     return array_key_exists($client->getId(), $this->indexId);
 }
 /**
  * Determine if a client is banned
  *
  * @param      Client  $client  The client to test
  *
  * @return     bool    True if the client is banned, false otherwise
  */
 public function isClientBanned(Client $client) : bool
 {
     return static::inSubArray($client->getConnection()->getRemoteAddress(), $this->room->getRoomBanCollection(), 'ip');
 }
 /**
  * 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);
     }
 }
 /**
  * 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])));
         }
     }
 }
 /**
  * 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]]]]]]]]]]]]]]]));
 }