public static function SetRecent($entityId, $messageId, $isChat = false, $userId = false) { $entityId = intval($entityId); $messageId = intval($messageId); if ($entityId <= 0 || $messageId <= 0) { return false; } $userId = intval($userId); if ($userId <= 0) { $userId = $GLOBALS['USER']->GetID(); } if (!$isChat && $userId == $entityId) { return false; } global $DB; $strSQL = "\n\t\t\tINSERT INTO b_im_recent (USER_ID, ITEM_TYPE, ITEM_ID, ITEM_MID)\n\t\t\tVALUES (" . $userId . ", '" . ($isChat ? IM_MESSAGE_GROUP : IM_MESSAGE_PRIVATE) . "', " . $entityId . ", " . $messageId . ")\n\t\t\tON DUPLICATE KEY UPDATE ITEM_MID = " . $messageId; $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); $obCache = new CPHPCache(); $obCache->CleanDir('/bx/im/rec' . CIMMessenger::GetCachePath($userId)); if ($isChat) { CIMMessenger::SpeedFileDelete($userId, IM_SPEED_GROUP); } else { CIMMessenger::SpeedFileDelete($userId, IM_SPEED_MESSAGE); } return true; }
public static function OnFileDelete($params) { $result = IM\ChatTable::getList(array('select' => array('ID', 'AUTHOR_ID'), 'filter' => array('=AVATAR' => $params['ID']))); while ($row = $result->fetch()) { IM\ChatTable::update($row['ID'], array('AVATAR' => '')); $obCache = new CPHPCache(); $arRel = CIMChat::GetRelationById($row['ID']); foreach ($arRel as $rel) { $obCache->CleanDir('/bx/imc/recent' . CIMMessenger::GetCachePath($rel['USER_ID'])); } } }
public static function SetRecent($arParams) { $itemId = intval($arParams['ENTITY_ID']); $messageId = intval($arParams['MESSAGE_ID']); if ($itemId <= 0) { return false; } $userId = intval($arParams['USER_ID']); if ($userId <= 0) { $userId = (int) $GLOBALS['USER']->GetID(); } $chatType = IM_MESSAGE_PRIVATE; if (isset($arParams['CHAT_TYPE']) && in_array($arParams['CHAT_TYPE'], array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT))) { $chatType = $arParams['CHAT_TYPE']; } else { if (isset($arParams['CHAT_ID'])) { $orm = IM\ChatTable::getById($arParams['CHAT_ID']); if ($chatData = $orm->fetch()) { $chatType = $chatData['TYPE']; } } } $isChat = in_array($chatType, array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT)); if (!$isChat && $userId == $itemId) { return false; } global $DB; $strSQL = "\n\t\t\tINSERT INTO b_im_recent (USER_ID, ITEM_TYPE, ITEM_ID, ITEM_MID)\n\t\t\tVALUES (" . $userId . ", '" . $chatType . "', " . $itemId . ", " . $messageId . ")\n\t\t\tON DUPLICATE KEY UPDATE ITEM_MID = " . $messageId . "\n\t\t"; $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); $obCache = new CPHPCache(); $obCache->CleanDir('/bx/imc/recent' . CIMMessenger::GetCachePath($userId)); if ($isChat) { CIMMessenger::SpeedFileDelete($userId, IM_SPEED_GROUP); } else { CIMMessenger::SpeedFileDelete($userId, IM_SPEED_MESSAGE); } return true; }
public static function GetRecentList($arParams = Array()) { global $DB, $USER; $bLoadUnreadMessage = isset($arParams['LOAD_UNREAD_MESSAGE']) && $arParams['LOAD_UNREAD_MESSAGE'] == 'Y'? true: false; $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N'? false: true; $bSmiles = isset($arParams['USE_SMILES']) && $arParams['USE_SMILES'] == 'N'? false: true; $nameTemplate = COption::GetOptionString("im", "user_name_template", "#LAST_NAME# #NAME#", SITE_ID); $nameTemplateSite = CSite::GetNameFormat(false); $nameOfSite = CModule::IncludeModule('extranet') && !CExtranet::IsIntranetUser()? "ex": false; $bIntranetEnable = IsModuleInstalled('intranet') && CModule::IncludeModule('intranet')? true: false; $arRecent = Array(); $arUsers = Array(); $cache_ttl = 2592000; $cache_id = $GLOBALS['USER']->GetID(); $cache_dir = '/bx/imc/rec'.CIMMessenger::GetCachePath($cache_id); $obCache = new CPHPCache(); if($obCache->InitCache($cache_ttl, $cache_id, $cache_dir)) { $ar = $obCache->GetVars(); $arRecent = $ar['recent']; $arUsers = $ar['users']; } else { if (!$bTimeZone) CTimeZone::Disable(); $strSql = " SELECT R.ITEM_TYPE, R.ITEM_ID, R.ITEM_MID M_ID, M.AUTHOR_ID M_AUTHOR_ID, M.MESSAGE M_MESSAGE, ".$DB->DatetimeToTimestampFunction('M.DATE_CREATE')." M_DATE_CREATE, C.TITLE C_TITLE, C.AUTHOR_ID C_OWNER_ID, U.LOGIN, U.NAME, U.LAST_NAME, U.PERSONAL_PHOTO, U.SECOND_NAME, U.PERSONAL_BIRTHDAY, U.PERSONAL_GENDER FROM b_im_recent R LEFT JOIN b_user U ON R.ITEM_TYPE = '".IM_MESSAGE_PRIVATE."' AND R.ITEM_ID = U.ID LEFT JOIN b_im_chat C ON R.ITEM_TYPE = '".IM_MESSAGE_GROUP."' AND R.ITEM_ID = C.ID LEFT JOIN b_im_message M ON R.ITEM_MID = M.ID WHERE R.USER_ID = ".$USER->GetId(); if (!$bTimeZone) CTimeZone::Enable(); $toDelete = Array(); $CCTP = new CTextParser(); $CCTP->MaxStringLen = 255; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => ($bSmiles? "Y": "N"), "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); while ($arRes = $dbRes->GetNext(true, false)) { $arRes['ITEM_TYPE'] = trim($arRes['ITEM_TYPE']); if ($arRes['M_DATE_CREATE']+2592000 < time()) { $toDelete[$arRes['ITEM_TYPE']][] = $arRes['ITEM_ID']; continue; } $itemId = $arRes['ITEM_ID']; $item = Array( 'TYPE' => $arRes['ITEM_TYPE'], 'MESSAGE' => Array( 'id' => $arRes['M_ID'], 'senderId' => $arRes['M_AUTHOR_ID'], 'date' => $arRes['M_DATE_CREATE'], 'text' => $CCTP->convertText(preg_replace("/\[s\].*?\[\/s\]/i", "", $arRes['M_MESSAGE'])) ) ); $item['MESSAGE']['text'] = preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [".GetMessage('IM_QUOTE')."] ", strip_tags(str_replace(array("<br>","<br/>","<br />", "#BR#"), Array(" "," ", " ", " "), $item['MESSAGE']['text']), "<img>")); if ($arRes['ITEM_TYPE'] == IM_MESSAGE_PRIVATE) { $arUsers[] = $arRes['ITEM_ID']; $arFileTmp = CFile::ResizeImageGet( $arRes["PERSONAL_PHOTO"], array('width' => 58, 'height' => 58), BX_RESIZE_IMAGE_EXACT, false ); $item['USER'] = Array( 'id' => $arRes['ITEM_ID'], 'name' => CUser::FormatName($nameTemplateSite, $arRes, true, false), 'nameList' => CUser::FormatName($nameTemplate, $arRes, true, false), 'avatar' => empty($arFileTmp['src'])? '/bitrix/js/im/images/blank.gif': $arFileTmp['src'], 'gender' => $arRes['PERSONAL_GENDER'] == 'F'? 'F': 'M', 'status' => 'offline', 'birthday' => $arRes['PERSONAL_BIRTHDAY'], 'profile' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('im', 'path_to_user_profile', "", $nameOfSite), array("user_id" => $arRes["ITEM_ID"])) ); } else { $itemId = 'chat'.$itemId; $item['CHAT'] = Array( 'id' => $arRes['ITEM_ID'], 'name' => $arRes["C_TITLE"], 'owner' => $arRes["C_OWNER_ID"], ); } $arRecent[$itemId] = $item; } // remove old entity if (!empty($toDelete)) { if (isset($toDelete[IM_MESSAGE_PRIVATE])) self::DeleteRecent($toDelete[IM_MESSAGE_PRIVATE]); if (isset($toDelete[IM_MESSAGE_GROUP])) self::DeleteRecent($toDelete[IM_MESSAGE_GROUP], true); } if($obCache->StartDataCache()) $obCache->EndDataCache(Array('recent' => $arRecent, 'users' => $arUsers)); } $arOnline = self::GetStatus(Array('ID' => array_values($arUsers))); foreach ($arRecent as $key => $value) { if ($value['TYPE'] != IM_MESSAGE_PRIVATE) continue; $arRecent[$key]['USER']['birthday'] = $bIntranetEnable? CIntranetUtils::IsToday($value['USER']['birthday']): false; $arRecent[$key]['USER']['status'] = isset($arOnline['users'][$value['USER']['id']])? 'online': 'offline'; } if ($bLoadUnreadMessage) { $CIMMessage = new CIMMessage(false, Array( 'hide_link' => true )); $ar = $CIMMessage->GetUnreadMessage(Array( 'LOAD_DEPARTMENT' => 'N', 'ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USE_TIME_ZONE' => $bTimeZone? 'Y': 'N', 'USE_SMILES' => $bSmiles? 'Y': 'N' )); foreach ($ar['message'] as $data) { if (!isset($arRecent[$data['senderId']])) { $arRecent[$data['senderId']] = Array( 'TYPE' => IM_MESSAGE_PRIVATE, 'USER' => $ar['users'][$data['senderId']] ); } $arRecent[$data['senderId']]['MESSAGE'] = Array( 'id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [".GetMessage('IM_QUOTE')."] ", strip_tags(str_replace(array("<br>","<br/>","<br />", "#BR#"), Array(" ", " ", " ", " "), $data['text']), "<img>")) ); $arRecent[$data['senderId']]['COUNTER'] = $data['counter']; } $CIMChat = new CIMChat(false, Array( 'hide_link' => true )); $ar = $CIMChat->GetUnreadMessage(Array( 'ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USER_LOAD' => 'N', 'USE_SMILES' => $bSmiles? 'Y': 'N', 'USE_TIME_ZONE' => $bTimeZone? 'Y': 'N' )); foreach ($ar['message'] as $data) { if (!isset($arRecent['chat'.$data['recipientId']])) { $arRecent['chat'.$data['recipientId']] = Array( 'TYPE' => IM_MESSAGE_GROUP, 'CHAT' => $ar['chat'] ); } $arRecent['chat'.$data['recipientId']]['MESSAGE'] = Array( 'id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => $data['text'] ); $arRecent['chat'.$data['recipientId']]['COUNTER'] = $data['counter']; } } if (!empty($arRecent)) { sortByColumn( $arRecent, array( 'COUNTER' => array(SORT_NUMERIC, SORT_DESC), 'MESSAGE' => array(SORT_NUMERIC, SORT_DESC) ), array( 'COUNTER' => function($counter){ return !is_null($counter); }, 'MESSAGE' => function($recent){ return $recent['date']; } ), null, true ); } return $arRecent; }
function HideAllChatMessage($chatId) { global $DB; $chatId = intval($chatId); $limitById = ''; $ar = \CIMChat::GetRelationById($chatId, $this->user_id); if ($ar && $ar['START_ID'] > 0) { $limitById = 'AND M.ID >= ' . intval($ar['START_ID']); } $strSql = "\n\t\t\tSELECT\n\t\t\t\tMAX(M.ID)+1 MAX_ID,\n\t\t\t\tR1.ID R1_ID\n\t\t\tFROM b_im_relation R1\n\t\t\tINNER JOIN b_im_message M ON M.CHAT_ID = R1.CHAT_ID\n\t\t\tWHERE\n\t\t\t\tR1.USER_ID = " . $this->user_id . "\n\t\t\tAND R1.MESSAGE_TYPE <> '" . IM_MESSAGE_PRIVATE . "'\n\t\t\tAND R1.CHAT_ID = " . $chatId . "\n\t\t\t\t" . $limitById . "\n\t\t\tGROUP BY M.CHAT_ID, R1.ID\n\t\t"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $strSql = "UPDATE b_im_relation SET START_ID = " . intval($arRes['MAX_ID']) . ", LAST_ID = " . (intval($arRes['MAX_ID']) - 1) . " WHERE ID = " . intval($arRes['R1_ID']); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $obCache = new CPHPCache(); $obCache->CleanDir('/bx/imc/recent' . CIMMessenger::GetCachePath($this->user_id)); } return true; }
/** * Method will be invoked after an database record updated. * * @param array $oldRecord All fields before update. * @param array $newRecord All fields after update. * * @return void */ public function afterUpdateTrigger(array $oldRecord, array $newRecord) { if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } $arFields = \CIMMessenger::GetById($newRecord['ID'], array('WITH_FILES' => 'Y')); if (!$arFields) { return; } $arFields['DATE_MODIFY'] = time() + \CTimeZone::GetOffset(); $CCTP = new \CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $pullMessage = $CCTP->convertText(htmlspecialcharsbx($arFields['MESSAGE'])); $relations = \CIMChat::GetRelationById($arFields['CHAT_ID']); $arPullMessage = array('id' => $arFields['ID'], 'type' => $arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE ? 'private' : 'chat', 'text' => $pullMessage, 'date' => $arFields['DATE_MODIFY']); if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) { $arFields['FROM_USER_ID'] = $arFields['AUTHOR_ID']; foreach ($relations as $rel) { if ($rel['USER_ID'] != $arFields['AUTHOR_ID']) { $arFields['TO_USER_ID'] = $rel['USER_ID']; } } $arPullMessage['fromUserId'] = $arFields['FROM_USER_ID']; $arPullMessage['toUserId'] = $arFields['TO_USER_ID']; } else { $arPullMessage['chatId'] = $arFields['CHAT_ID']; $arPullMessage['senderId'] = $arFields['AUTHOR_ID']; } \CPullStack::AddByUsers(array_keys($relations), $p = array('module_id' => 'im', 'command' => $arFields['PARAMS']['IS_DELETED'] === 'Y' ? 'messageDelete' : 'messageUpdate', 'params' => $arPullMessage)); foreach ($relations as $rel) { $obCache = new \CPHPCache(); $obCache->CleanDir('/bx/imc/recent' . \CIMMessenger::GetCachePath($rel['USER_ID'])); } if ($newRecord['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) { \CPullWatch::AddToStack('IM_PUBLIC_' . $arFields['CHAT_ID'], array('module_id' => 'im', 'command' => $arFields['PARAMS']['IS_DELETED'] === 'Y' ? 'messageDelete' : 'messageUpdate', 'params' => $arPullMessage)); } foreach (\GetModuleEvents("im", "OnAfterMessagesUpdate", true) as $arEvent) { \ExecuteModuleEventEx($arEvent, array(intval($newRecord['ID']), $arFields)); } }
public static function GetRecentList($arParams = array()) { global $DB, $USER; $bLoadUnreadMessage = isset($arParams['LOAD_UNREAD_MESSAGE']) && $arParams['LOAD_UNREAD_MESSAGE'] == 'Y' ? true : false; $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N' ? false : true; $bSmiles = isset($arParams['USE_SMILES']) && $arParams['USE_SMILES'] == 'N' ? false : true; $userId = isset($arParams['USER_ID']) ? $arParams['USER_ID'] : $USER->GetId(); $nameTemplate = self::GetUserNameTemplate(SITE_ID); $nameTemplateSite = CSite::GetNameFormat(false); $bIntranetEnable = IsModuleInstalled('intranet') && CModule::IncludeModule('intranet') ? true : false; $arRecent = array(); $arUsers = array(); $bColorEnabled = IM\Color::isEnabled(); $cache_ttl = 2592000; $cache_id = 'im_recent_v8_' . $userId . '_' . $bColorEnabled; $cache_dir = '/bx/imc/recent' . CIMMessenger::GetCachePath($userId); $obCache = new CPHPCache(); if ($obCache->InitCache($cache_ttl, $cache_id, $cache_dir)) { $ar = $obCache->GetVars(); $arRecent = $ar['recent']; $arUsers = $ar['users']; } else { if (!$bTimeZone) { CTimeZone::Disable(); } $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tR.ITEM_TYPE, R.ITEM_ID,\n\t\t\t\t\tR.ITEM_MID M_ID, M.AUTHOR_ID M_AUTHOR_ID, M.ID M_ID, M.CHAT_ID M_CHAT_ID, M.MESSAGE M_MESSAGE, " . $DB->DatetimeToTimestampFunction('M.DATE_CREATE') . " M_DATE_CREATE,\n\t\t\t\t\tC.TITLE C_TITLE, C.AUTHOR_ID C_OWNER_ID, C.ENTITY_TYPE C_ENTITY_TYPE, C.AVATAR C_AVATAR, C.CALL_NUMBER C_CALL_NUMBER, C.EXTRANET CHAT_EXTRANET, C.COLOR CHAT_COLOR, C.TYPE CHAT_TYPE,\n\t\t\t\t\tU.LOGIN, U.NAME, U.LAST_NAME, U.PERSONAL_PHOTO, U.SECOND_NAME, U.PERSONAL_BIRTHDAY, U.PERSONAL_GENDER, U.EXTERNAL_AUTH_ID, U.WORK_POSITION,\n\t\t\t\t\tC1.USER_ID RID\n\t\t\t\tFROM\n\t\t\t\tb_im_recent R\n\t\t\t\tLEFT JOIN b_user U ON R.ITEM_TYPE = '" . IM_MESSAGE_PRIVATE . "' AND R.ITEM_ID = U.ID\n\t\t\t\tLEFT JOIN b_im_chat C ON R.ITEM_TYPE != '" . IM_MESSAGE_PRIVATE . "' AND R.ITEM_ID = C.ID\n\t\t\t\tLEFT JOIN b_im_message M ON R.ITEM_MID = M.ID\n\t\t\t\tLEFT JOIN b_im_relation C1 ON C1.CHAT_ID = C.ID AND C1.USER_ID = " . $userId . "\n\t\t\t\tWHERE R.USER_ID = " . $userId; if (!$bTimeZone) { CTimeZone::Enable(); } $toDelete = array(); $arMessageId = array(); $CCTP = new CTextParser(); $CCTP->MaxStringLen = 255; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => $bSmiles ? "Y" : "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->GetNext(true, false)) { $arRes['ITEM_TYPE'] = trim($arRes['ITEM_TYPE']); if ($arRes['ITEM_TYPE'] == IM_MESSAGE_OPEN) { if (intval($arRes['RID']) <= 0 && IM\User::getInstance($userId)->isExtranet()) { continue; } } else { if ($arRes['ITEM_TYPE'] == IM_MESSAGE_CHAT) { if (intval($arRes['RID']) <= 0) { continue; } } } $arMessageId[] = $arRes['M_ID']; if ($arRes['M_DATE_CREATE'] + 2592000 < time()) { $toDelete[$arRes['ITEM_TYPE']][] = $arRes['ITEM_ID']; continue; } $itemId = $arRes['ITEM_ID']; $item = array('TYPE' => $arRes['ITEM_TYPE'], 'MESSAGE' => array('id' => $arRes['M_ID'], 'chatId' => $arRes['M_CHAT_ID'], 'senderId' => $arRes['M_AUTHOR_ID'], 'date' => $arRes['M_DATE_CREATE'], 'text' => $CCTP->convertText(preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $arRes['M_MESSAGE'])))); $item['MESSAGE']['text'] = preg_replace('#\\-{54}.+?\\-{54}#s', " [" . GetMessage('IM_QUOTE') . "] ", strip_tags(str_replace(array("<br>", "<br/>", "<br />", "#BR#"), array(" ", " ", " ", " "), $item['MESSAGE']['text']), "<img>")); if ($arRes['ITEM_TYPE'] == IM_MESSAGE_PRIVATE) { $arUsers[] = $arRes['ITEM_ID']; $arFileTmp = CFile::ResizeImageGet($arRes["PERSONAL_PHOTO"], array('width' => 58, 'height' => 58), BX_RESIZE_IMAGE_EXACT, false, false, true); $item['USER'] = array('id' => $arRes['ITEM_ID'], 'name' => CUser::FormatName($nameTemplateSite, $arRes, true, false), 'nameList' => CUser::FormatName($nameTemplate, $arRes, true, false), 'workPosition' => $arRes['WORK_POSITION'], 'color' => self::GetUserColor($arRes["ID"], $arRes['PERSONAL_GENDER'] == 'M' ? 'M' : 'F'), 'avatar' => empty($arFileTmp['src']) ? '/bitrix/js/im/images/blank.gif' : $arFileTmp['src'], 'status' => 'offline', 'birthday' => $arRes['PERSONAL_BIRTHDAY'], 'gender' => $arRes['PERSONAL_GENDER'] == 'F' ? 'F' : 'M', 'extranet' => false, 'network' => $arRes['EXTERNAL_AUTH_ID'] == self::NETWORK_AUTH_ID, 'phoneDevice' => false, 'profile' => CIMContactList::GetUserPath($arRes["ITEM_ID"])); } else { $chatType = $arRes["ITEM_TYPE"] == IM_MESSAGE_OPEN ? 'open' : 'chat'; if ($arRes["C_ENTITY_TYPE"] == 'CALL') { $chatType = 'call'; } $itemId = 'chat' . $itemId; $item['CHAT'] = array('id' => $arRes['ITEM_ID'], 'name' => $arRes["C_TITLE"], 'color' => $arRes["CHAT_COLOR"] == "" ? IM\Color::getColorByNumber($arRes['ITEM_ID']) : IM\Color::getColor($arRes['CHAT_COLOR']), 'avatar' => CIMChat::GetAvatarImage($arRes["C_AVATAR"]), 'extranet' => $arRes["CHAT_EXTRANET"] == "" ? "" : ($arRes["CHAT_EXTRANET"] == "Y" ? true : false), 'owner' => $arRes["C_OWNER_ID"], 'type' => $chatType, 'messageType' => $arRes['CHAT_TYPE'], 'call_number' => $arRes["C_CALL_NUMBER"]); } $arRecent[$itemId] = $item; } $params = CIMMessageParam::Get($arMessageId); foreach ($arRecent as $key => $value) { if (isset($params[$value['MESSAGE']['id']])) { if (count($params[$value['MESSAGE']['id']]['FILE_ID']) > 0 && strlen(trim($arRecent[$key]['MESSAGE']['text'])) <= 0) { $arRecent[$key]['MESSAGE']['text'] = "[" . GetMessage('IM_FILE') . "]"; } $arRecent[$key]['MESSAGE']['params'] = $params[$value['MESSAGE']['id']]; } } if (!empty($toDelete)) { if (isset($toDelete[IM_MESSAGE_PRIVATE])) { self::DeleteRecent($toDelete[IM_MESSAGE_PRIVATE]); } if (isset($toDelete[IM_MESSAGE_CHAT])) { self::DeleteRecent($toDelete[IM_MESSAGE_CHAT], true); } if (isset($toDelete[IM_MESSAGE_OPEN])) { self::DeleteRecent($toDelete[IM_MESSAGE_OPEN], true); } } $bExtranetEnable = IsModuleInstalled('extranet'); $bVoximplantEnable = IsModuleInstalled('voximplant'); if ($bExtranetEnable || $bVoximplantEnable) { $arUserPhone = array(); $arUserDepartment = array(); $arSelectParams = array(); if ($bExtranetEnable) { $arSelectParams[] = 'UF_DEPARTMENT'; } if ($bVoximplantEnable) { $arSelectParams[] = 'UF_VI_PHONE'; } $dbUsers = CUser::GetList($sort_by = array('last_name' => 'asc'), $dummy = '', array('ID' => $userId . "|" . implode('|', $arUsers)), array('FIELDS' => array("ID"), 'SELECT' => $arSelectParams)); while ($arUser = $dbUsers->GetNext(true, false)) { $arUserPhone[$arUser['ID']] = $arUser['UF_VI_PHONE'] == 'Y'; $arUserDepartment[$arUser['ID']] = self::IsExtranet($arUser); } foreach ($arRecent as $key => $value) { if (isset($value['USER'])) { $arRecent[$key]['USER']['extranet'] = $arUserDepartment[$value['USER']['id']]; $arRecent[$key]['USER']['phoneDevice'] = $arUserPhone[$value['USER']['id']]; } } } if ($obCache->StartDataCache()) { $obCache->EndDataCache(array('recent' => $arRecent, 'users' => $arUsers)); } } $arOnline = CIMStatus::GetList(array('ID' => array_values($arUsers), 'GET_OFFLINE' => 'Y')); foreach ($arRecent as $key => $value) { if ($value['TYPE'] != IM_MESSAGE_PRIVATE) { continue; } $arRecent[$key]['USER']['birthday'] = $bIntranetEnable ? CIntranetUtils::IsToday($value['USER']['birthday']) : false; $arRecent[$key]['USER']['status'] = isset($arOnline['users'][$value['USER']['id']]) ? $arOnline['users'][$value['USER']['id']]['status'] : 'offline'; $arRecent[$key]['USER']['idle'] = isset($arOnline['users'][$value['USER']['id']]) ? $arOnline['users'][$value['USER']['id']]['idle'] : 0; $arRecent[$key]['USER']['mobileLastDate'] = isset($arOnline['users'][$value['USER']['id']]) ? $arOnline['users'][$value['USER']['id']]['mobileLastDate'] : 0; if ($arOnline['users'][$value['USER']['id']]['color']) { $arRecent[$key]['USER']['color'] = $arOnline['users'][$value['USER']['id']]['color']; } } if ($bLoadUnreadMessage) { $CIMMessage = new CIMMessage(false, array('HIDE_LINK' => 'Y')); $ar = $CIMMessage->GetUnreadMessage(array('LOAD_DEPARTMENT' => 'N', 'ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USE_TIME_ZONE' => $bTimeZone ? 'Y' : 'N', 'USE_SMILES' => $bSmiles ? 'Y' : 'N')); foreach ($ar['message'] as $data) { if (!isset($arRecent[$data['senderId']])) { $arRecent[$data['senderId']] = array('TYPE' => IM_MESSAGE_PRIVATE, 'USER' => $ar['users'][$data['senderId']]); } $arRecent[$data['senderId']]['MESSAGE'] = array('id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => preg_replace('#\\-{54}.+?\\-{54}#s', " [" . GetMessage('IM_QUOTE') . "] ", strip_tags(str_replace(array("<br>", "<br/>", "<br />", "#BR#"), array(" ", " ", " ", " "), $data['text']), "<img>"))); $arRecent[$data['senderId']]['COUNTER'] = $data['counter']; } $CIMChat = new CIMChat(false, array('HIDE_LINK' => 'Y')); $ar = $CIMChat->GetUnreadMessage(array('ORDER' => 'ASC', 'GROUP_BY_CHAT' => 'Y', 'USER_LOAD' => 'N', 'FILE_LOAD' => 'N', 'USE_SMILES' => $bSmiles ? 'Y' : 'N', 'USE_TIME_ZONE' => $bTimeZone ? 'Y' : 'N')); foreach ($ar['message'] as $data) { if (!isset($arRecent['chat' . $data['recipientId']])) { $arRecent['chat' . $data['recipientId']] = array('TYPE' => $ar['messageType'] ? $ar['messageType'] : IM_MESSAGE_CHAT, 'CHAT' => $ar['chat']); } $arRecent['chat' . $data['recipientId']]['MESSAGE'] = array('id' => $data['id'], 'senderId' => $data['senderId'], 'date' => $data['date'], 'text' => $data['text']); $arRecent['chat' . $data['recipientId']]['COUNTER'] = $data['counter']; } } if (!empty($arRecent)) { sortByColumn($arRecent, array('COUNTER' => array(SORT_NUMERIC, SORT_DESC), 'MESSAGE' => array(SORT_NUMERIC, SORT_DESC)), array('COUNTER' => array(__CLASS__, 'GetRecentListSortCounter'), 'MESSAGE' => array(__CLASS__, 'GetRecentListSortMessage')), null, true); } return $arRecent; }