/** * 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 static function afterUpdateTrigger(array $oldRecord, array $newRecord) { if ($oldRecord['TITLE'] !== $newRecord['TITLE']) { if (\CModule::IncludeModule("pull")) { $ar = \CIMChat::GetRelationById($newRecord['CHAT_ID']); foreach ($ar as $rel) { \CIMContactList::CleanChatCache($rel['USER_ID']); \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'chatRename', 'params' => array('chatId' => $newRecord['CHAT_ID'], 'chatTitle' => htmlspecialcharsbx($newRecord['TITLE'])))); } } } if ($oldRecord['AVATAR'] !== $newRecord['AVATAR']) { if (\CModule::IncludeModule('pull')) { $avatarImage = \CIMChat::GetAvatarImage($newRecord['AVATAR']); $ar = \CIMChat::GetRelationById($newRecord['CHAT_ID']); foreach ($ar as $relation) { \CIMContactList::CleanChatCache($relation['USER_ID']); \CPullStack::AddByUser($relation['USER_ID'], array('module_id' => 'im', 'command' => 'chatAvatar', 'params' => array('chatId' => $newRecord['CHAT_ID'], 'chatAvatar' => $avatarImage))); } } } if ($oldRecord['COLOR'] !== $newRecord['COLOR']) { if (\CModule::IncludeModule('pull')) { $ar = \CIMChat::GetRelationById($newRecord['CHAT_ID']); foreach ($ar as $relation) { \CIMContactList::CleanChatCache($relation['USER_ID']); \CPullStack::AddByUser($relation['USER_ID'], array('module_id' => 'im', 'command' => 'chatChangeColor', 'params' => array('chatId' => $newRecord['CHAT_ID'], 'chatColor' => \Bitrix\Im\Color::getColor($newRecord['COLOR'])))); } } } }
function onExecuteStartWriting(\Bitrix\Main\Event $event) { $parameters = $event->getParameters(); $userId = $parameters[0]; $dialogId = $parameters[1] . $parameters[2]; if ($userId > 0) { if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } \CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS'); if (intval($dialogId) > 0) { \CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId))); } elseif (substr($dialogId, 0, 4) == 'chat') { $chatId = substr($dialogId, 4); $arRelation = \CIMChat::GetRelationById($chatId); unset($arRelation[$userId]); $pullMessage = array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)); \CPullStack::AddByUsers(array_keys($arRelation), $pullMessage); $orm = \Bitrix\Im\ChatTable::getById($chatId); $chat = $orm->fetch(); if ($chat['TYPE'] == IM_MESSAGE_OPEN) { \CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $pullMessage); } } } }
public static function Set($userId, $params) { $userId = intval($userId); if ($userId <= 0) { return false; } if (isset($params['STATUS'])) { $params['IDLE'] = null; } $needToUpdate = false; $params = self::PrepereFields($params); $res = IM\StatusTable::getById($userId); if ($status = $res->fetch()) { foreach ($params as $key => $value) { $oldValue = is_object($status[$key]) ? $status[$key]->toString() : $status[$key]; $newValue = is_object($value) ? $value->toString() : $value; if ($oldValue != $newValue) { $status[$key] = $value; $needToUpdate = true; } } if ($needToUpdate) { IM\StatusTable::update($userId, $params); } } else { $params['USER_ID'] = $userId; IM\StatusTable::add($params); $needToUpdate = true; $status = $params; } if ($needToUpdate && self::Enable()) { CPullStack::AddShared(array('module_id' => 'online', 'command' => 'user_status', 'params' => self::PrepereToPush($status))); } 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 ($oldRecord["STATUS"] !== $newRecord["STATUS"]) { if (\CIMStatus::Enable()) { \CPullStack::AddShared(array('module_id' => 'online', 'command' => 'user_status', 'expiry' => 120, 'params' => array("USER_ID" => $newRecord["USER_ID"], "STATUS" => $newRecord["STATUS"]))); } } }
public static function Delete($channelId) { global $DB; $arMessage = array('module_id' => 'pull', 'command' => 'channel_die', 'params' => ''); CPullStack::AddByChannel($channelId, $arMessage); $strSql = "DELETE FROM b_pull_channel WHERE CHANNEL_ID = '" . $DB->ForSQL($channelId) . "'"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); return true; }
public static function AddToStack($tag, $arMessage) { global $DB; $result = false; $strSql = "SELECT CHANNEL_ID FROM b_pull_watch WHERE TAG = '" . $DB->ForSQL($tag) . "'"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->Fetch()) { $result = CPullStack::AddByChannel($arRes['CHANNEL_ID'], $arMessage); if (!$result) { break; } } return !$result ? false : true; }
/** * Method will be invoked after new database record inserted. * * @param array $newRecord All fields of inserted record. * * @return void */ public function afterInsertTrigger(array $newRecord) { $id = intval($newRecord['MESSAGE_ID']); if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } $message = \CIMMessenger::GetById($id, array('WITH_FILES' => 'Y')); if (!$message) { return; } if ($newRecord['PARAM_NAME'] === 'LIKE' && $newRecord["PARAM_VALUE"]) { $like = $message['PARAMS']['LIKE']; $result = \Bitrix\IM\ChatTable::getList(array('filter' => array('=ID' => $message['CHAT_ID']))); $chat = $result->fetch(); $relations = \CIMMessenger::GetRelationById($id); if (!isset($relations[$newRecord["PARAM_VALUE"]])) { return; } if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $newRecord["PARAM_VALUE"]) { $CCTP = new \CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $message['MESSAGE'] = str_replace('<br />', ' ', $CCTP->convertText($message['MESSAGE'])); $message['MESSAGE'] = preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/\\[[bui]\\](.*?)\\[\\/[bui]\\]/i", "\$1", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", "\$2", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [" . GetMessage('IM_QUOTE') . "] ", str_replace(array("#BR#"), array(" "), $message['MESSAGE'])); if (count($message['FILES']) > 0 && strlen($message['MESSAGE']) < 200) { foreach ($message['FILES'] as $file) { $file = " [" . GetMessage('IM_MESSAGE_FILE') . ": " . $file['name'] . "]"; if (strlen($message['MESSAGE'] . $file) > 200) { break; } $message['MESSAGE'] .= $file; } $message['MESSAGE'] = trim($message['MESSAGE']); } $isChat = $chat && strlen($chat['TITLE']) > 0; $dot = strlen($message['MESSAGE']) >= 200 ? '...' : ''; $message['MESSAGE'] = substr($message['MESSAGE'], 0, 199) . $dot; $message['MESSAGE'] = strlen($message['MESSAGE']) > 0 ? $message['MESSAGE'] : '-'; $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $message['AUTHOR_ID'], "FROM_USER_ID" => $newRecord["PARAM_VALUE"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|IM|" . ($isChat ? 'G' : 'P') . "|" . ($isChat ? $chat['ID'] : $newRecord["PARAM_VALUE"]) . "|" . $id, "NOTIFY_MESSAGE" => GetMessage($isChat ? 'IM_MESSAGE_LIKE' : 'IM_MESSAGE_LIKE_PRIVATE', array('#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $chat['TITLE']))); \CIMNotify::Add($arMessageFields); } $arPullMessage = array('id' => $id, 'chatId' => $relations[$newRecord["PARAM_VALUE"]]['CHAT_ID'], 'senderId' => $newRecord["PARAM_VALUE"], 'users' => $like); foreach ($relations as $rel) { \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage)); } } }
/** * 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 ($newRecord["MESSAGE_TYPE"] === "P" && intval($oldRecord["LAST_ID"]) < intval($newRecord["LAST_ID"])) { $oldLastRead = $oldRecord["LAST_READ"] instanceof \Bitrix\Main\Type\DateTime ? $oldRecord["LAST_READ"]->getTimestamp() : 0; $newLastRead = $newRecord["LAST_READ"] instanceof \Bitrix\Main\Type\DateTime ? $newRecord["LAST_READ"]->getTimestamp() : 0; if ($oldLastRead < $newLastRead) { if (\Bitrix\Main\Loader::includeModule('pull')) { $relationList = \Bitrix\IM\RelationTable::getList(array("select" => array("ID", "USER_ID"), "filter" => array("=CHAT_ID" => $newRecord["CHAT_ID"], "!=USER_ID" => $newRecord["USER_ID"]))); if ($relation = $relationList->fetch()) { \CPullStack::AddByUser($relation['USER_ID'], array('module_id' => 'im', 'command' => 'readMessageApponent', 'params' => array('chatId' => intval($newRecord['CHAT_ID']), 'userId' => intval($newRecord['USER_ID']), 'lastId' => $newRecord['LAST_ID'], 'date' => $newLastRead, 'count' => 1))); } } } } }
public static function SendPullEvent($params) { // TODO check params if (!CModule::IncludeModule('pull') || !CPullOptions::GetQueueServerStatus() || $params['USER_ID'] <= 0) { return false; } $config = array(); if ($params['COMMAND'] == 'outgoing') { $config = array("callId" => $params['CALL_ID'], "callIdTmp" => $params['CALL_ID_TMP'] ? $params['CALL_ID_TMP'] : '', "callDevice" => $params['CALL_DEVICE'] == 'PHONE' ? 'PHONE' : 'WEBRTC', "phoneNumber" => $params['PHONE_NUMBER'], "external" => $params['EXTERNAL'] ? true : false, "CRM" => $params['CRM'] ? $params['CRM'] : array()); } else { if ($params['COMMAND'] == 'timeout') { $config = array("callId" => $params['CALL_ID'], "failedCode" => intval($params['FAILED_CODE'])); } } CPullStack::AddByUser($params['USER_ID'], array('module_id' => 'voximplant', 'command' => $params['COMMAND'], 'params' => $config)); return true; }
function onExecuteStartWriting(\Bitrix\Main\Event $event) { $parameters = $event->getParameters(); $userId = $parameters[0]; $dialogId = $parameters[1] . $parameters[2]; if ($userId > 0) { if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } \CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS'); if (intval($dialogId) > 0) { \CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId))); } elseif (substr($dialogId, 0, 4) == 'chat') { $arRelation = \CIMChat::GetRelationById(substr($dialogId, 4)); foreach ($arRelation as $rel) { if ($rel['USER_ID'] == $userId) { continue; } \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId))); } } } }
public static function Edit($Params = array()) { global $DB, $CACHE_MANAGER; $arFields = $Params['arFields']; // Get current user id $userId = isset($Params['userId']) && intVal($Params['userId']) > 0 ? intVal($Params['userId']) : CCalendar::GetCurUserId(); if (!$userId && isset($arFields['CREATED_BY'])) { $userId = intVal($arFields['CREATED_BY']); } $path = !empty($Params['path']) ? $Params['path'] : CCalendar::GetPath($arFields['CAL_TYPE'], $arFields['OWNER_ID'], true); if ($userId < 0) { return false; } if (!self::CheckFields($arFields)) { return false; } if ($arFields['CAL_TYPE'] == 'user') { $CACHE_MANAGER->ClearByTag('calendar_user_' . $arFields['OWNER_ID']); } $bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0; $arFields['TIMESTAMP_X'] = CCalendar::Date(mktime(), true, false); if ($bNew) { if (!isset($arFields['CREATED_BY'])) { $arFields['CREATED_BY'] = $userId; } if (!isset($arFields['DATE_CREATE'])) { $arFields['DATE_CREATE'] = $arFields['TIMESTAMP_X']; } } $attendees = is_array($arFields['ATTENDEES']) ? $arFields['ATTENDEES'] : array(); if (!isset($arFields['OWNER_ID']) || !$arFields['OWNER_ID']) { $arFields['OWNER_ID'] = 0; } if (!isset($arFields['LOCATION']['OLD']) && !$bNew) { // Select meeting info about event if (isset($Params['currentEvent'])) { $oldEvent = $Params['currentEvent']; } else { $oldEvent = CCalendarEvent::GetById($arFields['ID']); } if ($oldEvent) { $arFields['LOCATION']['OLD'] = $oldEvent['LOCATION']; } } $offset = CCalendar::GetOffset(); $arFields['LOCATION'] = CCalendar::SetLocation($arFields['LOCATION']['OLD'], $arFields['LOCATION']['NEW'], array('dateFrom' => CCalendar::Date($arFields['DT_FROM_TS'] + $offset), 'dateTo' => CCalendar::Date($arFields['DT_TO_TS'] + $offset), 'name' => $arFields['NAME'], 'persons' => count($attendees), 'attendees' => $attendees, 'bRecreateReserveMeetings' => $arFields['LOCATION']['RE_RESERVE'] !== 'N')); $bSendInvitations = false; if (!isset($arFields['IS_MEETING']) && isset($arFields['ATTENDEES']) && is_array($arFields['ATTENDEES']) && empty($arFields['ATTENDEES'])) { $arFields['IS_MEETING'] = false; } $attendeesCodes = array(); if ($arFields['IS_MEETING'] && is_array($arFields['MEETING'])) { if (!empty($arFields['ATTENDEES_CODES'])) { $attendeesCodes = $arFields['ATTENDEES_CODES']; $arFields['ATTENDEES_CODES'] = implode(',', $arFields['ATTENDEES_CODES']); } // Organizer $bSendInvitations = $Params['bSendInvitations'] !== false; $arFields['~MEETING'] = array('HOST_NAME' => $arFields['MEETING']['HOST_NAME'], 'TEXT' => $arFields['MEETING']['TEXT'], 'OPEN' => $arFields['MEETING']['OPEN'], 'NOTIFY' => $arFields['MEETING']['NOTIFY'], 'REINVITE' => $arFields['MEETING']['REINVITE']); $arFields['MEETING'] = serialize($arFields['~MEETING']); } $arReminders = array(); if ($arFields['REMIND'] && is_array($arFields['REMIND'])) { foreach ($arFields['REMIND'] as $remind) { if (in_array($remind['type'], array('min', 'hour', 'day'))) { $arReminders[] = array('type' => $remind['type'], 'count' => floatVal($remind['count'])); } } } $arFields['REMIND'] = count($arReminders) > 0 ? serialize($arReminders) : ''; $AllFields = self::GetFields(); $dbFields = array(); foreach ($arFields as $field => $val) { if (isset($AllFields[$field]) && $field != "ID") { $dbFields[$field] = $arFields[$field]; } } CTimeZone::Disable(); if ($bNew) { $ID = CDatabase::Add("b_calendar_event", $dbFields, array('DESCRIPTION', 'MEETING', 'RDATE', 'EXDATE')); } else { $ID = $arFields['ID']; $strUpdate = $DB->PrepareUpdate("b_calendar_event", $dbFields); $strSql = "UPDATE b_calendar_event SET " . $strUpdate . " WHERE ID=" . IntVal($arFields['ID']); $DB->QueryBind($strSql, array('DESCRIPTION' => $arFields['DESCRIPTION'], 'MEETING' => $arFields['MEETING'], 'RDATE' => $arFields['RDATE'], 'EXDATE' => $arFields['EXDATE'])); } CTimeZone::Enable(); if ($bNew && !isset($dbFields['DAV_XML_ID'])) { $strSql = "UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array('DAV_XML_ID' => $ID)) . " WHERE ID=" . IntVal($ID); $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } // Clean links // Del link from table if (!$bNew) { $arAffectedSections = CCalendarEvent::GetCurrentSectionIds($ID); $DB->Query("DELETE FROM b_calendar_event_sect WHERE EVENT_ID=" . IntVal($ID), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); } else { $arAffectedSections = array(); } $strSections = "0"; foreach ($arFields['SECTIONS'] as $sect) { if (IntVal($sect) > 0) { $strSections .= "," . IntVal($sect); $arAffectedSections[] = IntVal($sect); } } if (count($arAffectedSections) > 0) { CCalendarSect::UpdateModificationLabel($arAffectedSections); } // We don't have any section for this event // and we have to create default one. if ($strSections == "0") { $defCalendar = CCalendarSect::CreateDefault(array('type' => CCalendar::GetType(), 'ownerId' => CCalendar::GetOwnerId())); $strSections .= "," . IntVal($defCalendar['ID']); } // Add links $strSql = "INSERT INTO b_calendar_event_sect(EVENT_ID, SECT_ID) " . "SELECT " . intVal($ID) . ", ID " . "FROM b_calendar_section " . "WHERE ID in (" . $strSections . ")"; $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); $bPull = CModule::IncludeModule("pull"); if ($arFields['IS_MEETING']) { if (isset($arFields['ATTENDEES'])) { self::InviteAttendees($ID, $arFields, $arFields['ATTENDEES'], is_array($Params['attendeesStatuses']) ? $Params['attendeesStatuses'] : array(), $bSendInvitations, $userId); if ($bPull) { // TODO: CACHE IT! $attendees = self::GetAttendees($ID); $attendees = $attendees[$ID]; foreach ($attendees as $user) { CPullStack::AddByUser($user['USER_ID'], array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => $attendees, 'NEW' => $bNew ? 'Y' : 'N'))); } } } } else { if ($bPull) { CPullStack::AddByUser($userId, array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => array(), 'NEW' => $bNew ? 'Y' : 'N'))); } } // Clean old reminders and add new reminders self::UpdateReminders(array('id' => $ID, 'reminders' => $arReminders, 'arFields' => $arFields, 'userId' => $userId, 'path' => $path, 'bNew' => $bNew)); if ($arFields['CAL_TYPE'] == 'user' && $arFields['IS_MEETING'] && !empty($attendeesCodes)) { CCalendarLiveFeed::OnEditCalendarEventEntry($ID, $arFields, $attendeesCodes); } CCalendar::ClearCache('event_list'); return $ID; }
public static function SendConfigDie() { $arMessage = array('module_id' => 'pull', 'command' => 'config_die', 'params' => ''); CPullStack::AddBroadcast($arMessage); }
public function Confirm($ID, $VALUE) { global $DB; $ID = intval($ID); $strSql = "SELECT M.* FROM b_im_relation R, b_im_message M WHERE M.ID = ".$ID." AND R.USER_ID = ".$this->user_id." AND R.MESSAGE_TYPE = '".IM_MESSAGE_SYSTEM."' AND R.CHAT_ID = M.CHAT_ID AND M.NOTIFY_TYPE = ".IM_NOTIFY_CONFIRM; $dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($arRes = $dbRes->Fetch()) { $arRes['RELATION_USER_ID'] = $this->user_id; if (strlen($arRes['NOTIFY_TAG'])>0) { foreach(GetModuleEvents("im", "OnBeforeConfirmNotify", true) as $arEvent) if (ExecuteModuleEventEx($arEvent, Array($arRes['NOTIFY_MODULE'], $arRes['NOTIFY_TAG'], $VALUE, $arRes))===false) return false; } $strSql = "DELETE FROM b_im_message WHERE ID = ".$ID; $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); //CUserCounter::Decrement($this->user_id, 'im_notify', '**', false); if (strlen($arRes['NOTIFY_TAG'])>0) { foreach(GetModuleEvents("im", "OnAfterConfirmNotify", true) as $arEvent) ExecuteModuleEventEx($arEvent, array($arRes['NOTIFY_MODULE'], $arRes['NOTIFY_TAG'], $VALUE, $arRes)); } if (CModule::IncludeModule("pull")) { CPullStack::AddByUser($this->user_id, Array( 'module_id' => 'im', 'command' => 'confirmNotify', 'params' => Array( 'chatId' => intval($arRes['CHAT_ID']), 'id' => $ID ), )); //CIMMessenger::SendBadges($this->user_id); } CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_NOTIFY); return true; } return false; }
public static function Command($chatId, $recipientId, $command, $params = Array()) { if (!CModule::IncludeModule("pull")) return false; $chatId = intval($chatId); $recipientId = intval($recipientId); if ($recipientId <= 0 || $chatId <= 0 || empty($command) || !is_array($params)) return false; global $USER; $params['senderId'] = $USER->GetID(); $params['chatId'] = $chatId; $params['command'] = $command; CPullStack::AddByUser($recipientId, Array( 'module_id' => 'im', 'command' => 'call', 'params' => $params, )); return true; }
public function SetReadMessage($fromUserId, $lastId = null) { global $DB; $fromUserId = intval($fromUserId); if ($fromUserId <= 0) { return false; } $bReadMessage = false; if ($lastId == null) { $strSql = "\n\t\t\t\tSELECT MAX(M.ID) ID, M.CHAT_ID\n\t\t\t\tFROM b_im_relation RF\n\t\t\t\t\tINNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID\n\t\t\t\t\tINNER JOIN b_im_message M ON M.ID >= RT.LAST_ID AND M.CHAT_ID = RT.CHAT_ID\n\t\t\t\tWHERE RT.USER_ID = " . $this->user_id . "\n\t\t\t\t\tand RF.USER_ID = " . $fromUserId . "\n\t\t\t\t\tand RT.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "' and RT.STATUS < " . IM_STATUS_READ . "\n\t\t\t\tGROUP BY M.CHAT_ID"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, $arRes['ID']); } $lastId = $arRes['ID']; } else { $strSql = "\n\t\t\t\tSELECT RF.CHAT_ID\n\t\t\t\tFROM b_im_relation RF INNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID\n\t\t\t\tWHERE RT.USER_ID = " . $this->user_id . "\n\t\t\t\t\tand RF.USER_ID = " . $fromUserId . "\n\t\t\t\t\tand RT.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "'"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, intval($lastId)); } } if ($bReadMessage) { CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_MESSAGE); if (CModule::IncludeModule("pull")) { CPushManager::DeleteFromQueue($this->user_id, 'IM_MESS_' . $fromUserId); CPullStack::AddByUser($this->user_id, array('module_id' => 'im', 'command' => 'readMessage', 'params' => array('chatId' => intval($arRes['CHAT_ID']), 'senderId' => $this->user_id, 'id' => $fromUserId, 'userId' => $fromUserId, 'lastId' => $lastId))); } return true; } return false; }
public static function CancelRatingVote($arParam) { global $DB, $CACHE_MANAGER; $err_mess = CRatings::err_mess() . "<br>Function: CancelRatingVote<br>Line: "; $sqlStr = "\n\t\t\tSELECT\n\t\t\t\tRVG.ID,\n\t\t\t\tRV.ID AS VOTE_ID,\n\t\t\t\tRV.VALUE AS VOTE_VALUE,\n\t\t\t\tRVG.TOTAL_POSITIVE_VOTES\n\t\t\tFROM\n\t\t\t\tb_rating_voting RVG,\n\t\t\t\tb_rating_vote RV\n\t\t\tWHERE\n\t\t\t\tRVG.ENTITY_TYPE_ID = '" . $DB->ForSql($arParam['ENTITY_TYPE_ID']) . "'\n\t\t\tand RVG.ENTITY_ID = " . intval($arParam['ENTITY_ID']) . "\n\t\t\tand RVG.ID = RV.RATING_VOTING_ID\n\t\t\tand RV.USER_ID = " . intval($arParam['USER_ID']); $res = $DB->Query($sqlStr, false, $err_mess . __LINE__); if ($arVote = $res->Fetch()) { $votePlus = $arVote['VOTE_VALUE'] >= 0 ? true : false; $arFields = array('TOTAL_VOTES' => "TOTAL_VOTES-1", 'TOTAL_VALUE' => "TOTAL_VALUE" . ($votePlus ? '-' . floatval($arVote['VOTE_VALUE']) : '+' . floatval(-1 * $arVote['VOTE_VALUE'])), 'LAST_CALCULATED' => $DB->GetNowFunction()); $arFields[$votePlus ? 'TOTAL_POSITIVE_VOTES' : 'TOTAL_NEGATIVE_VOTES'] = $votePlus ? 'TOTAL_POSITIVE_VOTES-1' : 'TOTAL_NEGATIVE_VOTES-1'; $DB->Update("b_rating_voting", $arFields, "WHERE ID=" . intval($arVote['ID']), $err_mess . __LINE__); $DB->Query("DELETE FROM b_rating_vote WHERE ID=" . intval($arVote['VOTE_ID']), false, $err_mess . __LINE__); foreach (GetModuleEvents("main", "OnCancelRatingVote", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(intval($arVote['VOTE_ID']), $arParam)); } if (CModule::IncludeModule('pull')) { CPullStack::AddShared(array('module_id' => 'main', 'command' => 'rating_vote', 'params' => array("TYPE" => "CANCEL", "USER_ID" => intval($arParam['USER_ID']), "ENTITY_TYPE_ID" => $arParam["ENTITY_TYPE_ID"], "ENTITY_ID" => intval($arParam['ENTITY_ID']), "TOTAL_POSITIVE_VOTES" => intval($arVote['TOTAL_POSITIVE_VOTES'] + ($votePlus ? -1 : 1)), "RESULT" => $votePlus ? 'PLUS' : 'MINUS'))); } if (CACHED_b_rating_vote !== false) { $bucket_size = intval(CACHED_b_rating_bucket_size); if ($bucket_size <= 0) { $bucket_size = 100; } $bucket = intval(intval($arParam['ENTITY_ID']) / $bucket_size); $CACHE_MANAGER->Clean("b_rvg_" . $DB->ForSql($arParam["ENTITY_TYPE_ID"]) . $bucket, "b_rating_voting"); } return true; } return false; }
public function DeleteUser($chatId, $userId, $checkPermission = true) { global $DB; $chatId = intval($chatId); $userId = intval($userId); if ($chatId <= 0 || $userId <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_OR_CHAT"), "EMPTY_USER_OR_CHAT"); 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 = " . $userId . " 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']); if ($chatAuthorId == $userId) { $strSql = "\n\t\t\t\t\tSELECT R.USER_ID\n\t\t\t\t\tFROM b_im_relation R\n\t\t\t\t\tWHERE R.CHAT_ID = " . $chatId . " AND R.USER_ID <> " . $chatAuthorId; $strSql = $DB->TopSql($strSql, 1); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $strSql = "UPDATE b_im_chat SET AUTHOR_ID = " . $arRes['USER_ID'] . " WHERE ID = " . $chatId; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } $bSelf = true; $arUsers = array($userId); if (is_object($GLOBALS["USER"]) && $GLOBALS["USER"]->GetId() != $userId) { if ($checkPermission && $chatAuthorId != $GLOBALS["USER"]->GetId()) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_KICK"), "IM_ERROR_KICK"); return false; } $bSelf = false; $arUsers[] = $GLOBALS["USER"]->GetId(); } $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER"); $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => implode('|', $arUsers)), array('FIELDS' => $arSelect)); $arUsers = array(); while ($arUser = $dbUsers->Fetch()) { $arUsers[$arUser['ID']]['NAME'] = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false); $arUsers[$arUser['ID']]['GENDER'] = $arUser["PERSONAL_GENDER"] == 'F' ? 'F' : 'M'; } if ($bSelf) { $message = GetMessage("IM_CHAT_LEAVE_" . $arUsers[$userId]['GENDER'], array('#USER_NAME#' => $arUsers[$userId]['NAME'])); } else { $message = GetMessage("IM_CHAT_KICK_" . $arUsers[$GLOBALS["USER"]->GetId()]['GENDER'], array('#USER_1_NAME#' => $arUsers[$GLOBALS["USER"]->GetId()]['NAME'], '#USER_2_NAME#' => $arUsers[$userId]['NAME'])); } $arOldRelation = array(); if (CModule::IncludeModule("pull")) { $arOldRelation = CIMChat::GetRelationById($chatId); } $CIMChat = new CIMChat($userId); $CIMChat->SetReadMessage($chatId); CIMContactList::CleanChatCache($userId); $strSql = "DELETE FROM b_im_relation WHERE CHAT_ID = " . $chatId . " AND USER_ID = " . $userId; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); CIMDisk::ChangeFolderMembers($chatId, $userId, false); self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y')); foreach ($arOldRelation as $rel) { CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserLeave', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'userId' => $userId, 'message' => $bSelf ? '' : htmlspecialcharsbx($message)))); } CIMContactList::DeleteRecent($chatId, true, $userId); return true; } $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_USER_NOT_FOUND"), "USER_NOT_FOUND"); return false; }
public static function OnAfterUserLogout($arParams) { if (!CPullOptions::GetQueueServerStatus()) return false; if ($arParams['USER_ID'] <= 0) return false; $arParams['USER_ID'] = intval($arParams['USER_ID']); if (isset($_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']]) && intval($_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']])+100 > time()) return false; $_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']] = time(); unset($_SESSION['USER_LAST_AUTH_'.$arParams['USER_ID']]); $arChannel = CPullChannel::GetChannel($arParams['USER_ID']); $result = CPullChannel::Send($arChannel['CHANNEL_ID'], 'ping', 'GET', 5, false); if (is_object($result) && isset($result->infos[0])) { $sendOffline = $result->infos[0]->subscribers > 0? false: true; } else { $sendOffline = true; } if ($sendOffline) { CPullStack::AddShared(Array( 'module_id' => 'online', 'command' => 'user_offline', 'params' => Array( 'USER_ID' => $arParams['USER_ID'] ), )); } return true; }
public static function AddToStack($tag, $arMessage) { global $DB; $arPush = array(); if (isset($arMessage['push'])) { $arPush = $arMessage['push']; unset($arMessage['push']); } $channels = array(); $strSql = "\n\t\t\t\tSELECT pc.CHANNEL_ID, pc.USER_ID\n\t\t\t\tFROM b_pull_watch pw\n\t\t\t\tLEFT JOIN b_pull_channel pc ON pw.USER_ID = pc.USER_ID\n\t\t\t\tWHERE pw.TAG = '" . $DB->ForSQL($tag) . "'\n\t\t"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->Fetch()) { $channels[$arRes['USER_ID']] = $arRes['CHANNEL_ID']; } $result = CPullStack::AddByChannel($channels, $arMessage); if ($result && !empty($arPush) && (isset($arPush['advanced_params']) || isset($arPush['message']) && strlen($arPush['message']) > 0)) { $CPushManager = new CPushManager(); $pushUsers = array(); foreach ($channels as $userId => $channelId) { if (isset($arPush['skip_users']) && in_array($userId, $arPush['skip_users'])) { continue; } $pushUsers[] = $userId; } $CPushManager->AddQueue(array('USER_ID' => $pushUsers, 'MESSAGE' => str_replace("\n", " ", $arPush['message']), 'PARAMS' => $arPush['params'], 'ADVANCED_PARAMS' => isset($arPush['advanced_params']) ? $arPush['advanced_params'] : array(), 'BADGE' => isset($arPush['badge']) ? intval($arPush['badge']) : '', 'SOUND' => isset($arPush['sound']) ? $arPush['sound'] : '', 'TAG' => isset($arPush['tag']) ? $arPush['tag'] : '', 'SUB_TAG' => isset($arPush['sub_tag']) ? $arPush['sub_tag'] : '', 'APP_ID' => isset($arPush['app_id']) ? $arPush['app_id'] : '', 'SEND_IMMEDIATELY' => isset($arPush['send_immediately']) && $arPush['send_immediately'] == 'Y' ? 'Y' : 'N')); } return true; }
public static function SendPullEvent($params) { // TODO check $params if (!CModule::IncludeModule('pull') || !CPullOptions::GetQueueServerStatus() || $params['USER_ID'] <= 0) { return false; } $config = array(); $push = array(); if ($params['COMMAND'] == 'invite') { $config = array("callId" => $params['CALL_ID'], "callerId" => $params['CALLER_ID'], "phoneNumber" => $params['PHONE_NAME'], "chatId" => 0, "chat" => array(), "typeConnect" => $params['TYPE_CONNECT'], "portalCall" => $params['PORTAL_CALL'] == 'Y' ? true : false, "portalCallUserId" => $params['PORTAL_CALL'] == 'Y' ? $params['PORTAL_CALL_USER_ID'] : 0, "portalCallData" => $params['PORTAL_CALL'] == 'Y' ? $params['PORTAL_CALL_DATA'] : array(), "config" => $params['CONFIG'] ? $params['CONFIG'] : array(), "CRM" => $params['CRM']); $callName = $params['CALLER_ID']; if (isset($params['CRM']['CONTACT']['NAME']) && strlen($params['CRM']['CONTACT']['NAME']) > 0) { $callName = $params['CRM']['CONTACT']['NAME']; } if (isset($params['CRM']['COMPANY']) && strlen($params['CRM']['COMPANY']) > 0) { $callName .= ' (' . $params['CRM']['COMPANY'] . ')'; } else { if (isset($params['CRM']['CONTACT']['POST']) && strlen($params['CRM']['CONTACT']['POST']) > 0) { $callName .= ' (' . $params['CRM']['CONTACT']['POST'] . ')'; } } $push['sub_tag'] = 'VI_CALL_' . $params['CALL_ID']; $push['send_immediately'] = 'Y'; $push['sound'] = 'call.aif'; $push['advanced_params'] = array("notificationsToCancel" => array('VI_CALL_' . $params['CALL_ID']), "androidHighPriority" => true); if ($params['PORTAL_CALL'] == 'Y') { $push['message'] = GetMessage('INCOMING_CALL', array('#NAME#' => $params['PORTAL_CALL_DATA']['users'][$params['PORTAL_CALL_USER_ID']]['name'])); } else { $push['message'] = GetMessage('INCOMING_CALL', array('#NAME#' => $callName)); $push['message'] = $push['message'] . ' ' . GetMessage('CALL_FOR_NUMBER', array('#NUMBER#' => $params['PHONE_NAME'])); } $push['params'] = array('ACTION' => 'VI_CALL_' . $params['CALL_ID'], 'PARAMS' => $config); } else { if ($params['COMMAND'] == 'update_crm') { $config = array("callId" => $params['CALL_ID'], "CRM" => $params['CRM']); } else { if ($params['COMMAND'] == 'timeout' || $params['COMMAND'] == 'answer_self') { $config = array("callId" => $params['CALL_ID']); $push['send_immediately'] = 'Y'; $push['advanced_params'] = array("notificationsToCancel" => array('VI_CALL_' . $params['CALL_ID'])); } } } if (isset($params['MARK'])) { $config['mark'] = $params['MARK']; } CPullStack::AddByUser($params['USER_ID'], array('module_id' => 'voximplant', 'command' => $params['COMMAND'], 'params' => $config, 'push' => $push)); return true; }
public function SetReadMessage($fromUserId, $lastId = null) { global $DB; $fromUserId = intval($fromUserId); if ($fromUserId <= 0) return false; $sqlLastId = ''; if (intval($lastId) > 0) $sqlLastId = "AND M.ID <= ".intval($lastId); $strSql = " SELECT COUNT(M.ID) CNT, MAX(M.ID) ID, M.CHAT_ID FROM b_im_relation RF INNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID INNER JOIN b_im_message M ON M.ID > RT.LAST_ID ".$sqlLastId." AND M.CHAT_ID = RT.CHAT_ID WHERE RT.USER_ID = ".$this->user_id." and RF.USER_ID = ".$fromUserId." and RT.MESSAGE_TYPE = '".IM_MESSAGE_PRIVATE."' and RT.STATUS < ".IM_STATUS_READ." GROUP BY M.CHAT_ID"; $dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($arRes = $dbRes->Fetch()) { $bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, $arRes['ID']); if ($bReadMessage) { //CUserCounter::Decrement($this->user_id, 'im_message_v2', '**', false, $arRes['CNT']); CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_MESSAGE); if (CModule::IncludeModule("pull")) { CPushManager::DeleteFromQueueBySubTag($this->user_id, 'IM_MESS'); CPullStack::AddByUser($this->user_id, Array( 'module_id' => 'im', 'command' => 'readMessage', 'params' => Array( 'chatId' => intval($arRes['CHAT_ID']), 'senderId' => $this->user_id, 'id' => $fromUserId, 'userId' => $fromUserId, 'lastId' => $arRes['ID'], 'count' => $arRes['CNT'] ), )); CPullStack::AddByUser($fromUserId, Array( 'module_id' => 'im', 'command' => 'readMessageApponent', 'params' => Array( 'chatId' => intval($arRes['CHAT_ID']), 'userId' => $this->user_id, 'lastId' => $arRes['ID'], 'date' => time(), 'count' => $arRes['CNT'] ), )); CIMMessenger::SendBadges($this->user_id); } return true; } } return false; }
public static function SendPullEvent($params) { if (!CModule::IncludeModule('pull') || !CPullOptions::GetQueueServerStatus() || $params['USER_ID'] <= 0) { return false; } $config = array(); $push = array(); if ($params['COMMAND'] == 'start') { $config = array("callId" => $params['CALL_ID'], "callDevice" => $params['CALL_DEVICE'] == 'PHONE' ? 'PHONE' : 'WEBRTC', "external" => $params['EXTERNAL'] ? true : false, "CRM" => $params['CRM'] ? $params['CRM'] : false); } else { if ($params['COMMAND'] == 'hold' || $params['COMMAND'] == 'unhold') { $config = array("callId" => $params['CALL_ID']); } else { if ($params['COMMAND'] == 'timeout') { $config = array("callId" => $params['CALL_ID']); $push['send_immediately'] = 'Y'; $push['advanced_params'] = array("notificationsToCancel" => array('VI_CALL_' . $params['CALL_ID'])); } } } if (isset($params['MARK'])) { $config['mark'] = $params['MARK']; } CPullStack::AddByUser($params['USER_ID'], array('module_id' => 'voximplant', 'command' => $params['COMMAND'], 'params' => $config, 'push' => $push)); return true; }
public static function StartWriting($dialogId) { global $USER; if ($USER->GetID() > 0 && strlen($dialogId) > 0 && CModule::IncludeModule("pull")) { CPushManager::DeleteFromQueueBySubTag($USER->GetID(), 'IM_MESS'); if (intval($dialogId) > 0) { CPullStack::AddByUser($dialogId, Array( 'module_id' => 'im', 'command' => 'startWriting', 'params' => Array( 'senderId' => $USER->GetID(), 'dialogId' => $dialogId ), )); } elseif (substr($dialogId, 0, 4) == 'chat') { $arRelation = CIMChat::GetRelationById(substr($dialogId, 4)); foreach ($arRelation as $rel) { if ($rel['USER_ID'] == $USER->GetID()) continue; CPullStack::AddByUser($rel['USER_ID'], Array( 'module_id' => 'im', 'command' => 'startWriting', 'params' => Array( 'senderId' => $USER->GetID(), 'dialogId' => $dialogId ), )); } } return true; } return false; }
public static function UploadAvatar($hash, &$file, &$package, &$upload, &$error) { $post = \Bitrix\Main\Context::getCurrent()->getRequest()->getPostList()->toArray(); $chatId = intval($post['CHAT_ID']); if ($chatId <= 0) { return false; } $chat = IM\ChatTable::getById($chatId)->fetch(); if (!$chat) { return false; } $relationError = true; $chatRelation = CIMChat::GetRelationById($chatId); foreach ($chatRelation as $relation) { if ($relation['USER_ID'] == self::GetUserId()) { $relationError = false; break; } } if ($relationError) { $error = GetMessage('IM_DISK_ERR_AVATAR_1'); return false; } $fileId = CFile::saveFile($file["files"]["default"], self::MODULE_ID); if ($fileId > 0) { if ($chat['AVATAR'] > 0) { CFile::DeLete($chat['AVATAR']); } IM\ChatTable::update($chatId, array('AVATAR' => $fileId)); $file['chatId'] = $chatId; $file['chatAvatar'] = CIMChat::GetAvatarImage($fileId); if ($chat["ENTITY_TYPE"] != 'CALL') { CIMChat::AddSystemMessage(array('CHAT_ID' => $chatId, 'USER_ID' => self::GetUserId(), 'MESSAGE_CODE' => 'IM_DISK_AVATAR_CHANGE_')); } if (CModule::IncludeModule('pull')) { $pullMessage = array('module_id' => 'im', 'command' => 'chatAvatar', 'params' => array('chatId' => $chatId, 'chatAvatar' => $file['chatAvatar'])); CPullStack::AddByUsers(array_keys($chatRelation), $pullMessage); $orm = \Bitrix\Im\ChatTable::getById($chatId); $chat = $orm->fetch(); if ($chat['TYPE'] == IM_MESSAGE_OPEN) { CPullWatch::AddToStack('IM_PUBLIC_' . $chat['ID'], $pullMessage); } } } else { return false; } return true; }
public function DeleteUser($chatId, $userId, $checkPermission = true) { global $DB; $chatId = intval($chatId); $userId = intval($userId); if ($chatId <= 0 || $userId <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_OR_CHAT"), "EMPTY_USER_OR_CHAT"); return false; } $strSql = "\n\t\t\tSELECT R.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 LEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID\n\t\t\tWHERE R.USER_ID = " . $userId . " AND R.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "') AND R.CHAT_ID = " . $chatId; $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']; $chatType = $arRes['CHAT_TYPE']; $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']); if ($chatAuthorId == $userId) { $strSql = "\n\t\t\t\t\tSELECT R.USER_ID\n\t\t\t\t\tFROM b_im_relation R\n\t\t\t\t\tWHERE R.CHAT_ID = " . $chatId . " AND R.USER_ID <> " . $chatAuthorId; $strSql = $DB->TopSql($strSql, 1); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { $strSql = "UPDATE b_im_chat SET AUTHOR_ID = " . $arRes['USER_ID'] . " WHERE ID = " . $chatId; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } $bSelf = true; $arUsers = array($userId); if (is_object($GLOBALS["USER"]) && $GLOBALS["USER"]->GetId() != $userId) { if ($checkPermission && $chatAuthorId != $GLOBALS["USER"]->GetId()) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_KICK"), "IM_ERROR_KICK"); return false; } $bSelf = false; $arUsers[] = $GLOBALS["USER"]->GetId(); } $arOldRelation = CIMChat::GetRelationById($chatId); $arUsers = CIMContactList::GetUserData(array('ID' => array_keys($arOldRelation), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'N')); $arUsers = $arUsers['users']; if ($bSelf) { $message = GetMessage("IM_CHAT_LEAVE_" . $arUsers[$userId]['gender'], array('#USER_NAME#' => htmlspecialcharsback($arUsers[$userId]['name']))); } else { $message = GetMessage("IM_CHAT_KICK_" . $arUsers[$GLOBALS["USER"]->GetId()]['gender'], array('#USER_1_NAME#' => htmlspecialcharsback($arUsers[$GLOBALS["USER"]->GetId()]['name']), '#USER_2_NAME#' => htmlspecialcharsback($arUsers[$userId]['name']))); } $CIMChat = new CIMChat($userId); $CIMChat->SetReadMessage($chatId); CIMContactList::CleanChatCache($userId); $publicPullWatch = false; if ($chatType == IM_MESSAGE_OPEN && CModule::IncludeModule("pull")) { $publicPullWatch = true; } $relationList = IM\RelationTable::getList(array("select" => array("ID", "USER_ID"), "filter" => array("=CHAT_ID" => $chatId, "=USER_ID" => $userId))); while ($relation = $relationList->fetch()) { if ($publicPullWatch && !$arUsers[$relation["USER_ID"]]['extranet']) { CPullWatch::Add($relation["USER_ID"], 'IM_PUBLIC_' . $chatId, true); } Im\RelationTable::delete($relation["ID"]); CIMContactList::DeleteRecent($chatId, true, $relation["USER_ID"]); if ($extranetFlag !== false) { $isExtranet = false; foreach ($arUsers as $userData) { if ($userData['id'] == $userId) { continue; } if ($userData['extranet']) { $isExtranet = true; break; } } if (!$isExtranet || $extranetFlag === "") { IM\ChatTable::update($chatId, array('EXTRANET' => $isExtranet ? "Y" : "N")); } $extranetFlag = $isExtranet; } } CIMDisk::ChangeFolderMembers($chatId, $userId, false); self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y')); foreach ($arOldRelation as $rel) { CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserLeave', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'userId' => $userId, 'message' => $bSelf ? '' : htmlspecialcharsbx($message)))); } return true; } $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_USER_NOT_FOUND"), "USER_NOT_FOUND"); return false; }
'ERROR' => '', )); } else echo CUtil::PhpToJsObject(Array('ERROR' => 'ERROR_OPEN_CHANNEL')); } elseif ($_POST['PULL_UPDATE_WATCH'] == 'Y') { foreach ($_POST['WATCH'] as $tag) CPullWatch::Extend($USER->GetID(), $tag); echo CUtil::PhpToJsObject(Array('ERROR' => '')); } elseif ($_POST['PULL_UPDATE_STATE'] == 'Y') { $arMessage = CPullStack::Get($_POST['CHANNEL_ID'], intval($_POST['CHANNEL_LAST_ID'])); $arResult["COUNTERS"] = CUserCounter::GetAllValues($USER->GetID()); if (!empty($arResult["COUNTERS"])) { $arMessage[] = Array( 'module_id' => 'main', 'command' => 'user_counter', 'params' => $arResult["COUNTERS"] ); } echo CUtil::PhpToJsObject(Array('MESSAGE' => $arMessage, 'ERROR' => '')); } else { echo CUtil::PhpToJsObject(Array('ERROR' => 'UNKNOWN_ERROR'));
public static function IncrementWithSelect($sub_select, $sendPull = true) { global $DB, $CACHE_MANAGER, $APPLICATION; if (strlen($sub_select) > 0) { $pullInclude = $sendPull && self::CheckLiveMode(); $strSQL = " INSERT INTO b_user_counter (USER_ID, CNT, SITE_ID, CODE, SENT) (".$sub_select.") ON DUPLICATE KEY UPDATE CNT = CNT + VALUES(CNT), SENT = VALUES(SENT) "; $DB->Query($strSQL, false, "FILE: ".__FILE__."<br> LINE: ".__LINE__); self::$counters = false; $CACHE_MANAGER->CleanDir("user_counter"); if ($pullInclude) { $db_lock = $DB->Query("SELECT GET_LOCK('".$APPLICATION->GetServerUniqID()."_pull', 0) as L"); $ar_lock = $db_lock->Fetch(); if($ar_lock["L"] > 0) { $arSites = Array(); $res = CSite::GetList(($b = ""), ($o = ""), Array("ACTIVE" => "Y")); while($row = $res->Fetch()) $arSites[] = $row['ID']; $strSQL = " SELECT distinct pc.CHANNEL_ID, uc1.USER_ID, uc1.SITE_ID, uc1.CODE, uc1.CNT FROM b_user_counter uc INNER JOIN b_user_counter uc1 ON uc1.USER_ID = uc.USER_ID AND uc1.CODE = uc.CODE INNER JOIN b_pull_channel pc ON pc.USER_ID = uc.USER_ID WHERE uc.SENT = '0' "; $res = $DB->Query($strSQL, false, "FILE: ".__FILE__."<br> LINE: ".__LINE__); $pullMessage = Array(); while($row = $res->Fetch()) { if ($row['SITE_ID'] == '**') { foreach($arSites as $siteId) { if (isset($pullMessage[$row['CHANNEL_ID']][$siteId][$row['CODE']])) $pullMessage[$row['CHANNEL_ID']][$siteId][$row['CODE']] += intval($row['CNT']); else $pullMessage[$row['CHANNEL_ID']][$siteId][$row['CODE']] = intval($row['CNT']); } } else { if (isset($pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$row['CODE']])) $pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$row['CODE']] += intval($row['CNT']); else $pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$row['CODE']] = intval($row['CNT']); } } $DB->Query("UPDATE b_user_counter SET SENT = '1' WHERE SENT = '0'"); $DB->Query("SELECT RELEASE_LOCK('".$APPLICATION->GetServerUniqID()."_pull')"); foreach ($pullMessage as $channelId => $arMessage) { CPullStack::AddByChannel($channelId, Array( 'module_id' => 'main', 'command' => 'user_counter', 'params' => $arMessage, )); } } } } }
/** * 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 SendPullEvent($params) { if (!CModule::IncludeModule('pull') || !CPullOptions::GetQueueServerStatus() || $params['USER_ID'] <= 0) { return false; } if (empty($params['COMMAND'])) { return false; } $config = array(); if ($params['COMMAND'] == 'inviteTransfer') { $config = array("callId" => $params['CALL_ID'], "callerId" => $params['CALLER_ID'], "phoneNumber" => $params['PHONE_NAME'], "chatId" => 0, "chat" => array(), "application" => $params['APPLICATION'], "CRM" => $params['CRM']); } else { if ($params['COMMAND'] == 'completeTransfer') { $config = array("callId" => $params['CALL_ID'], "transferUserId" => $params['TRANSFER_USER_ID'], "callDevice" => $params['CALL_DEVICE'], "CRM" => $params['CRM'] ? $params['CRM'] : false); } else { $config["callId"] = $params['CALL_ID']; } } if (isset($params['MARK'])) { $config['mark'] = $params['MARK']; } CPullStack::AddByUser($params['USER_ID'], array('module_id' => 'voximplant', 'command' => $params['COMMAND'], 'params' => $config)); return true; }
protected static function SendPullEvent($user_id, $code = "") { $user_id = intval($user_id); if ($user_id <= 0) return false; if (self::CheckLiveMode()) { global $DB; $arSites = Array(); $res = CSite::GetList(($b = ""), ($o = ""), Array("ACTIVE" => "Y")); while ($row = $res->Fetch()) $arSites[] = $row['ID']; $strSQL = " SELECT pc.CHANNEL_ID, uc.USER_ID, uc.SITE_ID, uc.CODE, uc.CNT FROM b_user_counter uc INNER JOIN b_pull_channel pc ON pc.USER_ID = uc.USER_ID WHERE uc.USER_ID = ".intval($user_id).(strlen($code) > 0? " AND uc.CODE = '".$DB->ForSQL($code)."'": "")." "; $res = $DB->Query($strSQL, false, "FILE: ".__FILE__."<br> LINE: ".__LINE__); $pullMessage = Array(); while ($row = $res->Fetch()) { if ($row['SITE_ID'] == '**') { foreach ($arSites as $siteId) { if (isset($pullMessage[$row['CHANNEL_ID']][$siteId][$row['CODE']])) $pullMessage[$row['CHANNEL_ID']][$siteId][$row['CODE']] += intval($row['CNT']); else $pullMessage[$row['CHANNEL_ID']][$siteId][$row['CODE']] = intval($row['CNT']); } } else { if (isset($pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$row['CODE']])) $pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$row['CODE']] += intval($row['CNT']); else $pullMessage[$row['CHANNEL_ID']][$row['SITE_ID']][$row['CODE']] = intval($row['CNT']); } } foreach ($pullMessage as $channelId => $arMessage) { CPullStack::AddByChannel($channelId, Array( 'module_id' => 'main', 'command' => 'user_counter', 'params' => $arMessage, )); } } }