/** * Class constructor */ private function __construct() { $this->conversationDao = MAILBOX_BOL_ConversationDao::getInstance(); $this->lastMessageDao = MAILBOX_BOL_LastMessageDao::getInstance(); $this->messageDao = MAILBOX_BOL_MessageDao::getInstance(); $this->attachmentDao = MAILBOX_BOL_AttachmentDao::getInstance(); }
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); }
public function findUnreadConversations($userId, $messageIgnoreList, $timeStamp = null) { if (empty($timeStamp)) { $timeStamp = time(); } $ignore = ""; if (!empty($messageIgnoreList)) { $ignore = " AND `m`.id NOT IN (" . $this->dbo->mergeInClause($messageIgnoreList) . ") "; } $sql = "SELECT `conv`.id FROM `{$this->getTableName()}` as `m`\r\n INNER JOIN `" . MAILBOX_BOL_ConversationDao::getInstance()->getTableName() . "` as `conv` ON (`conv`.`id` = `m`.`conversationId`)\r\n WHERE ( ( ( `conv`.`initiatorId` = :userId AND `conv`.`deleted` != " . MAILBOX_BOL_ConversationDao::DELETED_INITIATOR . " )\r\n OR ( `conv`.`interlocutorId` = :userId AND `conv`.`deleted` != " . MAILBOX_BOL_ConversationDao::DELETED_INTERLOCUTOR . " ) )\r\n AND `m`.`recipientId` = :userId AND `m`.`recipientRead` = 0 {$ignore} ) OR ( `m`.`senderId` = :userId AND `m`.`timeStamp` > :timeStamp )\r\n GROUP BY `conv`.`id`"; return $this->dbo->queryForColumnList($sql, array('userId' => $userId, 'timeStamp' => $timeStamp)); }
/** * Class constructor * */ protected function __construct() { $this->conversationDao = MAILBOX_BOL_ConversationDao::getInstance(); }