Пример #1
0
 public function onPing(OW_Event $event)
 {
     $eventParams = $event->getParams();
     $params = $eventParams['params'];
     if ($eventParams['command'] == 'mailbox_api_ping') {
         return $this->onApiPing($event);
     }
     if ($eventParams['command'] != 'mailbox_ping') {
         return;
     }
     if (empty($_SESSION['lastRequestTimestamp'])) {
         $_SESSION['lastRequestTimestamp'] = (int) $params['lastRequestTimestamp'];
     }
     if ((int) $params['lastRequestTimestamp'] - (int) $_SESSION['lastRequestTimestamp'] < 3) {
         $event->setData(array('error' => "Too much requests"));
     }
     $_SESSION['lastRequestTimestamp'] = (int) $params['lastRequestTimestamp'];
     if (!OW::getUser()->isAuthenticated()) {
         $event->setData(array('error' => "You have to sign in"));
     }
     if (!OW::getRequest()->isAjax()) {
         $event->setData(array('error' => "Ajax request required"));
     }
     $userId = OW::getUser()->getId();
     /** SET **/
     if (!empty($params['readMessageList'])) {
         $this->service->markMessageIdListRead($params['readMessageList']);
         $this->service->resetUserLastData($userId);
     }
     if (!empty($params['viewedConversationList'])) {
         $this->service->setConversationViewedInConsole($params['viewedConversationList'], OW::getUser()->getId());
         $this->service->resetUserLastData($userId);
     }
     $ajaxActionResponse = array();
     if (!empty($params['ajaxActionData'])) {
         $this->service->resetUserLastData($userId);
         foreach ($params['ajaxActionData'] as $action) {
             switch ($action['name']) {
                 case 'postMessage':
                     $ajaxActionResponse[$action['uniqueId']] = $this->ajaxService->postMessage($action['data']);
                     if (!empty($ajaxActionResponse[$action['uniqueId']]['message'])) {
                         $params['lastMessageTimestamp'] = $ajaxActionResponse[$action['uniqueId']]['message']['timeStamp'];
                     }
                     break;
                 case 'getLog':
                     $ajaxActionResponse[$action['uniqueId']] = $this->ajaxService->getLog($action['data']);
                     break;
                 case 'markConversationUnRead':
                     $ajaxActionResponse[$action['uniqueId']] = $this->ajaxService->markConversationUnRead($action['data']);
                     break;
                 case 'markConversationRead':
                     $this->ajaxService->markConversationRead($action['data']);
                     break;
                 case 'loadMoreConversations':
                     if (isset($action['data']['searching']) && $action['data']['searching'] == 1) {
                         $conversationIds = MAILBOX_BOL_ConversationDao::getInstance()->findConversationByKeyword($action['data']['kw'], 8, $action['data']['from']);
                         $ajaxActionResponse[$action['uniqueId']] = MAILBOX_BOL_ConversationService::getInstance()->getConversationItemByConversationIdList($conversationIds);
                     } else {
                         $ajaxActionResponse[$action['uniqueId']] = $this->service->getConversationListByUserId(OW::getUser()->getId(), $action['data']['from'], 10);
                     }
                     break;
                 case 'bulkActions':
                     $ajaxActionResponse[$action['uniqueId']] = $this->ajaxService->bulkActions($action['data']);
                     break;
             }
         }
     }
     /** **/
     /** GET **/
     $response = $this->service->getLastData($params);
     if (!empty($ajaxActionResponse)) {
         $response['ajaxActionResponse'] = $ajaxActionResponse;
     }
     $markedUnreadConversationList = $this->service->getMarkedUnreadConversationList(OW::getUser()->getId());
     if (count($markedUnreadConversationList) > 0) {
         $response['markedUnreadConversationList'] = $markedUnreadConversationList;
     }
     /** **/
     $event->setData($response);
 }