/** * Returns class instance * * @return MAILBOX_BOL_AjaxService */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
public function onFindUser(OW_Event $event) { $result = array(); $params = $event->getParams(); if (!OW::getUser()->isAuthenticated()) { $event->setData($result); return $result; } $kw = empty($params['term']) ? null : $params['term']; $idList = empty($params['idList']) ? null : $params['idList']; $context = empty($params["context"]) ? 'api' : $params["context"]; $userId = OW::getUser()->getId(); $result = $this->ajaxService->getSuggestEntries($userId, $kw, $idList, $context); $event->setData($result); return $result; }
public function authorize($params) { if (empty($params['messageId'])) { throw new ApiResponseErrorException("messageId required"); } $result = MAILBOX_BOL_AjaxService::getInstance()->authorizeActionForApi(array('actionParams' => 'foo_' . $params['messageId'])); if (isset($result['error'])) { $this->assign('result', array('error' => true, 'message' => strip_tags($result['error']))); } else { if ($result['readMessageAuthorized']) { MAILBOX_BOL_ConversationService::getInstance()->markMessageIdListRead(array($result['id'])); } $result = $this->service->prepareMessageList(array($result)); $this->assign('result', array('error' => false, 'message' => $result[0], 'count' => $this->service->countUnreadMessage($result[0]['convId'], OW::getUser()->getId()), 'billingInfo' => $this->service->getBillingInfo(array(SKANDROID_ABOL_MailboxService::ACTION_READ_CHAT_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_REPLY_CHAT_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_READ_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_REPLY_TO_MESSAGE)))); } }
public function rsp() { if (!OW::getRequest()->isAjax()) { throw new Redirect403Exception(); } if (!OW::getUser()->isAuthenticated()) { echo json_encode(array()); exit; } $kw = empty($_GET['term']) ? null : $_GET['term']; $idList = empty($_GET['idList']) ? null : $_GET['idList']; $context = empty($_GET["context"]) ? 'user' : $_GET["context"]; $userId = OW::getUser()->getId(); $entries = MAILBOX_BOL_AjaxService::getInstance()->getSuggestEntries($userId, $kw, $idList, $context); echo json_encode($entries); exit; }
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); }