コード例 #1
0
 /**
  * Endpoint for periodic (every 10-20 seconds) maintenance services like:
  * - user authentication
  * - getting the list of actions to execute on the client side
  * - getting the list of events to listen on the client side
  * - maintenance actions in messages, bans, users, etc.
  */
 public function maintenanceEndpoint()
 {
     $this->verifyCheckSum();
     $response = array();
     try {
         $this->checkChatOpen();
         $this->checkUserAuthorization();
         $this->checkGetParams(array('channelId', 'lastActionId'));
         $channelId = $this->getGetParam('channelId');
         $channel = $this->channelsDAO->get($channelId);
         $this->checkChannel($channel);
         $this->checkChannelAuthorization($channel);
         // periodic maintenance:
         $this->userService->periodicMaintenance($channel);
         $this->messagesService->periodicMaintenance($channel);
         $this->bansService->periodicMaintenance();
         // load actions:
         $lastActionId = intval($this->getGetParam('lastActionId', 0));
         $user = $this->authentication->getUser();
         $response['actions'] = $this->actions->getJSONReadyActions($lastActionId, $user);
         // load events:
         $response['events'] = array();
         if ($this->userEvents->shouldTriggerEvent('usersList', $channel->getName())) {
             if ($this->options->isOptionEnabled('show_users')) {
                 $response['events'][] = array('name' => 'refreshUsersList', 'data' => $this->renderer->getRenderedUsersList($channel));
             }
             if ($this->options->isOptionEnabled('show_users_counter')) {
                 $response['events'][] = array('name' => 'refreshUsersCounter', 'data' => array('total' => $this->channelUsersDAO->getAmountOfUsersInChannel($channel->getId())));
             }
         }
     } catch (WiseChatUnauthorizedAccessException $exception) {
         $response['error'] = $exception->getMessage();
         $this->sendUnauthorizedStatus();
     } catch (Exception $exception) {
         $response['error'] = $exception->getMessage();
         $this->sendBadRequestStatus();
     }
     echo json_encode($response);
     die;
 }
コード例 #2
0
 /**
  * Refreshes username on user interface. Resets event tracker for users list and
  * publishes an action that refreshes username in plain places.
  *
  * @param WiseChatUser $user
  *
  * @return null
  */
 private function refreshUserName($user)
 {
     $this->userEvents->resetEventTracker('usersList');
     $this->actions->publishAction('refreshPlainUserName', array('name' => $user->getName()), $user);
 }