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'])); } } }
/** * 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)); } } }
public static function Like($id, $action = 'auto') { global $USER; if (!CModule::IncludeModule('pull')) return false; $action = in_array($action, Array('plus', 'minus'))? $action: 'auto'; $message = self::GetById($id, Array('WITH_FILES' => 'Y')); if (!$message) return false; $relations = CIMMessenger::GetRelationById($id); if (!isset($relations[$USER->GetId()])) return false; $isLike = false; if (isset($message['PARAMS']['LIKE'])) { $isLike = in_array($USER->GetId(), $message['PARAMS']['LIKE']); } if ($isLike && $action == 'plus') { return false; } else if (!$isLike && $action == 'minus') { return false; } $isLike = true; if (isset($message['PARAMS']['LIKE'])) { $like = $message['PARAMS']['LIKE']; $selfLike = array_search($USER->GetId(), $like); if ($selfLike !== false) { $isLike = false; unset($like[$selfLike]); } else { $like[] = $USER->GetId(); } } else { $like = Array($USER->GetId()); } sort($like); CIMMessageParam::Set($id, Array('LIKE' => $like)); $result = IM\ChatTable::getList(Array( 'filter'=>Array( '=ID' => $message['CHAT_ID'] ) )); $chat = $result->fetch(); if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $USER->GetId() && $isLike) { $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'])); 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; $arMessageFields = array( "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $message['AUTHOR_ID'], "FROM_USER_ID" => $USER->GetId(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|IM|".($isChat? 'G':'P')."|".($isChat? $chat['ID']: $USER->GetId())."|".$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[$USER->GetId()]['CHAT_ID'], 'senderId' => $USER->GetId(), 'users' => $like ); foreach ($relations as $rel) { CPullStack::AddByUser($rel['USER_ID'], Array( 'module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage )); } return $like; }
public function GetDialogInfo($phone, $chatTitle = '', $getPhoto = true) { $phoneNormalize = CVoxImplantPhone::Normalize($phone); if (!$phoneNormalize) { $phoneNormalize = preg_replace("/[^0-9\\#\\*]/i", "", $phone); } $phone = $phoneNormalize; $hrPhoto = array(); $openChat = true; $result = VI\PhoneTable::getList(array('select' => array('USER_ID', 'PHONE_MNEMONIC'), 'filter' => array('=PHONE_NUMBER' => $phone))); $userId = false; while ($row = $result->fetch()) { if (!$userId && $row['PHONE_MNEMONIC'] != 'WORK_PHONE') { $userId = $row['USER_ID']; $openChat = false; } else { if (!$userId && $row['PHONE_MNEMONIC'] == 'WORK_PHONE') { $openChat = true; } } } if ($userId == $this->userId) { $openChat = true; } $dialogId = 0; if (CModule::IncludeModule('im')) { if (CVoxImplantConfig::GetChatAction() == CVoxImplantConfig::INTERFACE_CHAT_NONE) { } else { if ($openChat) { $entityId = $phone; if (CVoxImplantConfig::GetChatAction() == CVoxImplantConfig::INTERFACE_CHAT_APPEND) { $entityId = 'UNIFY_CALL_CHAT'; $chatTitle = GetMessage('VI_CALL_CHAT_UNIFY'); } $result = IM\ChatTable::getList(array('select' => array('ID', 'AVATAR'), 'filter' => array('=ENTITY_TYPE' => 'CALL', '=ENTITY_ID' => $entityId, '=AUTHOR_ID' => $this->userId))); if ($row = $result->fetch()) { $dialogId = 'chat' . $row['ID']; $avatarId = $row['AVATAR']; } else { $CIMChat = new CIMChat($this->userId); $chatId = $CIMChat->Add(array('TITLE' => $chatTitle != '' ? $chatTitle : $phone, 'USERS' => false, 'CALL_NUMBER' => $entityId == 'UNIFY_CALL_CHAT' ? '' : $entityId, 'ENTITY_TYPE' => 'CALL', 'ENTITY_ID' => $entityId)); if ($chatId) { $dialogId = 'chat' . $chatId; $avatarId = $CIMChat->lastAvatarId; } } if ($getPhoto && intval($avatarId) > 0) { $arPhotoHrTmp = CFile::ResizeImageGet($avatarId, array('width' => 200, 'height' => 200), BX_RESIZE_IMAGE_EXACT, false, false, true); $hrPhoto[$dialogId] = empty($arPhotoHrTmp['src']) ? '/bitrix/js/im/images/hidef-avatar-v2.png' : $arPhotoHrTmp['src']; } } else { if ($userId) { if ($getPhoto) { $userData = CIMContactList::GetUserData(array('ID' => $userId, 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y')); $hrPhoto = $userData['hrphoto']; } $dialogId = $userId; } } } } if (!$dialogId) { $this->error = new CVoxImplantError(__METHOD__, 'ERROR_NEW_CHAT', GetMessage('VI_ERROR_NEW_CHAT')); return false; } //foreach(GetModuleEvents("voximplant", "OnGetDialogInfo", true) as $arEvent) // ExecuteModuleEventEx($arEvent, array('USER_ID' => $this->userId, 'DIALOG_ID' => $dialogId)); return array('DIALOG_ID' => $dialogId, 'HR_PHOTO' => $hrPhoto); }
public static function Like($id, $action = 'auto') { global $USER; if (!CModule::IncludeModule('pull')) { return false; } $action = in_array($action, array('plus', 'minus')) ? $action : 'auto'; $message = self::GetById($id, array('WITH_FILES' => 'Y')); if (!$message) { return false; } $relations = CIMMessenger::GetRelationById($id); if (!isset($relations[$USER->GetId()])) { return false; } $isLike = false; if (isset($message['PARAMS']['LIKE'])) { $isLike = in_array($USER->GetId(), $message['PARAMS']['LIKE']); } if ($isLike && $action == 'plus') { return false; } else { if (!$isLike && $action == 'minus') { return false; } } $isLike = true; if (isset($message['PARAMS']['LIKE'])) { $like = $message['PARAMS']['LIKE']; $selfLike = array_search($USER->GetId(), $like); if ($selfLike !== false) { $isLike = false; unset($like[$selfLike]); } else { $like[] = $USER->GetId(); } } else { $like = array($USER->GetId()); } sort($like); CIMMessageParam::Set($id, array('LIKE' => $like)); $result = IM\ChatTable::getList(array('filter' => array('=ID' => $message['CHAT_ID']))); $chat = $result->fetch(); if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $USER->GetId() && $isLike) { $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('#\\-{54}.+?\\-{54}#s', " [" . 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" => $USER->GetId(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "im", "NOTIFY_EVENT" => "like", "NOTIFY_TAG" => "RATING|IM|" . ($isChat ? 'G' : 'P') . "|" . ($isChat ? $chat['ID'] : $USER->GetId()) . "|" . $id, "NOTIFY_MESSAGE" => GetMessage($isChat ? 'IM_MESSAGE_LIKE' : 'IM_MESSAGE_LIKE_PRIVATE', array('#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $isChat ? '[CHAT=' . $chat['ID'] . ']' . $chat['TITLE'] . '[/CHAT]' : $chat['TITLE'])), "NOTIFY_MESSAGE_OUT" => GetMessage($isChat ? 'IM_MESSAGE_LIKE' : 'IM_MESSAGE_LIKE_PRIVATE', array('#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $chat['TITLE']))); CIMNotify::Add($arMessageFields); } $arPullMessage = array('id' => $id, 'chatId' => $chat['ID'], 'senderId' => $USER->GetId(), 'users' => $like); foreach ($relations as $rel) { CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage)); } if ($chat['TYPE'] == IM_MESSAGE_OPEN) { CPullWatch::AddToStack('IM_PUBLIC_' . $chat['ID'], array('module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage)); } return $like; }