Ejemplo n.º 1
0
 public function updateWithData($params)
 {
     if (!isset($params['lastRequestTimestamp'])) {
         return;
     }
     if ((int) $params['lastRequestTimestamp'] == 0) {
         $params['lastRequestTimestamp'] = time();
     }
     /***************************************************************************************************************/
     if (!empty($params['readMessageList'])) {
         $readMessageIdList = array();
         foreach ($params['readMessageList'] as $message) {
             $readMessageIdList[] = $message["id"];
         }
         $this->conversationService->markMessageIdListRead($readMessageIdList);
     }
     /***************************************************************************************************************/
     $ignoreMessageList = array();
     if (!empty($params['ignoreMessageList'])) {
         foreach ($params['ignoreMessageList'] as $message) {
             $ignoreMessageList[] = $message["id"];
         }
     }
     $m = $this->conversationService->findUnreadMessagesForApi($this->userId, $ignoreMessageList, $params['lastRequestTimestamp']);
     $this->setObject('messageList', $m);
     /***************************************************************************************************************/
     if (!isset($params['conversationListLength'])) {
         $params['conversationListLength'] = 0;
     }
     //        $count = $this->conversationService->countConversationListByUserId($this->userId);
     //
     //        if ((int)$params['conversationListLength'] != $count)
     //        {
     //            $list = $this->conversationService->getConversationListByUserId($this->userId);
     //            $this->setObject('conversationList', $list);
     //        }
     if (count($m) > 0) {
         $list = $this->conversationService->getChatUserList($this->userId, 0, 10);
         //TODO specify limits
         $this->setObject('conversationList', $list);
     }
     $this->setObject('lastRequestTimestamp', time());
 }
Ejemplo n.º 2
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);
 }