public static function AddByChannel($channelId, $arParams = array()) { global $DB; if (!is_array($channelId)) { $channelId = array($channelId); } if (strlen($arParams['module_id']) > 0 || strlen($arParams['command']) > 0) { $arData = array('module_id' => $arParams['module_id'], 'command' => $arParams['command'], 'params' => is_array($arParams['params']) ? $arParams['params'] : array()); if (CPullOptions::GetQueueServerStatus()) { $command = array('MESSAGE' => array($arData), 'ERROR' => ''); if (!is_array($channelId) && CPullOptions::GetQueueServerVersion() == 1) { $command['CHANNEL_ID'] = $channelId; } $message = CUtil::PhpToJsObject($command); if (!defined('BX_UTF') || !BX_UTF) { $message = $GLOBALS['APPLICATION']->ConvertCharset($message, SITE_CHARSET, 'utf-8'); } $res = CPullChannel::Send($channelId, str_replace("\n", " ", $message)); $result = $res ? true : false; } else { foreach ($channelId as $channel) { $arParams = array('CHANNEL_ID' => $channel, 'MESSAGE' => str_replace("\n", " ", serialize($arData)), '~DATE_CREATE' => $DB->CurrentTimeFunction()); $res = IntVal($DB->Add("b_pull_stack", $arParams, array("MESSAGE"))); $result = $res ? true : false; } } if (isset($arParams['push_text']) && strlen($arParams['push_text']) > 0 && isset($arParams['push_user']) && intval($arParams['push_user']) > 0) { $CPushManager = new CPushManager(); $CPushManager->AddQueue(array('USER_ID' => $arParams['push_user'], 'MESSAGE' => str_replace("\n", " ", $arParams['push_text']), 'PARAMS' => $arParams['push_params'], 'BADGE' => isset($arParams['push_badge']) ? intval($arParams['push_badge']) : '', 'TAG' => isset($arParams['push_tag']) ? $arParams['push_tag'] : '', 'SUB_TAG' => isset($arParams['push_sub_tag']) ? $arParams['push_sub_tag'] : '', 'APP_ID' => isset($arParams['push_app_id']) ? $arParams['push_app_id'] : '')); } return $result; } return false; }
public static function AddByChannel($channelId, $arParams = Array()) { global $DB; if (strlen($arParams['module_id']) > 0 || strlen($arParams['command']) > 0) { $arData = Array( 'module_id' => $arParams['module_id'], 'command' => $arParams['command'], 'params' => is_array($arParams['params'])? $arParams['params']: Array(), ); if (CPullOptions::GetNginxStatus()) { $message = CUtil::PhpToJsObject(Array('CHANNEL_ID' => $channelId, 'MESSAGE' => Array($arData), 'ERROR' => '')); if (!defined('BX_UTF') || !BX_UTF) $message = $GLOBALS['APPLICATION']->ConvertCharset($message, SITE_CHARSET,'utf-8'); $result = CPullChannel::Send($channelId, str_replace("\n", " ", $message)); } else { $arParams = Array( 'CHANNEL_ID' => $channelId, 'MESSAGE' => str_replace("\n", " ", serialize($arData)), '~DATE_CREATE' => $DB->CurrentTimeFunction(), ); $id = IntVal($DB->Add("b_pull_stack", $arParams, Array("MESSAGE"))); $result = $id? '{"channel": "'.$channelId.'", "id": "'.$id.'"}': false; } if (isset($arParams['push_text']) && strlen($arParams['push_text'])>0 && isset($arParams['push_user']) && intval($arParams['push_user'])>0) { $CPushManager = new CPushManager(); $CPushManager->AddQueue(Array( 'USER_ID' => $arParams['push_user'], 'MESSAGE' => str_replace("\n", " ", $arParams['push_text']), 'PARAMS' => $arParams['push_params'], 'BADGE' => isset($arParams['push_badge'])? intval($arParams['push_badge']): '', 'TAG' => isset($arParams['push_tag'])? $arParams['push_tag']: '', 'SUB_TAG' => isset($arParams['push_sub_tag'])? $arParams['push_sub_tag']: '', 'APP_ID' => isset($arParams['push_app_id'])? $arParams['push_app_id']: '', )); } return $result; } return false; }
function onExecuteStartWriting(\Bitrix\Main\Event $event) { $parameters = $event->getParameters(); $userId = $parameters[0]; $dialogId = $parameters[1] . $parameters[2]; if ($userId > 0) { if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } \CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS'); if (intval($dialogId) > 0) { \CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId))); } elseif (substr($dialogId, 0, 4) == 'chat') { $chatId = substr($dialogId, 4); $arRelation = \CIMChat::GetRelationById($chatId); unset($arRelation[$userId]); $pullMessage = array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)); \CPullStack::AddByUsers(array_keys($arRelation), $pullMessage); $orm = \Bitrix\Im\ChatTable::getById($chatId); $chat = $orm->fetch(); if ($chat['TYPE'] == IM_MESSAGE_OPEN) { \CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $pullMessage); } } } }
/** * Returns batch of the message * @return string */ public function getBatch() { $data = array("data" => array('contentTitle' => $this->title, "contentText" => $this->text, "messageParams" => $this->customProperties), "time_to_live" => $this->expiryValue, "registration_ids" => $this->deviceTokens); $data = CPushManager::_MakeJson($data, "", true); $batch = "Content-type: application/json\r\n"; $batch .= "Content-length: " . CUtil::BinStrlen($data) . "\r\n"; $batch .= "\r\n"; $batch .= $data; return base64_encode($batch); }
public static function AddByChannel($channelId, $arMessage) { global $DB; if (strlen($arMessage['module_id']) <= 0 || strlen($arMessage['command']) <= 0) { return false; } $arData = array('module_id' => $arMessage['module_id'], 'command' => $arMessage['command'], 'params' => is_array($arMessage['params']) ? $arMessage['params'] : array()); if (CPullOptions::GetNginxStatus()) { $CHTTP = new CHTTP(); $CHTTP->http_timeout = 10; if ($CHTTP->HTTPQuery('POST', CPullOptions::GetPublishUrl($channelId), str_replace("\n", " ", CUtil::PhpToJsObject(array('CHANNEL_ID' => $channelId, 'MESSAGE' => array($arData), 'ERROR' => ''))))) { $result = $CHTTP->result; } } else { $arParams = array('CHANNEL_ID' => $channelId, 'MESSAGE' => str_replace("\n", " ", serialize($arData)), '~DATE_CREATE' => $DB->CurrentTimeFunction()); $id = IntVal($DB->Add("b_pull_stack", $arParams, array("MESSAGE"))); $result = $id ? '{"channel": "' . $channelId . '", "id": "' . $id . '"}' : false; } if (isset($arMessage['push_text']) && strlen($arMessage['push_text']) > 0 && isset($arMessage['push_user']) && intval($arMessage['push_user']) > 0) { $CPushManager = new CPushManager(); $CPushManager->AddQueue(array('USER_ID' => $arMessage['push_user'], 'MESSAGE' => str_replace("\n", " ", $arMessage['push_text']), 'PARAMS' => $arMessage['push_params'], 'TAG' => isset($arMessage['push_tag']) ? $arMessage['push_tag'] : '')); } return $result; }
public function getPayload() { $sJSONPayload = str_replace('"' . self::APPLE_RESERVED_NAMESPACE . '":[]', '"' . self::APPLE_RESERVED_NAMESPACE . '":{}', CPushManager::_MakeJson($this->_getPayload(), "", false)); $nJSONPayloadLen = CUtil::BinStrlen($sJSONPayload); if ($nJSONPayloadLen > self::PAYLOAD_MAXIMUM_SIZE) { if ($this->_bAutoAdjustLongPayload) { $nMaxTextLen = $nTextLen = CUtil::BinStrlen($this->text) - ($nJSONPayloadLen - self::PAYLOAD_MAXIMUM_SIZE); if ($nMaxTextLen > 0) { while (CUtil::BinStrlen($this->text = CUtil::BinSubstr($this->text, 0, --$nTextLen)) > $nMaxTextLen) { } return $this->getPayload(); } else { throw new Exception("JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " . self::PAYLOAD_MAXIMUM_SIZE . " bytes. The message text can not be auto-adjusted."); } } else { throw new Exception("JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " . self::PAYLOAD_MAXIMUM_SIZE . " bytes"); } } return $sJSONPayload; }
public function getPayload() { $sJSONPayload = str_replace('"' . self::APPLE_RESERVED_NAMESPACE . '":[]', '"' . self::APPLE_RESERVED_NAMESPACE . '":{}', CPushManager::_MakeJson($this->_getPayload(), "", false)); $nJSONPayloadLen = CUtil::BinStrlen($sJSONPayload); if ($nJSONPayloadLen > $this->payloadMaxSize) { if ($this->_bAutoAdjustLongPayload) { $nMaxTextLen = $nTextLen = CUtil::BinStrlen($this->text) - ($nJSONPayloadLen - $this->payloadMaxSize); if ($nMaxTextLen > 0) { while (CUtil::BinStrlen($this->text = CUtil::BinSubstr($this->text, 0, --$nTextLen)) > $nMaxTextLen) { } return $this->getPayload(); } else { return false; } } else { return false; } } return $sJSONPayload; }
function onExecuteStartWriting(\Bitrix\Main\Event $event) { $parameters = $event->getParameters(); $userId = $parameters[0]; $dialogId = $parameters[1] . $parameters[2]; if ($userId > 0) { if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } \CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS'); if (intval($dialogId) > 0) { \CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId))); } elseif (substr($dialogId, 0, 4) == 'chat') { $arRelation = \CIMChat::GetRelationById(substr($dialogId, 4)); foreach ($arRelation as $rel) { if ($rel['USER_ID'] == $userId) { continue; } \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId))); } } } }
public function SetReadMessage($fromUserId, $lastId = null) { global $DB; $fromUserId = intval($fromUserId); if ($fromUserId <= 0) { return false; } $bReadMessage = false; if ($lastId == null) { $strSql = "\n\t\t\t\tSELECT MAX(M.ID) ID, M.CHAT_ID\n\t\t\t\tFROM b_im_relation RF\n\t\t\t\t\tINNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID\n\t\t\t\t\tINNER JOIN b_im_message M ON M.ID >= RT.LAST_ID AND M.CHAT_ID = RT.CHAT_ID\n\t\t\t\tWHERE RT.USER_ID = " . $this->user_id . "\n\t\t\t\t\tand RF.USER_ID = " . $fromUserId . "\n\t\t\t\t\tand RT.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "' and RT.STATUS < " . IM_STATUS_READ . "\n\t\t\t\tGROUP BY M.CHAT_ID"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, $arRes['ID']); } $lastId = $arRes['ID']; } else { $strSql = "\n\t\t\t\tSELECT RF.CHAT_ID\n\t\t\t\tFROM b_im_relation RF INNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID\n\t\t\t\tWHERE RT.USER_ID = " . $this->user_id . "\n\t\t\t\t\tand RF.USER_ID = " . $fromUserId . "\n\t\t\t\t\tand RT.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "'"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, intval($lastId)); } } if ($bReadMessage) { CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_MESSAGE); if (CModule::IncludeModule("pull")) { CPushManager::DeleteFromQueue($this->user_id, 'IM_MESS_' . $fromUserId); CPullStack::AddByUser($this->user_id, array('module_id' => 'im', 'command' => 'readMessage', 'params' => array('chatId' => intval($arRes['CHAT_ID']), 'senderId' => $this->user_id, 'id' => $fromUserId, 'userId' => $fromUserId, 'lastId' => $lastId))); } return true; } return false; }
/** * Method will be invoked after new database record inserted. * * @param array $newRecord All fields of inserted record. * * @return void */ public function afterInsertTrigger(array $newRecord) { $arParams = array(); $chatId = $newRecord['CHAT_ID']; $arRel = \CIMChat::GetRelationById($chatId); $arFields['MESSAGE_TYPE'] = ''; foreach ($arRel as $rel) { $arFields['MESSAGE_TYPE'] = $rel["MESSAGE_TYPE"]; break; } $arFields['PARAMS'] = array(); $arFields['FILES'] = array(); //CUserCounter::Increment($arFields['TO_USER_ID'], 'im_message_v2', '**', false); if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) { foreach ($arRel as $rel) { if ($rel['USER_ID'] == $newRecord['AUTHOR_ID']) { $arFields['FROM_USER_ID'] = $rel['USER_ID']; } else { $arFields['TO_USER_ID'] = $rel['USER_ID']; } } \CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['TO_USER_ID'], 'MESSAGE_ID' => $newRecord['ID'], 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['FROM_USER_ID'])); \CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['FROM_USER_ID'], 'MESSAGE_ID' => $newRecord['ID'], 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['TO_USER_ID'])); if (\CModule::IncludeModule('pull')) { $pullMessage = array('module_id' => 'im', 'command' => 'message', 'params' => \CIMMessage::GetFormatMessage(array('ID' => $newRecord['ID'], 'CHAT_ID' => $chatId, 'TO_USER_ID' => $arFields['TO_USER_ID'], 'FROM_USER_ID' => $arFields['FROM_USER_ID'], 'SYSTEM' => $newRecord['NOTIFY_EVENT'] == 'private_system' ? 'Y' : 'N', 'MESSAGE' => $newRecord['MESSAGE'], 'DATE_CREATE' => time(), 'PARAMS' => $arFields['PARAMS'], 'FILES' => $arFields['FILES']))); $pullMessageTo = $pullMessage; if (\CPullOptions::GetPushStatus()) { if (\CIMSettings::GetNotifyAccess($arFields["TO_USER_ID"], 'im', 'message', \CIMSettings::CLIENT_PUSH)) { $pushParams = \CIMMessenger::PreparePushForPrivate(array('FROM_USER_ID' => $arFields['FROM_USER_ID'], 'MESSAGE' => $newRecord['MESSAGE'], 'SYSTEM' => $arFields['SYSTEM'], 'FILES' => $arFields['FILES'])); $pullMessageTo = array_merge($pullMessage, $pushParams); } } \CPullStack::AddByUser($arFields['TO_USER_ID'], $pullMessageTo); \CPullStack::AddByUser($arFields['FROM_USER_ID'], $pullMessage); \CPushManager::DeleteFromQueueBySubTag($arFields['FROM_USER_ID'], 'IM_MESS'); //self::SendBadges($arFields['TO_USER_ID']); } } else { if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_CHAT || $arFields['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) { foreach ($arRel as $relation) { \CIMContactList::SetRecent(array('ENTITY_ID' => $relation['CHAT_ID'], 'MESSAGE_ID' => $newRecord['ID'], 'CHAT_TYPE' => $relation['MESSAGE_TYPE'], 'USER_ID' => $relation['USER_ID'])); } if (\CModule::IncludeModule('pull')) { $pullMessage = array('module_id' => 'im', 'command' => 'messageChat', 'params' => \CIMMessage::GetFormatMessage(array('ID' => $newRecord['ID'], 'CHAT_ID' => $chatId, 'TO_CHAT_ID' => $chatId, 'FROM_USER_ID' => $newRecord['AUTHOR_ID'], 'MESSAGE' => $newRecord['MESSAGE'], 'SYSTEM' => $newRecord['AUTHOR_ID'] > 0 ? 'N' : 'Y', 'DATE_CREATE' => time(), 'PARAMS' => $arFields['PARAMS'], 'FILES' => $arFields['FILES']))); $chat = \Bitrix\Im\ChatTable::getById($chatId); $chatData = $chat->fetch(); if ($chatData && \CPullOptions::GetPushStatus()) { $pushParams = \CIMMessenger::PreparePushForChat(array('CHAT_ID' => $chatId, 'CHAT_TITLE' => $chatData['TITLE'], 'FROM_USER_ID' => $newRecord['AUTHOR_ID'], 'MESSAGE' => $newRecord['MESSAGE'], 'SYSTEM' => $newRecord['AUTHOR_ID'] > 0 ? 'N' : 'Y', 'FILES' => $arFields['FILES'])); $pullMessage = array_merge($pullMessage, $pushParams); } $pullUsers = array(); $pullUsersSkip = array(); foreach ($arRel as $rel) { $pullUsers[] = $rel['USER_ID']; if ($rel['USER_ID'] == $newRecord['AUTHOR_ID']) { $pullUsersSkip[] = $rel['USER_ID']; \CPushManager::DeleteFromQueueBySubTag($newRecord['AUTHOR_ID'], 'IM_MESS'); } else { if ($rel['NOTIFY_BLOCK'] == 'Y' || !\CIMSettings::GetNotifyAccess($rel['USER_ID'], 'im', $arFields['MESSAGE_TYPE'] == IM_MESSAGE_OPEN ? 'openChat' : 'chat', \CIMSettings::CLIENT_PUSH)) { $pullUsersSkip[] = $rel['USER_ID']; } } } $pullMessage['push']['skip_users'] = $pullUsersSkip; \CPullStack::AddByUsers($pullUsers, $pullMessage); if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) { \CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $pullMessage); } /* TODO uncomment after fix mantis:66363 \CIMMessenger::SendMention(Array( 'CHAT_ID' => $chatId, 'CHAT_TITLE' => $chatData['TITLE'], 'CHAT_RELATION' => $arRel, 'CHAT_TYPE' => $chatData['TYPE'], 'MESSAGE' => $newRecord['MESSAGE'], 'FILES' => $arFields['FILES'], 'FROM_USER_ID' => $newRecord['AUTHOR_ID'], )); */ //\CIMMessenger::SendBadges($usersForBadges); foreach (\GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent) { \ExecuteModuleEventEx($arEvent, array($newRecord['ID'], $newRecord)); } } } } }
public static function SendAgent() { global $DB; if (!CPullOptions::GetPushStatus()) { return false; } $count = 0; $maxId = 0; $pushLimit = 70; $arPush = array(); $sqlDate = ""; $dbType = strtolower($DB->type); if ($dbType == "mysql") { $sqlDate = " WHERE DATE_CREATE < DATE_SUB(NOW(), INTERVAL 15 SECOND) "; } else { if ($dbType == "mssql") { $sqlDate = " WHERE DATE_CREATE < dateadd(SECOND, -15, getdate()) "; } else { if ($dbType == "oracle") { $sqlDate = " WHERE DATE_CREATE < SYSDATE-(1/24/60/60*15) "; } } } $strSql = $DB->TopSql("SELECT ID, USER_ID, MESSAGE, PARAMS, BADGE, APP_ID FROM b_pull_push_queue" . $sqlDate, 280); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->Fetch()) { if ($arRes['BADGE'] == '') { unset($arRes['BADGE']); } $arPush[$count][] = $arRes; if ($pushLimit <= count($arPush[$count])) { $count++; } $maxId = $maxId < $arRes['ID'] ? $arRes['ID'] : $maxId; } if ($maxId > 0) { $strSql = "DELETE FROM b_pull_push_queue WHERE ID <= " . $maxId; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $CPushManager = new CPushManager(); foreach ($arPush as $arStack) { $CPushManager->SendMessage($arStack); } $strSql = "SELECT COUNT(ID) CNT FROM b_pull_push_queue"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { global $pPERIOD; if ($arRes['CNT'] > 280) { $pPERIOD = 10; return "CPushManager::SendAgent();"; } else { if ($arRes['CNT'] > 0) { $pPERIOD = 30; return "CPushManager::SendAgent();"; } } } return false; }
public static function SendBadges($userID) { if (!(CModule::IncludeModule('pull') && CPullOptions::GetPushStatus())) return false; $arPush = Array(); if (!is_array($userID)) $userID = Array(intval($userID)); global $DB; if (empty($userID)) return false; foreach ($userID as $key => $userId) $userID[$key] = intval($userId); $sql = "SELECT SUM(CNT) CNT, USER_ID FROM b_user_counter WHERE USER_ID IN (".implode(',', $userID).") and SITE_ID = '**' and CODE IN ('im_notify', 'im_message', 'im_chat') GROUP BY USER_ID"; $res = $DB->Query($sql); while($row = $res->Fetch()) $arPush[] = Array('USER_ID' => $row['USER_ID'], 'BADGE' => $row['CNT']); $CPushManager = new CPushManager(); $CPushManager->SendMessage($arPush, defined('PULL_PUSH_SANDBOX')? true: false); }
public static function SendAgent() { global $DB; if (!CPullOptions::GetPushStatus()) { return false; } $count = 0; $maxId = 0; $pushLimit = 70; $arPush = array(); $sqlDate = ""; $dbType = strtolower($DB->type); if ($dbType == "mysql") { $sqlDate = " WHERE DATE_CREATE < DATE_SUB(NOW(), INTERVAL 15 SECOND) "; } else { if ($dbType == "mssql") { $sqlDate = " WHERE DATE_CREATE < dateadd(SECOND, -15, getdate()) "; } else { if ($dbType == "oracle") { $sqlDate = " WHERE DATE_CREATE < SYSDATE-(1/24/60/60*15) "; } } } $strSql = $DB->TopSql("SELECT ID, USER_ID, MESSAGE, PARAMS FROM b_pull_push_queue" . $sqlDate, 280); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->Fetch()) { $arPush[$count][] = $arRes; if ($pushLimit <= count($arPush[$count])) { $count++; } $maxId = $maxId < $arRes['ID'] ? $arRes['ID'] : $maxId; } foreach ($arPush as $arStack) { $CPushManager = new CPushManager(); $CPushManager->SendMessage($arStack, defined('PULL_PUSH_SANDBOX') ? true : false); } if ($maxId > 0) { $strSql = "DELETE FROM b_pull_push_queue WHERE ID <= " . $maxId; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $strSql = "SELECT COUNT(ID) CNT FROM b_pull_push_queue"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { if ($arRes['CNT'] > 280) { CAgent::RemoveAgent("CPushManager::SendAgent();", "pull"); CAgent::AddAgent("CPushManager::SendAgent();", "pull", "N", 15, "", "Y", ConvertTimeStamp(time() + CTimeZone::GetOffset() + 15, "FULL")); } else { if ($arRes['CNT'] > 0) { return "CPushManager::SendAgent();"; } } } return false; }
/** * Method will be invoked after new database record inserted. * * @param array $newRecord All fields of inserted record. * * @return void */ public function afterInsertTrigger(array $newRecord) { $arParams = array(); $chatId = $newRecord['CHAT_ID']; $arRel = \CIMChat::GetRelationById($chatId); //AddMessage2Log($newRecord); //AddMessage2Log($arRel); $arFields['MESSAGE_TYPE'] = ''; foreach ($arRel as $rel) { $arFields['MESSAGE_TYPE'] = $rel["MESSAGE_TYPE"]; break; } //AddMessage2Log($arParams); //CUserCounter::Increment($arFields['TO_USER_ID'], 'im_message_v2', '**', false); if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) { foreach ($arRel as $rel) { if ($rel['USER_ID'] == $newRecord['AUTHOR_ID']) { $arFields['FROM_USER_ID'] = $rel['USER_ID']; } else { $arFields['TO_USER_ID'] = $rel['USER_ID']; } } \CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['TO_USER_ID'], 'MESSAGE_ID' => $newRecord['ID'], 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['FROM_USER_ID'])); \CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['FROM_USER_ID'], 'MESSAGE_ID' => $newRecord['ID'], 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['TO_USER_ID'])); if (\CModule::IncludeModule('pull')) { $arPullTo = array('module_id' => 'im', 'command' => 'message', 'params' => \CIMMessage::GetFormatMessage(array('ID' => $newRecord['ID'], 'CHAT_ID' => $chatId, 'TO_USER_ID' => $arFields['TO_USER_ID'], 'FROM_USER_ID' => $arFields['FROM_USER_ID'], 'SYSTEM' => $newRecord['NOTIFY_EVENT'] == 'private_system' ? 'Y' : 'N', 'MESSAGE' => $newRecord['MESSAGE'], 'DATE_CREATE' => time()))); $arPullFrom = $arPullTo; \CPullStack::AddByUser($arFields['TO_USER_ID'], $arPullTo); \CPullStack::AddByUser($arFields['FROM_USER_ID'], $arPullFrom); \CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS'); //self::SendBadges($arParams['TO_USER_ID']); } } else { if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_CHAT || $arFields['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) { foreach ($arRel as $relation) { \CIMContactList::SetRecent(array('ENTITY_ID' => $relation['CHAT_ID'], 'MESSAGE_ID' => $newRecord['ID'], 'CHAT_TYPE' => $relation['MESSAGE_TYPE'], 'USER_ID' => $relation['USER_ID'])); } if (\CModule::IncludeModule('pull')) { $arPullTo = array('module_id' => 'im', 'command' => 'messageChat', 'params' => \CIMMessage::GetFormatMessage(array('ID' => $newRecord['ID'], 'CHAT_ID' => $chatId, 'TO_CHAT_ID' => $chatId, 'FROM_USER_ID' => $newRecord['AUTHOR_ID'], 'MESSAGE' => $newRecord['MESSAGE'], 'SYSTEM' => $newRecord['AUTHOR_ID'] > 0 ? 'N' : 'Y', 'DATE_CREATE' => time()))); $arPullFrom = $arPullTo; foreach ($arRel as $rel) { if ($rel['USER_ID'] == $arParams['FROM_USER_ID']) { \CPullStack::AddByUser($arParams['FROM_USER_ID'], $arPullFrom); \CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS'); } else { \CPullStack::AddByUser($rel['USER_ID'], $arPullTo); //$usersForBadges[] = $rel['USER_ID']; } } } } } }
public static function DeleteBySubTag($notifySubTag, $authorId = false) { global $DB; if (strlen($notifySubTag) <= 0) { return false; } $sqlUser = ""; $sqlUser2 = ""; if ($authorId !== false) { $sqlUser = "******" . intval($authorId); $sqlUser2 = " AND AUTHOR_ID = " . intval($authorId); } $dbRes = $DB->Query("SELECT M.ID, M.NOTIFY_TYPE, R.USER_ID, R.STATUS FROM b_im_relation R, b_im_message M WHERE M.CHAT_ID = R.CHAT_ID AND M.NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $arUsers = array(); $messages = array(); while ($row = $dbRes->Fetch()) { $messages[$row['ID']] = $row['NOTIFY_TYPE']; $count = $row['STATUS'] < IM_STATUS_READ ? 1 : 0; if (isset($arUsers[$row['USER_ID']])) { $arUsers[$row['USER_ID']] += $count; } else { $arUsers[$row['USER_ID']] = $count; } } $pullActive = false; if (CModule::IncludeModule("pull")) { $pullActive = true; } $arUsersSend = array(); foreach ($arUsers as $userId => $count) { CIMMessenger::SpeedFileDelete($userId, IM_SPEED_NOTIFY); if ($count > 0) { $arUsersSend[] = $userId; //CUserCounter::Decrement($userId, 'im_notify_v2', '**', false); } if ($pullActive) { CPushManager::DeleteFromQueueBySubTag($userId, $notifySubTag); } } if ($pullActive) { CPullStack::AddByUsers(array_keys($arUsers), array('module_id' => 'im', 'command' => 'massDeleteMessage', 'params' => array('MESSAGE' => $messages))); } if (count($messages) > 0) { $messageParameters = IM\MessageParamTable::getList(array('select' => array('ID'), 'filter' => array('=MESSAGE_ID' => array_keys($messages)))); while ($ar = $messageParameters->fetch()) { IM\MessageParamTable::delete($ar['ID']); } $strSql = "DELETE FROM b_im_message WHERE NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser2; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } CIMMessenger::SendBadges($arUsersSend); return true; }
public static function SendBadges($userID) { return false; if (!(CModule::IncludeModule('pull') && CPullOptions::GetPushStatus())) return false; $arPush = Array(); if (!is_array($userID)) $userID = Array(intval($userID)); global $DB; if (empty($userID)) return false; foreach ($userID as $key => $userId) $userID[$key] = intval($userId); $CPushManager = new CPushManager(); $sql = "SELECT SUM(CNT) CNT, USER_ID FROM b_user_counter WHERE USER_ID IN (".implode(',', $userID).") and SITE_ID = '**' and CODE IN ('im_notify_v2', 'im_message_v2', 'im_chat_v2') GROUP BY USER_ID"; $res = $DB->Query($sql); while($row = $res->Fetch()) { $CPushManager->AddQueue(Array('USER_ID' => $row['USER_ID'], 'BADGE' => $row['CNT'], 'SEND_IMMEDIATELY' => 'Y')); } return true; }
public static function AddToStack($tag, $arMessage) { global $DB; $arPush = array(); if (isset($arMessage['push'])) { $arPush = $arMessage['push']; unset($arMessage['push']); } $channels = array(); $strSql = "\n\t\t\t\tSELECT pc.CHANNEL_ID, pc.USER_ID\n\t\t\t\tFROM b_pull_watch pw\n\t\t\t\tLEFT JOIN b_pull_channel pc ON pw.USER_ID = pc.USER_ID\n\t\t\t\tWHERE pw.TAG = '" . $DB->ForSQL($tag) . "'\n\t\t"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->Fetch()) { $channels[$arRes['USER_ID']] = $arRes['CHANNEL_ID']; } $result = CPullStack::AddByChannel($channels, $arMessage); if ($result && !empty($arPush) && (isset($arPush['advanced_params']) || isset($arPush['message']) && strlen($arPush['message']) > 0)) { $CPushManager = new CPushManager(); $pushUsers = array(); foreach ($channels as $userId => $channelId) { if (isset($arPush['skip_users']) && in_array($userId, $arPush['skip_users'])) { continue; } $pushUsers[] = $userId; } $CPushManager->AddQueue(array('USER_ID' => $pushUsers, 'MESSAGE' => str_replace("\n", " ", $arPush['message']), 'PARAMS' => $arPush['params'], 'ADVANCED_PARAMS' => isset($arPush['advanced_params']) ? $arPush['advanced_params'] : array(), 'BADGE' => isset($arPush['badge']) ? intval($arPush['badge']) : '', 'SOUND' => isset($arPush['sound']) ? $arPush['sound'] : '', 'TAG' => isset($arPush['tag']) ? $arPush['tag'] : '', 'SUB_TAG' => isset($arPush['sub_tag']) ? $arPush['sub_tag'] : '', 'APP_ID' => isset($arPush['app_id']) ? $arPush['app_id'] : '', 'SEND_IMMEDIATELY' => isset($arPush['send_immediately']) && $arPush['send_immediately'] == 'Y' ? 'Y' : 'N')); } return true; }
public static function End($arParams) { $arConfig['CHAT_ID'] = intval($arParams['CHAT_ID']); if ($arConfig['CHAT_ID'] <= 0) { return false; } global $DB, $USER; $arConfig['USER_ID'] = intval($arParams['USER_ID']) > 0 ? intval($arParams['USER_ID']) : IntVal($USER->GetID()); $arConfig['RECIPIENT_ID'] = intval($arParams['RECIPIENT_ID']); $arChat = CIMChat::GetChatData(array('ID' => $arConfig['CHAT_ID'])); if (empty($arChat['chat'])) { return false; } $arUserToConnect = array(); $acceptUserExists = false; foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus) { if ($userId != $arConfig['USER_ID'] && in_array($callStatus, array(IM_CALL_STATUS_WAIT, IM_CALL_STATUS_ANSWER))) { if ($callStatus == IM_CALL_STATUS_ANSWER) { $acceptUserExists = true; } $arUserToConnect[] = $userId; } } if (!$acceptUserExists || empty($arUserToConnect) || count($arUserToConnect) == 1) { $arConfig['CLOSE_CONNECT'] = true; $strSql = "UPDATE b_im_chat SET CALL_TYPE = " . IM_CALL_NONE . " WHERE ID = " . $arConfig['CHAT_ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $strSql = "UPDATE b_im_relation SET CALL_STATUS = " . IM_CALL_STATUS_NONE . " WHERE CHAT_ID = " . $arConfig['CHAT_ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } else { $arConfig['CLOSE_CONNECT'] = false; $strSql = "UPDATE b_im_relation SET CALL_STATUS = " . IM_CALL_STATUS_DECLINE . " WHERE CHAT_ID = " . $arConfig['CHAT_ID'] . " AND USER_ID = " . $arConfig['USER_ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $arConfig['CALL_TO_GROUP'] = $arChat['chat'][$arConfig['CHAT_ID']]['type'] == IM_MESSAGE_GROUP; if ($arParams['REASON'] == 'decline') { if ($arConfig['CALL_TO_GROUP']) { if ($arParams['ACTIVE'] == 'Y') { self::MessageToChat($arConfig['CHAT_ID'], $arConfig['CLOSE_CONNECT'] ? "IM_CALL_CHAT_CLOSE_" : "IM_CALL_CHAT_END_", $arConfig['USER_ID'], true); } else { self::MessageToChat($arConfig['CHAT_ID'], $arConfig['CLOSE_CONNECT'] ? "IM_CALL_CHAT_CLOSE_" : "IM_CALL_CHAT_G_DECLINE_", $arConfig['USER_ID'], true); } } else { if ($arParams['ACTIVE'] == 'Y') { self::MessageToPrivate($arConfig['USER_ID'], $arConfig['RECIPIENT_ID'], "IM_CALL_CHAT_END"); } else { self::MessageToPrivate($arConfig['USER_ID'], $arConfig['RECIPIENT_ID'], "IM_CALL_CHAT_DECLINE_", true); } } } else { if ($arParams['REASON'] == 'busy') { if ($arConfig['CALL_TO_GROUP']) { self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_G_BUSY_", $arConfig['USER_ID'], true); } else { self::MessageToPrivate($arConfig['USER_ID'], $arConfig['RECIPIENT_ID'], "IM_CALL_CHAT_BUSY_", true); } } else { if ($arParams['REASON'] == 'waitTimeout') { if ($arConfig['CALL_TO_GROUP']) { self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_TIMEOUT"); } else { self::MessageToPrivate($arConfig['USER_ID'], $arConfig['RECIPIENT_ID'], "IM_CALL_CHAT_WAIT", $arConfig['RECIPIENT_ID'], false); } } else { if ($arParams['REASON'] == 'errorOffline') { if ($arConfig['CALL_TO_GROUP']) { self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_TIMEOUT"); } else { self::MessageToPrivate($arConfig['RECIPIENT_ID'], $arConfig['USER_ID'], "IM_CALL_CHAT_OFFLINE", true, false); } } else { if ($arParams['REASON'] == 'errorAccess') { if ($arConfig['CALL_TO_GROUP']) { self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_ERROR_", $arConfig['USER_ID'], true); } else { self::MessageToPrivate($arConfig['USER_ID'], $arConfig['RECIPIENT_ID'], "IM_CALL_CHAT_ERROR", true, false); } } } } } } $arSend = array(); $arSend['callToGroup'] = $arConfig['CALL_TO_GROUP']; $arSend['closeConnect'] = $arConfig['CLOSE_CONNECT']; if (isset($arParams['VIDEO'])) { $arSend['video'] = $arParams['VIDEO'] == 'Y' ? true : false; } foreach ($arUserToConnect as $userId) { self::Command($arConfig['CHAT_ID'], $userId, $arParams['REASON'], $arSend); } if ($arParams['REASON'] == 'decline') { self::Command($arConfig['CHAT_ID'], $arConfig['USER_ID'], 'decline_self', $arSend); self::Command($arConfig['CHAT_ID'], $arConfig['RECIPIENT_ID'], 'end_call', $arSend); if (false && !$arConfig['CALL_TO_GROUP'] && CModule::IncludeModule('pull') && CPullOptions::GetPushStatus()) { $CPushManager = new CPushManager(); $CPushManager->AddQueue(array('USER_ID' => $arConfig['USER_ID'], 'EXPIRY' => 0, 'APP_ID' => 'Bitrix24', 'SEND_IMMEDIATELY' => 'Y')); } } return true; }
public function SetReadMessage($chatId, $lastId = null) { global $DB; $chatId = intval($chatId); if ($chatId <= 0) { return false; } $bReadMessage = false; if ($lastId == null) { $strSql = "\n\t\t\t\tSELECT MAX(M.ID) ID, M.CHAT_ID\n\t\t\t\tFROM b_im_message M\n\t\t\t\tINNER JOIN b_im_relation R1 ON M.ID >= R1.LAST_ID AND M.CHAT_ID = R1.CHAT_ID\n\t\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . "\n\t\t\t\tGROUP BY M.CHAT_ID\n\t\t\t"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = CIMMessage::SetLastId($chatId, $this->user_id, $arRes['ID']); } $lastId = $arRes['ID']; } else { $bReadMessage = CIMMessage::SetLastId($chatId, $this->user_id, intval($lastId)); } if ($bReadMessage) { CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_GROUP); if (CModule::IncludeModule("pull")) { CPushManager::DeleteFromQueue($this->user_id, 'IM_GROUP_' . $chatId); CPullStack::AddByUser($this->user_id, array('module_id' => 'im', 'command' => 'readMessageChat', 'params' => array('chatId' => $chatId, 'lastId' => $lastId))); } return true; } return false; }
public function SetReadMessage($fromUserId, $lastId = null) { global $DB; $fromUserId = intval($fromUserId); if ($fromUserId <= 0) return false; $sqlLastId = ''; if (intval($lastId) > 0) $sqlLastId = "AND M.ID <= ".intval($lastId); $strSql = " SELECT COUNT(M.ID) CNT, MAX(M.ID) ID, M.CHAT_ID FROM b_im_relation RF INNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID INNER JOIN b_im_message M ON M.ID > RT.LAST_ID ".$sqlLastId." AND M.CHAT_ID = RT.CHAT_ID WHERE RT.USER_ID = ".$this->user_id." and RF.USER_ID = ".$fromUserId." and RT.MESSAGE_TYPE = '".IM_MESSAGE_PRIVATE."' and RT.STATUS < ".IM_STATUS_READ." GROUP BY M.CHAT_ID"; $dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, $arRes['ID']); if ($bReadMessage) { //CUserCounter::Decrement($this->user_id, 'im_message_v2', '**', false, $arRes['CNT']); CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_MESSAGE); if (CModule::IncludeModule("pull")) { CPushManager::DeleteFromQueueBySubTag($this->user_id, 'IM_MESS'); CPullStack::AddByUser($this->user_id, Array( 'module_id' => 'im', 'command' => 'readMessage', 'params' => Array( 'chatId' => intval($arRes['CHAT_ID']), 'senderId' => $this->user_id, 'id' => $fromUserId, 'userId' => $fromUserId, 'lastId' => $arRes['ID'], 'count' => $arRes['CNT'] ), )); CPullStack::AddByUser($fromUserId, Array( 'module_id' => 'im', 'command' => 'readMessageApponent', 'params' => Array( 'chatId' => intval($arRes['CHAT_ID']), 'userId' => $this->user_id, 'lastId' => $arRes['ID'], 'date' => time(), 'count' => $arRes['CNT'] ), )); CIMMessenger::SendBadges($this->user_id); } return true; } } return false; }
public static function Invite($arParams) { $arConfig['CHAT_ID'] = intval($arParams['CHAT_ID']); if ($arConfig['CHAT_ID'] <= 0) { return false; } global $DB, $USER; $arConfig['RECIPIENT_ID'] = intval($arParams['RECIPIENT_ID']); $arConfig['USER_ID'] = intval($arParams['USER_ID']) > 0 ? intval($arParams['USER_ID']) : IntVal($USER->GetID()); $arConfig['VIDEO'] = isset($arParams['VIDEO']) && $arParams['VIDEO'] == 'N' ? 'N' : 'Y'; $arChat = CIMChat::GetChatData(array('ID' => $arConfig['CHAT_ID'])); if (empty($arChat['chat'])) { return false; } $arConfig['CALL_TO_GROUP'] = $arChat['chat'][$arConfig['CHAT_ID']]['type'] == IM_MESSAGE_GROUP; $arConfig['STATUS_TYPE'] = intval($arChat['chat'][$arConfig['CHAT_ID']]['call']); if (!$arConfig['CALL_TO_GROUP'] && !IsModuleInstalled('intranet') && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CALL, $arConfig['RECIPIENT_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arConfig['USER_ID'], $arConfig['RECIPIENT_ID'])) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_CALL_PRIVACY'), "ERROR_FROM_PRIVACY"); return false; } if ($arConfig['STATUS_TYPE'] != IM_CALL_NONE) { if ($arConfig['CALL_TO_GROUP']) { self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_START_", $arConfig['USER_ID'], true); } $strSql = "UPDATE b_im_relation SET CALL_STATUS = " . IM_CALL_STATUS_ANSWER . " WHERE CHAT_ID = " . $arConfig['CHAT_ID'] . " AND USER_ID = " . $arConfig['USER_ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $arUserData = CIMContactList::GetUserData(array('ID' => $arChat['userInChat'][$arConfig['CHAT_ID']], 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y')); $arConfig['USER_DATA']['USERS'] = $arUserData['users']; $arConfig['USER_DATA']['HR_PHOTO'] = $arUserData['hrphoto']; foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus) { if ($userId != $arConfig['USER_ID'] && in_array($callStatus, array(IM_CALL_STATUS_WAIT, IM_CALL_STATUS_ANSWER))) { $arUserToConnect[$userId] = $callStatus; } } $arConfig['USERS_CONNECT'] = $arUserToConnect; $arSend['users'] = $arUserData['users']; $arSend['hrphoto'] = $arUserData['hrphoto']; $arSend['video'] = $arConfig['VIDEO'] == 'Y' ? true : false; $arSend['callToGroup'] = $arConfig['CALL_TO_GROUP']; $arSend['chat'] = $arChat['chat']; $arSend['userChatBlockStatus'] = $arChat['userChatBlockStatus']; $arSend['userInChat'] = $arChat['userInChat']; foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus) { if ($userId != $arConfig['USER_ID'] && !in_array($callStatus, array(IM_CALL_STATUS_DECLINE))) { self::Command($arConfig['CHAT_ID'], $userId, 'invite_join', $arSend); } } } else { if ($arConfig['CALL_TO_GROUP']) { self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_INIT_", $arConfig['USER_ID'], true); } $strSql = "UPDATE b_im_chat SET CALL_TYPE = " . ($arConfig['VIDEO'] == 'Y' ? IM_CALL_VIDEO : IM_CALL_AUDIO) . " WHERE ID = " . $arConfig['CHAT_ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $strSql = "UPDATE b_im_relation SET CALL_STATUS = " . IM_CALL_STATUS_ANSWER . " WHERE CHAT_ID = " . $arConfig['CHAT_ID'] . " AND USER_ID = " . $arConfig['USER_ID']; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $arUserToConnect = array(); foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus) { if ($userId != $arConfig['USER_ID']) { $arUserToConnect[$userId] = $callStatus; } } $arUserData = CIMContactList::GetUserData(array('ID' => $arChat['userInChat'][$arConfig['CHAT_ID']], 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y')); $arSend['users'] = $arUserData['users']; $arSend['hrphoto'] = $arUserData['hrphoto']; $arSend['video'] = $arConfig['VIDEO'] == 'Y' ? true : false; $arSend['callToGroup'] = $arConfig['CALL_TO_GROUP']; $arSend['chat'] = $arChat['chat']; $arSend['userChatBlockStatus'] = $arChat['userChatBlockStatus']; $arSend['userInChat'] = $arChat['userInChat']; foreach ($arUserToConnect as $userId => $callStatus) { self::Command($arConfig['CHAT_ID'], $userId, 'invite', $arSend); } $arConfig['USER_DATA']['USERS'] = $arUserData['users']; $arConfig['USER_DATA']['HR_PHOTO'] = $arUserData['hrphoto']; if (!$arConfig['CALL_TO_GROUP'] && CModule::IncludeModule('pull') && CPullOptions::GetPushStatus()) { $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME"); $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => $USER->GetID()), array('FIELDS' => $arSelect)); if ($arUser = $dbUsers->GetNext(true, false)) { $sName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false); $pushText = GetMessage('IM_CALL_INVITE', array('#USER_NAME#' => $sName)); } else { $pushText = GetMessage('IM_CALL_INVITE', array('#USER_NAME#' => GetMessage('IM_CALL_INVITE_NA'))); } $CPushManager = new CPushManager(); foreach ($arUserToConnect as $sendTouserId => $callStatus) { $CPushManager->AddQueue(array('USER_ID' => $sendTouserId, 'MESSAGE' => $pushText, 'EXPIRY' => 0, 'PARAMS' => 'IMINV_' . $USER->GetID() . "_" . time(), 'APP_ID' => 'Bitrix24', 'SOUND' => 'call.aif', 'SEND_IMMEDIATELY' => 'Y')); } } } foreach (GetModuleEvents("im", "OnCallStart", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($arConfig)); } return $arConfig; }
public static function send($eventId, $arParams) { $result = false; if (!isset($arParams["ORDER"]) && isset($arParams["ORDER_ID"])) { $arParams["ORDER"] = CSaleOrder::GetById($arParams["ORDER_ID"]); } if (in_array($eventId, self::$arEvents) && isset($arParams["ORDER"]) && CModule::IncludeModule("pull")) { $arUsers = self::getSubscribers($eventId, $arParams); if (!empty($arUsers)) { $text = self::makeMessage($eventId, $arParams); $title = self::makeTitle($eventId, $arParams); $arMessages = array(); foreach ($arUsers as $userId) { if (!self::checkRights($userId, $eventId, array("ORDER_ID" => $arParams["ORDER"]["ID"]))) { continue; } $arMessages[] = array("USER_ID" => $userId, "TITLE" => $title, "APP_ID" => "BitrixAdmin", "MESSAGE" => $text, "PARAMS" => "sl_" . $arParams["ORDER"]["ID"]); } $pushMe = new CPushManager(); $result = $pushMe->SendMessage($arMessages); } } return $result; }
public static function AddByUsers($userIds, $arMessage, $channelType = 'private') { if (!is_array($userIds)) { return false; } $arPush = array(); if (isset($arMessage['push'])) { $arPush = $arMessage['push']; unset($arMessage['push']); } $channels = array(); foreach ($userIds as $userId) { $userId = intval($userId); if ($userId > 0) { $arChannel = CPullChannel::GetChannel($userId, $channelType); $channels[$userId] = $arChannel['CHANNEL_ID']; } } if (empty($channels)) { return false; } $result = self::AddByChannel($channels, $arMessage); if ($result && !empty($arPush) && (isset($arPush['advanced_params']) || isset($arPush['message']) && strlen($arPush['message']) > 0)) { $CPushManager = new CPushManager(); $pushUsers = array(); foreach ($channels as $userId => $channelId) { if (isset($arPush['skip_users']) && in_array($userId, $arPush['skip_users'])) { continue; } $pushUsers[] = $userId; } $CPushManager->AddQueue(array('USER_ID' => $pushUsers, 'MESSAGE' => str_replace("\n", " ", $arPush['message']), 'PARAMS' => $arPush['params'], 'ADVANCED_PARAMS' => isset($arPush['advanced_params']) ? $arPush['advanced_params'] : array(), 'BADGE' => isset($arPush['badge']) ? intval($arPush['badge']) : '', 'SOUND' => isset($arPush['sound']) ? $arPush['sound'] : '', 'TAG' => isset($arPush['tag']) ? $arPush['tag'] : '', 'SUB_TAG' => isset($arPush['sub_tag']) ? $arPush['sub_tag'] : '', 'APP_ID' => isset($arPush['app_id']) ? $arPush['app_id'] : '', 'SEND_IMMEDIATELY' => isset($arPush['send_immediately']) && $arPush['send_immediately'] == 'Y' ? 'Y' : 'N')); } return $result; }
public function SetReadMessage($chatId, $lastId = null) { global $DB; $chatId = intval($chatId); if ($chatId <= 0) { return false; } $sqlLastId = ''; if (intval($lastId) > 0) { $sqlLastId = "AND M.ID <= " . intval($lastId); } $strSql = "\n\t\t\tSELECT COUNT(M.ID) CNT, MAX(M.ID) ID, M.CHAT_ID\n\t\t\tFROM b_im_message M\n\t\t\tINNER JOIN b_im_relation R1 ON M.ID > R1.LAST_ID " . $sqlLastId . " AND M.CHAT_ID = R1.CHAT_ID\n\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . "\n\t\t\tGROUP BY M.CHAT_ID\n\t\t"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = CIMMessage::SetLastId($chatId, $this->user_id, $arRes['ID']); if ($bReadMessage) { //CUserCounter::Decrement($this->user_id, 'im_chat_v2', '**', false, $arRes['CNT']); CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_GROUP); if (CModule::IncludeModule("pull")) { CPushManager::DeleteFromQueueBySubTag($this->user_id, 'IM_MESS'); CPullStack::AddByUser($this->user_id, array('module_id' => 'im', 'command' => 'readMessageChat', 'params' => array('chatId' => $chatId, 'lastId' => $arRes['ID'], 'count' => $arRes['CNT']))); CIMMessenger::SendBadges($this->user_id); } return true; } } return false; }
public static function DeleteBySubTag($notifySubTag, $authorId = false) { global $DB; if (strlen($notifySubTag) <= 0) { return false; } $sqlUser = ""; $sqlUser2 = ""; if ($authorId !== false) { $sqlUser = "******" . intval($authorId); $sqlUser2 = " AND AUTHOR_ID = " . intval($authorId); } $dbRes = $DB->Query("SELECT R.USER_ID, R.STATUS FROM b_im_relation R, b_im_message M WHERE M.CHAT_ID = R.CHAT_ID AND M.NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $arUsers = array(); while ($row = $dbRes->Fetch()) { $count = $row['STATUS'] < IM_STATUS_READ ? 1 : 0; if (isset($arUsers[$row['USER_ID']])) { $arUsers[$row['USER_ID']] += $count; } else { $arUsers[$row['USER_ID']] = $count; } } $pullActive = false; if (CModule::IncludeModule("pull")) { $pullActive = true; } $arUsersSend = array(); foreach ($arUsers as $userId => $count) { CIMMessenger::SpeedFileDelete($userId, IM_SPEED_NOTIFY); if ($count > 0) { $arUsersSend[] = $userId; //CUserCounter::Decrement($userId, 'im_notify_v2', '**', false); } if ($pullActive) { CPushManager::DeleteFromQueueBySubTag($userId, $notifySubTag); } } $strSql = "DELETE FROM b_im_message WHERE NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser2; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); CIMMessenger::SendBadges($arUsersSend); return true; }