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 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; }
/** * 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 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 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; }
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 static function Add($arFields) { global $DB; if (isset($arFields['TITLE']) && !isset($arFields['NOTIFY_TITLE'])) { $arFields['NOTIFY_TITLE'] = $arFields['TITLE']; } if (isset($arFields['NOTIFY_MESSAGE']) && !isset($arFields['MESSAGE'])) { $arFields['MESSAGE'] = $arFields['NOTIFY_MESSAGE']; } if (isset($arFields['NOTIFY_MESSAGE_OUT']) && !isset($arFields['MESSAGE_OUT'])) { $arFields['MESSAGE_OUT'] = $arFields['NOTIFY_MESSAGE_OUT']; } $bConvert = false; if (isset($arFields['CONVERT']) && $arFields['CONVERT'] == 'Y') { $bConvert = true; } if (!isset($arFields['MESSAGE_OUT'])) { $arFields['MESSAGE_OUT'] = ""; } if (!isset($arFields['MESSAGE_TYPE'])) { $arFields['MESSAGE_TYPE'] = ""; } if (!isset($arFields['NOTIFY_MODULE'])) { $arFields['NOTIFY_MODULE'] = 'im'; } if (!isset($arFields['NOTIFY_EVENT'])) { $arFields['NOTIFY_EVENT'] = 'default'; } if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) { if (!isset($arFields['NOTIFY_TYPE']) && intval($arFields['FROM_USER_ID']) > 0) { $arFields['NOTIFY_TYPE'] = IM_NOTIFY_FROM; } else { if (!isset($arFields['NOTIFY_TYPE'])) { $arFields['NOTIFY_TYPE'] = IM_NOTIFY_SYSTEM; } } } if (isset($arFields['NOTIFY_EMAIL_TEMPLATE']) && !isset($arFields['EMAIL_TEMPLATE'])) { $arFields['EMAIL_TEMPLATE'] = $arFields['NOTIFY_EMAIL_TEMPLATE']; } if (isset($arFields['EMAIL_TEMPLATE']) && strlen(trim($arFields['EMAIL_TEMPLATE'])) > 0) { $arParams['EMAIL_TEMPLATE'] = trim($arFields['EMAIL_TEMPLATE']); } if (!isset($arFields['AUTHOR_ID'])) { $arFields['AUTHOR_ID'] = intval($arFields['FROM_USER_ID']); } foreach (GetModuleEvents("im", "OnBeforeMessageNotifyAdd", true) as $arEvent) { $result = ExecuteModuleEventEx($arEvent, array(&$arFields)); if ($result === false || isset($result['result']) && $result['result'] === false) { if (isset($result['reason'])) { $CBXSanitizer = new CBXSanitizer(); $CBXSanitizer->AddTags(array('a' => array('href', 'style', 'target'), 'b' => array(), 'u' => array(), 'i' => array(), 'br' => array(), 'span' => array('style'))); $reason = $CBXSanitizer->SanitizeHtml($result['reason']); } else { $reason = $arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE ? GetMessage("IM_ERROR_MESSAGE_CANCELED") : ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_GROUP ? GetMessage("IM_ERROR_GROUP_CANCELED") : GetMessage("IM_ERROR_NOTIFY_CANCELED")); } $GLOBALS["APPLICATION"]->ThrowException($reason, "ERROR_FROM_OTHER_MODULE"); return false; } } if (!self::CheckFields($arFields)) { return false; } if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) { $arFields['FROM_USER_ID'] = intval($arFields['FROM_USER_ID']); $arFields['TO_USER_ID'] = intval($arFields['TO_USER_ID']); $chatId = 0; $strSql = "\n\t\t\t\tSELECT RF.CHAT_ID\n\t\t\t\tFROM\n\t\t\t\t\tb_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\tWHERE\n\t\t\t\t\tRF.USER_ID = " . $arFields['FROM_USER_ID'] . "\n\t\t\t\tand RT.USER_ID = " . $arFields['TO_USER_ID'] . "\n\t\t\t\tand RF.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "'\n\t\t\t"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $chatId = intval($arRes['CHAT_ID']); } else { $chatId = IntVal($DB->Add("b_im_chat", array('AUTHOR_ID' => $arFields['AUTHOR_ID']), array())); if ($chatId <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID"); return false; } $strSql = "INSERT INTO b_im_relation (CHAT_ID, MESSAGE_TYPE, USER_ID, STATUS) VALUES (" . $chatId . ",'" . IM_MESSAGE_PRIVATE . "'," . $arFields['FROM_USER_ID'] . ", " . ($bConvert ? 2 : 0) . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $strSql = "INSERT INTO b_im_relation (CHAT_ID, MESSAGE_TYPE, USER_ID, STATUS) VALUES (" . $chatId . ",'" . IM_MESSAGE_PRIVATE . "'," . $arFields['TO_USER_ID'] . ", " . ($bConvert ? 2 : 0) . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } if ($chatId > 0) { $arParams = array(); $arParams['CHAT_ID'] = $chatId; $arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']); $arParams['MESSAGE'] = trim($arFields['MESSAGE']); $arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']); $arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE']; $arParams['NOTIFY_EVENT'] = 'private'; if (isset($arFields['IMPORT_ID'])) { $arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']); } if (isset($arFields['MESSAGE_DATE'])) { $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE']; } else { $arParams['~DATE_CREATE'] = $DB->CurrentTimeFunction(); } $messageID = IntVal($DB->Add("b_im_message", $arParams, array('MESSAGE', 'MESSAGE_OUT'))); CIMContactList::SetRecent($arFields['TO_USER_ID'], $messageID, false, $arFields['FROM_USER_ID']); CIMContactList::UpdateRecent($arFields['FROM_USER_ID'], $messageID, false, $arFields['TO_USER_ID']); if (!$bConvert) { if (CModule::IncludeModule("pull")) { $arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID']; $arParams['TO_USER_ID'] = $arFields['TO_USER_ID']; $pushText = ''; if (CPullOptions::GetPushStatus()) { $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME"); $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => $arParams['FROM_USER_ID']), array('FIELDS' => $arSelect)); if ($arUser = $dbUsers->GetNext(true, false)) { $sName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false); $pushText = $sName . ': ' . $arParams['MESSAGE']; } } $arPullTo = array('module_id' => 'im', 'command' => 'message', 'params' => CIMMessage::GetFormatMessage(array('ID' => $messageID, 'TO_USER_ID' => $arParams['TO_USER_ID'], 'FROM_USER_ID' => $arParams['FROM_USER_ID'], 'MESSAGE' => $arParams['MESSAGE'], 'DATE_CREATE' => time())), 'push_params' => 'IM_MESS_' . $arParams['FROM_USER_ID'], 'push_tag' => 'IM_MESS_' . $arParams['FROM_USER_ID'], 'push_text' => $pushText); $arPullFrom = $arPullTo; unset($arPullFrom['push_text']); CPullStack::AddByUser($arParams['TO_USER_ID'], $arPullTo); CPullStack::AddByUser($arParams['FROM_USER_ID'], $arPullFrom); } $strSql = "\n\t\t\t\t\t\tUPDATE b_im_relation SET STATUS = '" . IM_STATUS_UNREAD . "'\n\t\t\t\t\t\tWHERE USER_ID = " . $arFields['TO_USER_ID'] . " AND MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "' AND CHAT_ID = " . $chatId; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); foreach (GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields)); } } return $messageID; } else { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID"); return false; } } else { if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_GROUP) { $chatId = 0; $systemMessage = false; if (isset($arFields['SYSTEM']) && $arFields['SYSTEM'] == 'Y' && intval($arFields['FROM_USER_ID']) <= 0) { $strSql = "\n\t\t\t\t\tSELECT C.ID CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID\n\t\t\t\t\tFROM b_im_chat C\n\t\t\t\t\tWHERE C.ID = " . intval($arFields['TO_CHAT_ID']) . "\n\t\t\t\t"; $systemMessage = true; } else { $strSql = "\n\t\t\t\t\tSELECT R.CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID\n\t\t\t\t\tFROM b_im_relation R LEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID\n\t\t\t\t\tWHERE R.USER_ID = " . intval($arFields['FROM_USER_ID']) . " AND R.MESSAGE_TYPE = '" . IM_MESSAGE_GROUP . "' AND R.CHAT_ID = " . intval($arFields['TO_CHAT_ID']) . "\n\t\t\t\t"; } $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $chatId = intval($arRes['CHAT_ID']); $chatTitle = htmlspecialcharsbx($arRes['CHAT_TITLE']); $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']); } else { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED"); return false; } if ($chatId > 0) { $arParams = array(); $arParams['CHAT_ID'] = $chatId; $arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']); $arParams['MESSAGE'] = trim($arFields['MESSAGE']); $arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']); $arParams['NOTIFY_MODULE'] = 'im'; $arParams['NOTIFY_EVENT'] = 'group'; if (isset($arFields['MESSAGE_DATE'])) { $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE']; } else { $arParams['~DATE_CREATE'] = $DB->CurrentTimeFunction(); } $messageID = IntVal($DB->Add("b_im_message", $arParams, array('MESSAGE', 'MESSAGE_OUT'))); //if(!$systemMessage) CIMContactList::SetRecent($chatId, $messageID, true, $arFields['FROM_USER_ID']); CIMContactList::UpdateRecent($chatId, $messageID, true); if (CModule::IncludeModule("pull")) { $arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID']; $arParams['TO_CHAT_ID'] = $arFields['TO_CHAT_ID']; $arPullTo = array('module_id' => 'im', 'command' => 'messageChat', 'params' => CIMMessage::GetFormatMessage(array('ID' => $messageID, 'TO_CHAT_ID' => $arParams['TO_CHAT_ID'], 'FROM_USER_ID' => $arParams['FROM_USER_ID'], 'MESSAGE' => $arParams['MESSAGE'], 'DATE_CREATE' => time()))); $arPullFrom = $arPullTo; unset($arPullFrom['push_text']); CPullStack::AddByUser($arParams['FROM_USER_ID'], $arPullFrom); $arRel = CIMChat::GetRelationById($chatId); foreach ($arRel as $rel) { if ($rel['USER_ID'] != $arParams['FROM_USER_ID']) { CPullStack::AddByUser($rel['USER_ID'], $arPullTo); } } } if (!$systemMessage) { $strSql = "\n\t\t\t\t\t\tUPDATE b_im_relation SET STATUS = '" . IM_STATUS_UNREAD . "'\n\t\t\t\t\t\tWHERE USER_ID <> " . $arFields['FROM_USER_ID'] . " AND MESSAGE_TYPE = '" . IM_MESSAGE_GROUP . "' AND CHAT_ID = " . $chatId; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } foreach (GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields)); } return $messageID; } else { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID"); return false; } } else { if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) { $chatId = 0; $strSql = "\n\t\t\t\tSELECT CHAT_ID\n\t\t\t\tFROM b_im_relation\n\t\t\t\tWHERE USER_ID = " . intval($arFields['TO_USER_ID']) . " AND MESSAGE_TYPE = '" . IM_MESSAGE_SYSTEM . "'"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $chatId = intval($arRes['CHAT_ID']); } else { $chatId = IntVal($DB->Add("b_im_chat", array('AUTHOR_ID' => intval($arFields['TO_USER_ID'])), array())); if ($chatId <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID"); return false; } $strSql = "INSERT INTO b_im_relation (CHAT_ID, MESSAGE_TYPE, USER_ID, STATUS) VALUES (" . $chatId . ",'" . IM_MESSAGE_SYSTEM . "'," . intval($arFields['TO_USER_ID']) . ", " . ($bConvert ? 2 : 0) . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } if ($chatId > 0) { $arParams = array(); $arParams['CHAT_ID'] = $chatId; $arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']); $arParams['MESSAGE'] = trim($arFields['MESSAGE']); $arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']); $arParams['NOTIFY_TYPE'] = intval($arFields['NOTIFY_TYPE']); $arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE']; $arParams['NOTIFY_EVENT'] = $arFields['NOTIFY_EVENT']; if (isset($arFields['IMPORT_ID'])) { $arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']); } if (isset($arFields['MESSAGE_DATE'])) { $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE']; } else { $arParams['~DATE_CREATE'] = $DB->CurrentTimeFunction(); } if (isset($arFields['EMAIL_TEMPLATE']) && strlen(trim($arFields['EMAIL_TEMPLATE'])) > 0) { $arParams['EMAIL_TEMPLATE'] = trim($arFields['EMAIL_TEMPLATE']); } if (isset($arFields['NOTIFY_TAG'])) { $arParams['NOTIFY_TAG'] = $arFields['NOTIFY_TAG']; } if (isset($arFields['NOTIFY_SUB_TAG'])) { $arParams['NOTIFY_SUB_TAG'] = $arFields['NOTIFY_SUB_TAG']; } if (isset($arFields['NOTIFY_TITLE']) && strlen(trim($arFields['NOTIFY_TITLE'])) > 0) { $arParams['NOTIFY_TITLE'] = trim($arFields['NOTIFY_TITLE']); } if ($arParams['NOTIFY_TYPE'] == IM_NOTIFY_CONFIRM) { if (isset($arFields['NOTIFY_BUTTONS'])) { foreach ($arFields['NOTIFY_BUTTONS'] as $key => $arButtons) { if (is_array($arButtons)) { if (isset($arButtons['TITLE']) && strlen($arButtons['TITLE']) > 0 && isset($arButtons['VALUE']) && strlen($arButtons['VALUE']) > 0 && isset($arButtons['TYPE']) && strlen($arButtons['TYPE']) > 0) { $arButtons['TITLE'] = htmlspecialcharsbx($arButtons['TITLE']); $arButtons['VALUE'] = htmlspecialcharsbx($arButtons['VALUE']); $arButtons['TYPE'] = htmlspecialcharsbx($arButtons['TYPE']); $arFields['NOTIFY_BUTTONS'][$key] = $arButtons; } else { unset($arFields['NOTIFY_BUTTONS'][$key]); } } else { unset($arFields['NOTIFY_BUTTONS'][$key]); } } } else { $arFields['NOTIFY_BUTTONS'] = array(array('TITLE' => GetMessage('IM_ERROR_BUTTON_ACCEPT'), 'VALUE' => 'Y', 'TYPE' => 'accept'), array('TITLE' => GetMessage('IM_ERROR_BUTTON_CANCEL'), 'VALUE' => 'N', 'TYPE' => 'cancel')); } $arParams['NOTIFY_BUTTONS'] = serialize($arFields["NOTIFY_BUTTONS"]); if (isset($arParams['NOTIFY_TAG']) && strlen($arParams['NOTIFY_TAG']) > 0) { CIMNotify::DeleteByTag($arParams['NOTIFY_TAG']); } } $messageID = IntVal($DB->Add("b_im_message", $arParams, array('MESSAGE', 'MESSAGE_OUT', 'NOTIFY_BUTTONS'))); CIMMessenger::SpeedFileDelete(intval($arFields['TO_USER_ID']), IM_SPEED_NOTIFY); if (!$bConvert) { if (CModule::IncludeModule("pull")) { CPullStack::AddByUser(intval($arFields['TO_USER_ID']), array('module_id' => 'im', 'command' => 'notify', 'params' => CIMNotify::GetFormatNotify(array('ID' => $messageID, 'TIMESTAMP' => time(), 'FROM_USER_ID' => intval($arFields['FROM_USER_ID']), 'MESSAGE' => $arParams['MESSAGE'], 'NOTIFY_TAG' => $arParams['NOTIFY_TAG'], 'NOTIFY_TYPE' => $arParams['NOTIFY_TYPE'], 'NOTIFY_BUTTONS' => isset($arParams['NOTIFY_BUTTONS']) ? $arParams['NOTIFY_BUTTONS'] : serialize(array()), 'NOTIFY_TITLE' => isset($arParams['NOTIFY_TITLE']) ? $arParams['NOTIFY_TITLE'] : '')))); } $strSql = "\n\t\t\t\t\t\tUPDATE b_im_relation SET STATUS = '" . IM_STATUS_UNREAD . "'\n\t\t\t\t\t\tWHERE USER_ID = " . intval($arFields['TO_USER_ID']) . " AND MESSAGE_TYPE = '" . IM_MESSAGE_SYSTEM . "' AND CHAT_ID = " . $chatId; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); foreach (GetModuleEvents("im", "OnAfterNotifyAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields)); } } return $messageID; } else { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID"); return false; } } else { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_TYPE"), "MESSAGE_TYPE"); return false; } } } return false; }
<td><input id="config_path_to_listener" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetListenUrl())?>" name="path_to_listener" <?=(CPullOptions::GetNginxStatus()? '':'disabled="true"')?>></td> </tr> <?/* <tr> <td width="40%"><nobr><?=GetMessage("PULL_OPTIONS_WEBSOCKET")?></nobr>:</td> <td width="60%"><input id="config_websocket" type="checkbox" size="40" value="Y" <?=(CPullOptions::GetWebSocketStatus()?' checked':'')?> name="websocket" <?=(CPullOptions::GetNginxStatus()? '':'disabled="true"')?>></td> </tr> <tr> <td ><?=GetMessage("PULL_OPTIONS_PATH_TO_WEBSOCKET")?>:</td> <td><input id="config_path_to_websocket" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetWebSocketUrl())?>" name="path_to_websocket" <?=(!CPullOptions::GetNginxStatus() || !CPullOptions::GetWebSocketStatus() ? 'disabled="true"': '')?></td> </tr> */?> <?if (IsModuleInstalled('mobileapp')):?> <tr> <td align="right" width="50%"><?=GetMessage("PULL_OPTIONS_PUSH")?>:</td> <td><input type="checkbox" size="40" value="Y" <?=(CPullOptions::GetPushStatus()?' checked':'')?> name="push"></td> </tr> <?endif;?> <?$tabControl->Buttons();?> <script language="JavaScript"> BX.bind(BX('config_nginx'), 'change', function(){ if (this.checked) { if (confirm("<?=GetMessageJS("PULL_OPTIONS_NGINX_CONFIRM")?>")) { BX('config_path_to_publish').disabled = false; BX('config_path_to_listener').disabled = false; BX('config_path_to_websocket').disabled = false; BX('config_websocket').disabled = false; BX('config_websocket').checked = true; }
</td> </tr> <?php } ?> <tr> <td width="40%"></td> <td width="60%"></td> </tr> <tr> <td align="right" width="50%"><?php echo GetMessage("PULL_OPTIONS_PUSH"); ?> :</td> <td><input type="checkbox" size="40" value="Y" <?php echo CPullOptions::GetPushStatus() ? ' checked' : ''; ?> name="push"></td> </tr> <tr> <td width="40%"></td> <td width="60%"></td> </tr> <tr> <td width="40%"><nobr><?php echo GetMessage("PULL_OPTIONS_NGINX"); ?> </nobr>:</td> <td width="60%"><input id="config_nginx" type="checkbox" size="40" value="Y" <?php echo CPullOptions::GetQueueServerStatus() ? ' checked' : ''; ?>
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); }