public function SendUnreadMessages($receiverJId, $domain = "") { $receiverJId = trim($receiverJId); if (strlen($receiverJId) <= 0) { return false; } $receiver = CXMPPUtility::GetUserByJId($receiverJId, $domain); if (!$receiver) { return false; } $factory = CXMPPFactory::GetFactory(); if (IsModuleInstalled("im") && CModule::IncludeModule("im")) { $CIMMessage = new CIMMessage($receiverJId, array('hide_link' => true)); $arMessage = $CIMMessage->GetUnreadMessage(array('SPEED_CHECK' => 'N', 'ORDER' => 'ASC', 'USE_SMILES' => 'N', 'USER_LOAD' => 'N', 'LOAD_DEPARTMENT' => 'N')); if ($arMessage['result']) { foreach ($arMessage['message'] as $id => $arMessage) { $factory->__SendMessage($arMessage["senderId"], $arMessage["recipientId"], $arMessage["id"], IM_MESSAGE_PRIVATE, htmlspecialcharsbx(CTextParser::convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", $arMessage["text"]))), $domain); } } // Notify $CIMNotify = new CIMNotify($receiverJId); $arNotify = $CIMNotify->GetUnreadNotify(array('SPEED_CHECK' => 'N', 'ORDER' => 'ASC')); if ($arNotify['result']) { foreach ($arNotify['original_notify'] as $id => $arNotify) { if (isset($arNotify["NOTIFY_MODULE"]) && isset($arNotify["NOTIFY_EVENT"]) && !CIMSettings::GetNotifyAccess($arNotify["TO_USER_ID"], $arNotify["NOTIFY_MODULE"], $arNotify["NOTIFY_EVENT"], CIMSettings::CLIENT_XMPP)) { continue; } if ($arNotify["MESSAGE_OUT"] == IM_MAIL_SKIP) { $arNotify["MESSAGE_OUT"] = ''; } $factory->__SendMessage($arNotify["FROM_USER_ID"], $arNotify["TO_USER_ID"], $arNotify["ID"], IM_MESSAGE_SYSTEM, htmlspecialcharsbx(CTextParser::convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", strlen($arNotify["MESSAGE_OUT"]) > 0 ? $arNotify["MESSAGE_OUT"] : $arNotify["MESSAGE"]))), $domain); } } } else { $parser = new CSocNetTextParser(); $dbMessages = CSocNetMessages::GetList(array("DATE_CREATE" => "ASC"), array("TO_USER_ID" => $receiver["ID"], "DATE_VIEW" => "", "TO_DELETED" => "N", "IS_LOG_ALL" => "Y"), false, false, array("ID", "FROM_USER_ID", "TO_USER_ID", "MESSAGE", "DATE_VIEW", "MESSAGE_TYPE", "FROM_DELETED", "TO_DELETED", "IS_LOG")); while ($arMessage = $dbMessages->Fetch()) { $factory->__SendMessage($arMessage["IS_LOG"] == "Y" ? -5 : $arMessage["FROM_USER_ID"], $arMessage["TO_USER_ID"], $arMessage["ID"], $arMessage["MESSAGE_TYPE"], htmlspecialcharsbx($parser->convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", $arMessage["MESSAGE"]))), $domain); } } return true; }
public static function SearchUsers($searchText) { $searchText = trim($searchText); if (strlen($searchText) <= 3) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_CL_SEARCH_EMPTY"), "ERROR_SEARCH_EMPTY"); return false; } $nameTemplate = COption::GetOptionString("im", "user_name_template", "#LAST_NAME# #NAME#", SITE_ID); $nameTemplateSite = CSite::GetNameFormat(false); $arFilter = array( "ACTIVE" => "Y", "NAME_SEARCH" => $searchText, ); $arSettings = CIMSettings::GetDefaultSettings(CIMSettings::SETTINGS); if ($arSettings[CIMSettings::PRIVACY_SEARCH] == CIMSettings::PRIVACY_RESULT_ALL) $arFilter['?UF_IM_SEARCH'] = "~".CIMSettings::PRIVACY_RESULT_CONTACT; else $arFilter['UF_IM_SEARCH'] = CIMSettings::PRIVACY_RESULT_ALL; $arExtParams = Array('FIELDS' => Array("ID", "LAST_NAME", "NAME", "SECOND_NAME", "LOGIN", "PERSONAL_PHOTO", "PERSONAL_BIRTHDAY", "IS_ONLINE"), 'SELECT' => Array('UF_IM_SEARCH')); $dbUsers = CUser::GetList(($sort_by = Array('last_name'=>'asc')), ($dummy=''), $arFilter, $arExtParams); while ($arUser = $dbUsers->GetNext(true, false)) { $arFileTmp = CFile::ResizeImageGet( $arUser["PERSONAL_PHOTO"], array('width' => 58, 'height' => 58), BX_RESIZE_IMAGE_EXACT, false ); $arUsers[$arUser["ID"]] = Array( 'id' => $arUser["ID"], 'select' => $arUser['UF_IM_SEARCH'], 'name' => CUser::FormatName($nameTemplateSite, $arUser, true, false), 'nameList' => CUser::FormatName($nameTemplate, $arUser, true, false), 'avatar' => empty($arFileTmp['src'])? '/bitrix/js/im/images/blank.gif': $arFileTmp['src'], 'status' => $arUser['IS_ONLINE'] == 'Y'? 'online': 'offline', 'profile' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('im', 'path_to_user_profile', "", CModule::IncludeModule('extranet') && !CExtranet::IsIntranetUser()? "ex": false), array("user_id" => $arUser["ID"])) ); } return Array('users' => $arUsers); }
public function AddUser($chatId, $userId) { global $DB; $chatId = intval($chatId); if ($chatId <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_CHAT_ID"), "EMPTY_CHAT_ID"); return false; } $arUserId = array(); if (is_array($userId)) { $arUserId = \CIMContactList::PrepareUserIds($userId); } else { if (intval($userId) > 0) { $arUserId[intval($userId)] = intval($userId); } } if ($this->user_id > 0) { $arUserId[$this->user_id] = $this->user_id; } if (count($arUserId) <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID"), "EMPTY_USER_ID"); return false; } if ($this->user_id > 0 && !IsModuleInstalled('intranet') && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) { $arFriendUsers = array(); $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $this->user_id, "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID", "DATE_CREATE", "DATE_UPDATE", "INITIATED_BY")); while ($arFriends = $dbFriends->Fetch()) { $friendId = $this->user_id == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"]; $arFriendUsers[$friendId] = $friendId; } foreach ($arUserId as $id => $userId) { if ($userId == $this->user_id) { continue; } if (!isset($arFriendUsers[$userId]) && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CHAT, $userId) == CIMSettings::PRIVACY_RESULT_CONTACT) { unset($arUserId[$id]); } } if (count($arUserId) <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID_BY_PRIVACY"), "EMPTY_USER_ID_BY_PRIVACY"); return false; } } $strSql = "\n\t\t\tSELECT\n\t\t\t\tR.CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID, C.EXTRANET CHAT_EXTRANET, C.TYPE CHAT_TYPE\n\t\t\tFROM b_im_relation R\n\t\t\tLEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID\n\t\t\tWHERE\n\t\t\t\t" . ($this->user_id > 0 ? "R.USER_ID = " . $this->user_id . " AND " : "") . "\n\t\t\t\tR.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "')\n\t\t\t\tAND R.CHAT_ID = " . $chatId . "\n\t\t"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $extranetFlag = $arRes["CHAT_EXTRANET"] == "" ? "" : ($arRes["CHAT_EXTRANET"] == "Y" ? true : false); $chatTitle = $arRes['CHAT_TITLE']; $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']); $chatType = intval($arRes['CHAT_TYPE']); $arRelation = self::GetRelationById($chatId); $arExistUser = array(); foreach ($arRelation as $relation) { $arExistUser[] = $relation['USER_ID']; } if (count($arRelation) + count($arUserId) > 500) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MAX_USER", array('#COUNT#' => 500)), "MAX_USER"); return false; } $arUserId = array_diff($arUserId, $arExistUser); if (empty($arUserId)) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_NOTHING_TO_ADD"), "NOTHING_TO_ADD"); return false; } $arUserSelect = $arUserId; if ($this->user_id > 0) { $arUserSelect[] = $this->user_id; } $arUsers = CIMContactList::GetUserData(array('ID' => array_values($arUserSelect), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'N')); $arUsers = $arUsers['users']; if ($extranetFlag !== true) { $isExtranet = false; foreach ($arUsers as $userData) { if ($userData['extranet']) { $isExtranet = true; break; } } if ($isExtranet || $extranetFlag === "") { IM\ChatTable::update($chatId, array('EXTRANET' => $isExtranet ? "Y" : "N")); } $extranetFlag = $isExtranet; } $arUsersName = array(); foreach ($arUserId as $userId) { $arUsersName[] = htmlspecialcharsback($arUsers[$userId]['name']); } if ($this->user_id > 0) { $message = GetMessage("IM_CHAT_JOIN_" . $arUsers[$this->user_id]['gender'], array('#USER_1_NAME#' => htmlspecialcharsback($arUsers[$this->user_id]['name']), '#USER_2_NAME#' => implode(', ', $arUsersName))); } else { if (count($arUsersName) > 1) { $message = GetMessage("IM_CHAT_SELF_JOIN", array('#USERS_NAME#' => implode(', ', $arUsersName))); } else { $arUserList = array_values($arUserId); $message = GetMessage("IM_CHAT_SELF_JOIN_" . $arUsers[$arUserList[0]]['gender'], array('#USER_NAME#' => implode(', ', $arUsersName))); } } $fileMaxId = CIMDisk::GetMaxFileId($chatId); $maxId = 0; $strSql = "SELECT MAX(ID) ID FROM b_im_message WHERE CHAT_ID = " . $chatId . " GROUP BY CHAT_ID"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arMax = $dbRes->Fetch()) { $maxId = $arMax['ID']; } $update = array(); $publicPullWatch = false; if ($chatType == IM_MESSAGE_OPEN && CModule::IncludeModule("pull")) { $publicPullWatch = true; } foreach ($arUserId as $userId) { if ($publicPullWatch) { CPullWatch::Delete($userId, 'IM_PUBLIC_' . $chatId); } CIMContactList::SetRecent(array('ENTITY_ID' => $chatId, 'MESSAGE_ID' => $maxId, 'CHAT_TYPE' => $arRes['CHAT_TYPE'], 'USER_ID' => $userId)); $hideHistory = CIMSettings::GetStartChatMessage() == CIMSettings::START_MESSAGE_LAST && $arRes['CHAT_TYPE'] == IM_MESSAGE_CHAT; if ($arRes['CHAT_TYPE'] != IM_MESSAGE_PRIVATE && $arUsers[$userId]['extranet']) { $hideHistory = true; } $orm = IM\RelationTable::add(array("CHAT_ID" => $chatId, "MESSAGE_TYPE" => $arRes['CHAT_TYPE'], "USER_ID" => $userId, "START_ID" => $hideHistory ? $maxId + 1 : 0, "LAST_ID" => $maxId, "LAST_SEND_ID" => $maxId, "LAST_FILE_ID" => $hideHistory ? $fileMaxId : 0)); $update[] = $orm->getId(); CIMContactList::CleanChatCache($userId); } CIMDisk::ChangeFolderMembers($chatId, $arUserId); if (CModule::IncludeModule("pull")) { foreach ($arRelation as $ar) { CPullStack::AddByUser($ar['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserAdd', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'chatOwner' => $chatAuthorId, 'chatExtranet' => $extranetFlag, 'users' => $arUsers, 'newUsers' => $arUserId))); } } $lastId = self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y')); if (IsModuleInstalled('replica')) { if ($lastId && CIMSettings::GetStartChatMessage() == CIMSettings::START_MESSAGE_LAST && $arRes['CHAT_TYPE'] == IM_MESSAGE_CHAT) { foreach ($update as $relId) { IM\RelationTable::update($relId, array('START_ID' => $lastId)); } } } return true; } $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_AUTHORIZE_ERROR"), "AUTHORIZE_ERROR"); return false; }
public static function GetSettings($userId = false) { $arSettings = CIMSettings::Get($userId); return $arSettings['settings']; }
public static function GetPrivacy($type, $userId = false) { $ar = CIMSettings::Get($userId); return array_key_exists($type, $ar[CIMSettings::SETTINGS]) ? $ar[CIMSettings::SETTINGS][$type] : false; }
public function AddUser($chatId, $userId) { global $DB; $chatId = intval($chatId); if ($chatId <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_CHAT_ID"), "EMPTY_CHAT_ID"); return false; } $arUserId = array(); if (is_array($userId)) { foreach ($userId as $value) { $arUserId[] = intval($value); } } else { $arUserId[] = intval($userId); } if (count($arUserId) <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID"), "EMPTY_USER_ID"); return false; } if (!IsModuleInstalled('intranet') && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) { global $USER; $arFriendUsers = array(); $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $USER->GetID(), "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID", "DATE_CREATE", "DATE_UPDATE", "INITIATED_BY")); while ($arFriends = $dbFriends->Fetch()) { $friendId = $USER->GetID() == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"]; $arFriendUsers[$friendId] = $friendId; } foreach ($arUserId as $id => $userId) { if ($userId == $USER->GetID()) { continue; } if (!isset($arFriendUsers[$userId]) && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CHAT, $userId) == CIMSettings::PRIVACY_RESULT_CONTACT) { unset($arUserId[$id]); } } if (count($arUserId) <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID_BY_PRIVACY"), "EMPTY_USER_ID_BY_PRIVACY"); return false; } } $strSql = "\n\t\t\tSELECT R.CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID\n\t\t\tFROM b_im_relation R LEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID\n\t\t\tWHERE R.USER_ID = " . $this->user_id . " AND R.MESSAGE_TYPE = '" . IM_MESSAGE_GROUP . "' AND R.CHAT_ID = " . $chatId; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $chatTitle = $arRes['CHAT_TITLE']; $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']); $arRelation = self::GetRelationById($chatId); $arExistUser = array(); foreach ($arRelation as $relation) { $arExistUser[] = $relation['USER_ID']; } if (count($arRelation) + count($arUserId) > 100) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MAX_USER", array('#COUNT#' => 100)), "MAX_USER"); return false; } $arUserId = array_diff($arUserId, $arExistUser); if (empty($arUserId)) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_NOTHING_TO_ADD"), "NOTHING_TO_ADD"); return false; } $arUserSelect = $arUserId; $arUserSelect[] = $this->user_id; $arUsers = CIMContactList::GetUserData(array('ID' => array_values($arUserSelect), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'N')); $arUsers = $arUsers['users']; $maxId = 0; $strSql = "SELECT MAX(ID) ID FROM b_im_message WHERE CHAT_ID = " . $chatId . " GROUP BY CHAT_ID"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $maxId = $arRes['ID']; } $fileMaxId = CIMDisk::GetMaxFileId($chatId); $arUsersName = array(); foreach ($arUserId as $userId) { $arUsersName[] = htmlspecialcharsback($arUsers[$userId]['name']); CIMContactList::SetRecent($chatId, $maxId, true, $userId); $strSql = "INSERT INTO b_im_relation (CHAT_ID, MESSAGE_TYPE, USER_ID, START_ID, LAST_ID, LAST_SEND_ID, LAST_FILE_ID) VALUES (" . $chatId . ",'" . IM_MESSAGE_GROUP . "'," . $userId . "," . ($maxId + 1) . "," . $maxId . "," . $maxId . ", " . $fileMaxId . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); CIMContactList::CleanChatCache($userId); } CIMDisk::ChangeFolderMembers($chatId, $arUserId); $message = GetMessage("IM_CHAT_JOIN_" . $arUsers[$this->user_id]['gender'], array('#USER_1_NAME#' => htmlspecialcharsback($arUsers[$this->user_id]['name']), '#USER_2_NAME#' => implode(', ', $arUsersName))); if (CModule::IncludeModule("pull")) { foreach ($arRelation as $ar) { CPullStack::AddByUser($ar['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserAdd', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'chatOwner' => $chatAuthorId, 'users' => $arUsers, 'newUsers' => $arUserId))); } } self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y')); return true; } $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_AUTHORIZE_ERROR"), "AUTHORIZE_ERROR"); 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['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['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']; } foreach(GetModuleEvents("im", "OnCallStart", true) as $arEvent) ExecuteModuleEventEx($arEvent, array($arConfig)); return $arConfig; }
<form method="post" action="<?php echo $APPLICATION->GetCurPage(); ?> ?mid=<?php echo htmlspecialcharsbx($mid); ?> &lang=<?php echo LANG; ?> "> <?php echo bitrix_sessid_post(); $tabControl->Begin(); $tabControl->BeginNextTab(); $selfVideoServer = COption::GetOptionString("im", "turn_server_self") == 'Y' ? true : false; $arSettingsDefault = CIMSettings::GetDefaultSettings(CIMSettings::SETTINGS); if ($arSettingsDefault['panelPositionVertical'] == 'top' && $arSettingsDefault['panelPositionHorizontal'] == 'left') { $arSettingsDefault['location'] = 'TL'; } else { if ($arSettingsDefault['panelPositionVertical'] == 'top' && $arSettingsDefault['panelPositionHorizontal'] == 'right') { $arSettingsDefault['location'] = 'TR'; } else { if ($arSettingsDefault['panelPositionVertical'] == 'top' && $arSettingsDefault['panelPositionHorizontal'] == 'center') { $arSettingsDefault['location'] = 'TC'; } else { if ($arSettingsDefault['panelPositionVertical'] == 'bottom' && $arSettingsDefault['panelPositionHorizontal'] == 'left') { $arSettingsDefault['location'] = 'BL'; } else { if ($arSettingsDefault['panelPositionVertical'] == 'bottom' && $arSettingsDefault['panelPositionHorizontal'] == 'right') { $arSettingsDefault['location'] = 'BR'; } else {
/** * 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)); } } } } }
$arSettings = CIMSettings::Get(); $arNotifyNames = CIMSettings::GetNotifyNames(); echo CUtil::PhpToJsObject(Array( 'NAMES' => $arNotifyNames, 'VALUES' => $arSettings['notify'], 'ERROR' => $errorMessage )); } else if ($_POST['IM_SETTINGS_SIMPLE_NOTIFY_LOAD'] == 'Y') { $errorMessage = ""; $arNotifyNames = CIMSettings::GetNotifyNames(); $arNotifyValues = CIMSettings::GetSimpleNotifyBlocked(true); echo CUtil::PhpToJsObject(Array( 'NAMES' => $arNotifyNames, 'VALUES' => $arNotifyValues, 'ERROR' => $errorMessage )); } else { echo CUtil::PhpToJsObject(Array('ERROR' => 'UNKNOWN_ERROR')); } } else { echo CUtil::PhpToJsObject(Array(
static function AllowToSend($arParams) { $bResult = false; if (isset($arParams['TO_USER_ID'])) { global $USER; $toUserId = intval($arParams['TO_USER_ID']); $bResult = true; if (IsModuleInstalled('intranet') && CModule::IncludeModule('extranet') && !CExtranet::IsIntranetUser()) { $bResult = false; if (CModule::IncludeModule("socialnetwork")) { global $USER, $CACHE_MANAGER; if (defined("BX_COMP_MANAGED_CACHE")) { $ttl = 2592000; } else { $ttl = 600; } $cache_id = 'im_user_sg_' . $USER->GetID(); $obSGCache = new CPHPCache(); $cache_dir = '/bx/imc/sonet'; if ($obSGCache->InitCache($ttl, $cache_id, $cache_dir)) { $tmpVal = $obSGCache->GetVars(); $bResult = in_array($toUserId, $tmpVal['EXTRANET_USERS']); } else { if (defined("BX_COMP_MANAGED_CACHE")) { $CACHE_MANAGER->StartTagCache($cache_dir); } $dbUsersInGroup = CSocNetUserToGroup::GetList(array(), array("USER_ID" => $USER->GetID(), "<=ROLE" => SONET_ROLES_USER, "GROUP_SITE_ID" => CExtranet::GetExtranetSiteID(), "GROUP_ACTIVE" => "Y", "GROUP_CLOSED" => "N"), false, false, array("ID", "GROUP_ID", "GROUP_NAME")); $arUserSocNetGroups = array(); $arUserSG = array(); while ($ar = $dbUsersInGroup->GetNext(true, false)) { $arUserSocNetGroups[] = $ar["GROUP_ID"]; $arUserSG['SG' . $ar['GROUP_ID']] = array('id' => 'SG' . $ar['GROUP_ID'], 'status' => 'close', 'name' => GetMessage('IM_CL_GROUP_SG') . $ar['GROUP_NAME']); if (defined("BX_COMP_MANAGED_CACHE")) { $CACHE_MANAGER->RegisterTag('sonet_group_' . $ar['GROUP_ID']); $CACHE_MANAGER->RegisterTag('sonet_user2group_G' . $ar['GROUP_ID']); } } $arExtranetUsers = array(); $arUserInGroup = array(); $arWoUserInGroup = array(); if (count($arUserSocNetGroups) > 0) { $dbUsersInGroup = CSocNetUserToGroup::GetList(array(), array("GROUP_ID" => $arUserSocNetGroups, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y", "USER_CONFIRM_CODE" => false), false, false, array("ID", "USER_ID", "GROUP_ID")); while ($ar = $dbUsersInGroup->GetNext(true, false)) { if ($USER->GetID() != $ar["USER_ID"]) { $arExtranetUsers[$ar["USER_ID"]] = $ar["USER_ID"]; if (isset($arUserInGroup["SG" . $ar["GROUP_ID"]])) { $arUserInGroup["SG" . $ar["GROUP_ID"]]['users'][] = $ar["USER_ID"]; } else { $arUserInGroup["SG" . $ar["GROUP_ID"]] = array('id' => "SG" . $ar["GROUP_ID"], 'users' => array($ar["USER_ID"])); } if (isset($arWoUserInGroup["extranet"])) { $arWoUserInGroup["extranet"]['users'][] = $ar["USER_ID"]; } else { $arWoUserInGroup["extranet"] = array('id' => "extranet", 'users' => array($ar["USER_ID"])); } } } if (isset($arWoUserInGroup['extranet']) && isset($arWoUserInGroup['extranet']['users'])) { $arWoUserInGroup['extranet']['users'] = array_values(array_unique($arWoUserInGroup['extranet']['users'])); } } if (defined("BX_COMP_MANAGED_CACHE")) { $CACHE_MANAGER->EndTagCache(); } if ($obSGCache->StartDataCache()) { $obSGCache->EndDataCache(array('USER_SG' => $arUserSG, 'EXTRANET_USERS' => $arExtranetUsers, 'USER_IN_GROUP' => $arUserInGroup, 'WO_USER_IN_GROUP' => $arWoUserInGroup)); } $bResult = in_array($toUserId, $arExtranetUsers); } unset($obSGCache); } } else { if (!IsModuleInstalled('intranet')) { if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($USER->GetID(), $arParams['TO_USER_ID'])) { $bResult = false; } else { if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arParams['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($USER->GetID(), $arParams['TO_USER_ID'])) { $bResult = false; } } } } } else { if (isset($arParams['TO_CHAT_ID'])) { global $DB, $USER; $toChatId = intval($arParams['TO_CHAT_ID']); $fromUserId = intval($USER->GetID()); $strSql = "\n\t\t\t\tSELECT R.CHAT_ID\n\t\t\t\tFROM b_im_relation R\n\t\t\t\tWHERE R.USER_ID = " . $fromUserId . "\n\t\t\t\t\tAND R.MESSAGE_TYPE IN ('" . IM_MESSAGE_CHAT . "', '" . IM_MESSAGE_OPEN . "')\n\t\t\t\t\tAND R.CHAT_ID = " . $toChatId . ""; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $bResult = true; } else { $bResult = false; } } } return $bResult; }
return; } if (defined('IM_COMPONENT_INIT')) { return; } else { define("IM_COMPONENT_INIT", true); } if (intval($USER->GetID()) <= 0) { return; } if (!CModule::IncludeModule('im')) { return; } $GLOBALS["APPLICATION"]->SetPageProperty("BodyClass", "im-page"); $arResult = array(); $arSettings = CIMSettings::Get(); $arResult['SETTINGS'] = $arSettings['settings']; $CIMMessage = new CIMMessage(); $arResult['MESSAGE'] = $CIMMessage->GetUnreadMessage(array('USE_TIME_ZONE' => 'N', 'ORDER' => 'ASC')); $CIMChat = new CIMChat(); $arChatMessage = $CIMChat->GetUnreadMessage(array('USE_TIME_ZONE' => 'N', 'ORDER' => 'ASC')); if ($arChatMessage['result']) { foreach ($arChatMessage['message'] as $id => $ar) { $ar['recipientId'] = 'chat' . $ar['recipientId']; $arResult['MESSAGE']['message'][$id] = $ar; } foreach ($arChatMessage['usersMessage'] as $chatId => $ar) { $arResult['MESSAGE']['usersMessage']['chat' . $chatId] = $ar; } foreach ($arChatMessage['unreadMessage'] as $chatId => $ar) { $arResult['MESSAGE']['unreadMessage']['chat' . $chatId] = $ar;
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 MailMessageAgent() { global $DB; $defSiteID = CSite::GetDefSite(); $arMark = array(); $arUnsendMessage = CIMMessage::GetUnsendMessage(); $arToUser = array(); $arFromUser = array(); $arDialog = array(); foreach ($arUnsendMessage as $id => $arMessage) { if (!isset($arMark[$arMessage["TO_USER_ID"]][$arMessage["CHAT_ID"]]) || $arMark[$arMessage["TO_USER_ID"]][$arMessage["CHAT_ID"]] < $arMessage["ID"]) { $arMark[$arMessage["TO_USER_ID"]][$arMessage["CHAT_ID"]] = $arMessage["ID"]; } if ($arMessage['TO_USER_ACTIVE'] != 'Y') { unset($arUnsendMessage[$id]); continue; } if (!CIMSettings::GetNotifyAccess($arMessage["TO_USER_ID"], 'im', 'message', CIMSettings::CLIENT_MAIL)) { unset($arUnsendMessage[$id]); continue; } if ($arMessage["MESSAGE_OUT"] == IM_MAIL_SKIP) { unset($arUnsendMessage[$id]); continue; } if (strlen($arMessage["MESSAGE_OUT"]) <= 0) { $arMessage["MESSAGE_OUT"] = $arMessage["MESSAGE"]; } if (!isset($arToUser[$arMessage["TO_USER_ID"]])) { $siteID = $arMessage["TO_USER_LID"]; if ($siteID == false || StrLen($siteID) <= 0) { $siteID = $defSiteID; if ($siteID == false || StrLen($siteID) <= 0) { continue; } } $arMessage["USER"] = htmlspecialcharsback(CUser::FormatName(CSite::GetNameFormat(false), array("NAME" => $arMessage["TO_USER_NAME"], "LAST_NAME" => $arMessage["TO_USER_LAST_NAME"], "SECOND_NAME" => $arMessage["TO_USER_SECOND_NAME"], "LOGIN" => $arMessage["TO_USER_LOGIN"]), true)); $arToUser[$arMessage["TO_USER_ID"]] = array("USER" => $arMessage["USER"], "USER_ID" => $arMessage["TO_USER_ID"], "USER_LOGIN" => $arMessage["TO_USER_LOGIN"], "USER_NAME" => $arMessage["TO_USER_NAME"], "USER_LAST_NAME" => $arMessage["TO_USER_LAST_NAME"], "USER_SECOND_NAME" => $arMessage["TO_USER_SECOND_NAME"], "TO_USER_LID" => $siteID, "EMAIL_TO" => $arMessage["TO_USER_EMAIL"]); } if (!isset($arFromUser[$arMessage["FROM_USER_ID"]])) { $arMessage["FROM_USER"] = htmlspecialcharsback(CUser::FormatName(CSite::GetNameFormat(false), array("NAME" => $arMessage["FROM_USER_NAME"], "LAST_NAME" => $arMessage["FROM_USER_LAST_NAME"], "SECOND_NAME" => $arMessage["FROM_USER_SECOND_NAME"], "LOGIN" => $arMessage["FROM_USER_LOGIN"]), true)); $arFromUser[$arMessage["FROM_USER_ID"]] = array("FROM_USER" => $arMessage["FROM_USER"], "FROM_USER_ID" => $arMessage["FROM_USER_ID"], "FROM_USER_LOGIN" => $arMessage["FROM_USER_LOGIN"], "FROM_USER_NAME" => $arMessage["FROM_USER_NAME"], "FROM_USER_LAST_NAME" => $arMessage["FROM_USER_LAST_NAME"], "FROM_USER_SECOND_NAME" => $arMessage["FROM_USER_SECOND_NAME"]); } $arDialog[$arMessage["TO_USER_ID"]][$arMessage["FROM_USER_ID"]][] = array('DATE_CREATE' => $arMessage["DATE_CREATE"], 'MESSAGE' => CTextParser::convert4mail(str_replace("#BR#", "\n", strip_tags($arMessage["MESSAGE_OUT"])))); } foreach ($arMark as $userId => $ar) { foreach ($ar as $chatId => $lastSendId) { CIMMessage::SetLastSendId($chatId, $userId, $lastSendId); } } foreach ($arToUser as $toID => $arToInfo) { $message = ""; $bHeader = false; $arNames = array(); $bFirstMessage = true; foreach ($arDialog[$toID] as $fromID => $arMessages) { if ($bFirstMessage) { $bFirstMessage = false; } else { $message .= "\n"; } if (count($arDialog[$toID]) > 1) { $message .= GetMessage('IM_MAIL_TEMPLATE_NEW_MESSAGE_HEADER', array('#FROM_USER#' => $arFromUser[$fromID]['FROM_USER'])) . "\n"; $bHeader = true; } $arNames[] = $arFromUser[$fromID]['FROM_USER']; foreach ($arMessages as $arMessage) { $message .= "\n" . GetMessage('IM_MAIL_TEMPLATE_NEW_MESSAGE_TEXT', array('#DATE_CREATE#' => $arMessage['DATE_CREATE'], '#MESSAGE#' => $arMessage['MESSAGE'])) . "\n"; } } if ($bHeader) { $message .= "\n" . GetMessage('IM_MAIL_TEMPLATE_NEW_MESSAGE_FOOTER'); } $arFields = array("USER" => $arToInfo["USER_ID"], "USER_ID" => $arToInfo["USER_ID"], "USER_LOGIN" => $arToInfo["USER_LOGIN"], "USER_NAME" => $arToInfo["USER_NAME"], "USER_LAST_NAME" => $arToInfo["USER_LAST_NAME"], "USER_SECOND_NAME" => $arToInfo["USER_SECOND_NAME"], "EMAIL_TO" => $arToInfo["EMAIL_TO"], "TITLE" => $arToInfo["TITLE"], "MESSAGES" => $message); if (count($arNames) > 1) { $mailTemplate = "IM_NEW_MESSAGE_GROUP"; $arFields['FROM_USERS'] = implode(', ', $arNames); } else { $mailTemplate = "IM_NEW_MESSAGE"; $arFields['FROM_USER'] = implode(', ', $arNames); } $event = new CEvent(); $event->Send($mailTemplate, $arToInfo['TO_USER_LID'], $arFields, "N"); } return "CIMMail::MailMessageAgent();"; }
$arResult['CONTACT_LIST']['woUserInGroup']['other']['users'] = array_merge($arResult['CONTACT_LIST']['woUserInGroup']['other']['users'], $arWoUserInGroup['users']); } else { $arWoUserInGroup['id'] = 'other'; $arResult['CONTACT_LIST']['woUserInGroup']['other'] = $arWoUserInGroup; } } } } } if (!isset($arResult['CONTACT_LIST']['users'][$USER->GetID()])) { $arUsers = CIMContactList::GetUserData(array('ID' => $USER->GetID(), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'Y', 'SHOW_ONLINE' => 'N')); $arResult['CONTACT_LIST']['users'][$USER->GetID()] = $arUsers['users'][$USER->GetID()]; } $arResult['CURRENT_TAB'] = CIMMessenger::GetCurrentTab(); } else { $arResult['SETTINGS_NOTIFY_BLOCKED'] = CIMSettings::GetSimpleNotifyBlocked(); } $arResult['DESKTOP'] = $arParams['DESKTOP'] == 'Y' ? 'true' : 'false'; $arResult["INIT"] = $arParams['INIT']; $arResult['DESKTOP_LINK_OPEN'] = $arParams['DESKTOP_LINK_OPEN'] == 'Y' ? 'true' : 'false'; $arResult['PATH_TO_USER_PROFILE_TEMPLATE'] = CIMContactList::GetUserPath(); $arResult['PATH_TO_USER_PROFILE'] = CIMContactList::GetUserPath($USER->GetId()); $arResult['TURN_SERVER'] = COption::GetOptionString('im', 'turn_server'); $arResult['TURN_SERVER_FIREFOX'] = COption::GetOptionString('im', 'turn_server_firefox'); $arResult['TURN_SERVER_LOGIN'] = COption::GetOptionString('im', 'turn_server_login'); $arResult['TURN_SERVER_PASSWORD'] = COption::GetOptionString('im', 'turn_server_password'); CIMMessenger::InitCounters($USER->GetID()); $jsInit = array('im'); if (defined('LANGUAGE_ID') && LANGUAGE_ID == 'ru') { $jsInit[] = 'translit'; }
public static function SendMention($params) { $params['CHAT_ID'] = intval($params['CHAT_ID']); if (!isset($params['MESSAGE']) || $params['CHAT_ID'] <= 0) { return false; } if (!isset($params['CHAT_TITLE']) || !isset($params['CHAT_TYPE'])) { $orm = \Bitrix\Im\ChatTable::getById($params['CHAT_ID']); $chat = $orm->fetch(); if (!$chat) { return false; } $params['CHAT_TITLE'] = $chat['TITLE']; $params['CHAT_TYPE'] = trim($chat['TYPE']); } if (!in_array($params['CHAT_TYPE'], array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT))) { return false; } if (!isset($params['CHAT_RELATION'])) { $params['CHAT_RELATION'] = CIMChat::GetRelationById($params['CHAT_ID']); } $forUsers = array(); if (preg_match_all("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", $params['MESSAGE'], $matches)) { if ($params['CHAT_TYPE'] == IM_MESSAGE_OPEN) { foreach ($matches[1] as $userId) { if (!isset($params['CHAT_RELATION'][$userId])) { $forUsers[$userId] = $userId; } else { if ($params['CHAT_RELATION'][$userId]['NOTIFY_BLOCK'] == 'Y' || !CIMSettings::GetNotifyAccess($params['CHAT_RELATION'][$userId]['USER_ID'], 'im', 'openChat', CIMSettings::CLIENT_PUSH)) { $forUsers[$userId] = $userId; } } } } else { foreach ($matches[1] as $userId) { if (isset($params['CHAT_RELATION'][$userId]) && ($params['CHAT_RELATION'][$userId]['NOTIFY_BLOCK'] == 'Y' || !CIMSettings::GetNotifyAccess($params['CHAT_RELATION'][$userId]['USER_ID'], 'im', 'chat', CIMSettings::CLIENT_PUSH))) { $forUsers[$userId] = $userId; } } } } $userName = \Bitrix\Im\User::getInstance($params['FROM_USER_ID'])->getName(); $userGender = \Bitrix\Im\User::getInstance($params['FROM_USER_ID'])->getGender(); if ($userName) { $chatTitle = substr(htmlspecialcharsback($params['CHAT_TITLE']), 0, 32); $notifyMail = GetMessage('IM_MESSAGE_MENTION_' . ($userGender == 'F' ? 'F' : 'M'), array('#TITLE#' => $chatTitle)); $notifyText = GetMessage('IM_MESSAGE_MENTION_' . ($userGender == 'F' ? 'F' : 'M'), array('#TITLE#' => '[CHAT=' . $params['CHAT_ID'] . ']' . $chatTitle . '[/CHAT]')); $pushText = GetMessage('IM_MESSAGE_MENTION_PUSH_' . ($userGender == 'F' ? 'F' : 'M'), array('#USER#' => $userName, '#TITLE#' => $chatTitle)) . ': ' . self::PrepareMessageForPush(array('MESSAGE' => $params['MESSAGE'], 'FILES' => $params['FILES'])); } if (strlen($notifyText) > 0) { foreach ($forUsers as $userId) { $arMessageFields = array("TO_USER_ID" => $userId, "FROM_USER_ID" => $params['FROM_USER_ID'], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "im", "NOTIFY_EVENT" => "mention", "NOTIFY_TAG" => 'IM|MENTION|' . $params['CHAT_ID'], "NOTIFY_SUB_TAG" => "IM_MESS", "NOTIFY_MESSAGE" => $notifyText, "NOTIFY_MESSAGE_OUT" => $notifyMail, "PUSH_MESSAGE" => $pushText, "PUSH_PARAMS" => array('TAG' => 'IM_CHAT_' . $params['CHAT_ID'], 'CATEGORY' => 'ANSWER', 'URL' => SITE_DIR . 'mobile/ajax.php?mobile_action=im_answer', 'PARAMS' => array('RECIPIENT_ID' => 'chat' . $params['CHAT_ID'])), "PUSH_APP_ID" => 'Bitrix24'); CIMNotify::Add($arMessageFields); } } return true; }