Поддержка серверов

CIMMessenger::Delete: метод Битрикс

Постоянная ссылка: http://bxapi.ru/src/?id=211360

//    CIMMessenger::Delete()
//    /bitrix/modules/im/classes/general/im_messenger.php:1616

    public static function Delete($id, $userId = null, $completeDelete = false, $byEvent = false)
    {
        $deleteFlags = Array(
            'ID' => $id,
            'USER_ID' => $userId,
            'COMPLETE_DELETE' => $completeDelete,
            'BY_EVENT' => $byEvent
        );

        $message = self::CheckPossibilityUpdateMessage(IM_CHECK_DELETE, $id, $userId);
        if (!$message)
            return false;

        $deleteFlags['COMPLETE_DELETE'] = $completeDelete = $message['CHAT_ID'] == CIMChat::GetGeneralChatId() && self::IsAdmin()? true: $completeDelete;

        $params = CIMMessageParam::Get($message['ID']);
        if (!empty($params['FILE_ID']))
        {
            foreach ($params['FILE_ID'] as $fileId)
            {
                CIMDisk::DeleteFile($message['CHAT_ID'], $fileId);
            }
        }

        $date = FormatDate("FULL", $message['DATE_CREATE']+CTimeZone::GetOffset());
        if (!$completeDelete)
        {
            IM\Model\MessageTable::update($message['ID'], array(
                "MESSAGE" => GetMessage('IM_MESSAGE_DELETED'),
                "MESSAGE_OUT" => GetMessage('IM_MESSAGE_DELETED_OUT', Array('#DATE#' => $date)),
            ));
            CIMMessageParam::Set($message['ID'], Array('IS_DELETED' => 'Y', 'URL_ID' => Array(), 'FILE_ID' => Array(), 'KEYBOARD' => 'N', 'ATTACH' => Array()));
        }

        $arFields = $message;
        $arFields['MESSAGE'] = GetMessage('IM_MESSAGE_DELETED_OUT', Array('#DATE#' => $date));
        $arFields['DATE_MODIFY'] = new \Bitrix\Main\Type\DateTime();

        $relations = CIMMessenger::GetRelationById($message['ID']);
        $arPullMessage = Array(
            'id' => (int)$arFields['ID'],
            'type' => $arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE? 'private': 'chat',
            'text' => GetMessage('IM_MESSAGE_DELETED'),
            'params' => Array('IS_DELETED' => 'Y', 'URL_ID' => Array(), 'FILE_ID' => Array(), 'KEYBOARD' => 'N', 'ATTACH' => Array())
        );
        $arBotInChat = Array();
        if ($message['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE)
        {
            $arFields['FROM_USER_ID'] = $arFields['AUTHOR_ID'];
            $arFields['TO_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'] = (int)$arFields['FROM_USER_ID'];
            $arPullMessage['toUserId'] = (int)$arFields['TO_USER_ID'];
            $arPullMessage['senderId'] = (int)$arFields['TO_USER_ID'];
            $arPullMessage['chatId'] = (int)$arFields['CHAT_ID'];
        }
        else
        {
            $arPullMessage['chatId'] = (int)$arFields['CHAT_ID'];
            $arPullMessage['senderId'] = (int)$arFields['AUTHOR_ID'];

            foreach ($relations as $relation)
            {
                if ($message['CHAT_ENTITY_TYPE'] == 'LINES')
                {
                    if ($relation["EXTERNAL_AUTH_ID"] == 'imconnector')
                    {
                        unset($relations[$relation["USER_ID"]]);
                        continue;
                    }
                }
                if ($relation["EXTERNAL_AUTH_ID"] == \Bitrix\Im\Bot::EXTERNAL_AUTH_ID)
                {
                    $arBotInChat[$relation["USER_ID"]] = $relation["USER_ID"];
                    unset($relations[$relation["USER_ID"]]);
                    continue;
                }
            }
        }

        if ($message['MESSAGE_TYPE'] != IM_MESSAGE_PRIVATE)
        {
            $arFields['BOT_IN_CHAT'] = $arBotInChat;
        }

        \Bitrix\Im\Bot::onMessageDelete(intval($id), $arFields);

        if ($completeDelete)
        {
            IM\Model\ChatTable::update($message['CHAT_ID'], Array(
                'MESSAGE_COUNT' => new \Bitrix\Main\DB\SqlExpression('?# - 1', 'MESSAGE_COUNT'),
            ));

            if ($message['CHAT_PARENT_MID'])
            {
                $chatData = IM\Model\ChatTable::getById($message['CHAT_ID'])->fetch();
                CIMMessageParam::set($chatData['PARENT_MID'], Array(
                    'CHAT_MESSAGE' => $chatData['MESSAGE_COUNT'],
                    'CHAT_LAST_DATE' => new \Bitrix\Main\Type\DateTime()
                ));
                CIMMessageParam::SendPull($chatData['PARENT_MID'], Array('CHAT_MESSAGE', 'CHAT_LAST_DATE'));
            }

            $completeDelete = true;
            CIMMessageParam::DeleteAll($message['ID']);
            \Bitrix\Im\Model\MessageTable::delete($message['ID']);

            $relationCounters = \Bitrix\Im\Chat::getRelation($message['CHAT_ID'], Array(
                'SELECT' => Array('ID', 'USER_ID'),
                'REAL_COUNTERS' => 'Y',
                'USER_DATA' => 'Y',
                'SKIP_RELATION_WITH_UNMODIFIED_COUNTERS' => 'Y'
            ));
            foreach ($relationCounters as $relation)
            {
                if (
                    $relation['USER_DATA']["EXTERNAL_AUTH_ID"] == \Bitrix\Im\Bot::EXTERNAL_AUTH_ID
                    || $relation['USER_DATA']['ACTIVE'] == 'N'
                )
                {
                    continue;
                }
                \Bitrix\Im\Model\RelationTable::update($relation['ID'], Array('COUNTER' => $relation['COUNTER']));
                \Bitrix\Im\Counter::clearCache($relation['USER_ID']);
            }

            $result = \Bitrix\Im\Model\RecentTable::getList(Array('filter' => Array('=ITEM_MID' => $message['ID'])))->fetchAll();
            if (!empty($result))
            {
                $message = \Bitrix\Im\Model\MessageTable::getList(Array(
                    'filter' => Array('=CHAT_ID' => $message['CHAT_ID']),
                    'limit' => 1,
                    'order' => Array('ID' => 'DESC')
                ))->fetch();
                if ($message)
                {
                    foreach ($result as $recent)
                    {
                        \Bitrix\Im\Model\RecentTable::update(Array(
                            'USER_ID' => $recent['USER_ID'],
                            'ITEM_TYPE' => $recent['ITEM_TYPE'],
                            'ITEM_ID' => $recent['ITEM_ID'],
                        ), Array('ITEM_MID' => $message['ID']));

                        $obCache = new CPHPCache();
                        $obCache->CleanDir('/bx/imc/recent'.CIMMessenger::GetCachePath($recent['USER_ID']));

                        if ($recent['ITEM_TYPE'] == IM_MESSAGE_PRIVATE)
                            CIMMessenger::SpeedFileDelete($recent['USER_ID'], IM_SPEED_GROUP);
                        else
                            CIMMessenger::SpeedFileDelete($recent['USER_ID'], IM_SPEED_MESSAGE);
                    }
                }
            }
        }

        foreach ($relations as $rel)
        {
            $obCache = new CPHPCache();
            $obCache->CleanDir('/bx/imc/recent'.self::GetCachePath($rel['USER_ID']));
        }

        if ($message['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE)
        {
            $arPullMessage['dialogId'] = (int)$arFields['FROM_USER_ID'];
            $arPullMessage['chatId'] = (int)$message['CHAT_ID'];
            $arPullMessage['fromUserId'] = (int)$arFields['FROM_USER_ID'];
            $arPullMessage['toUserId'] = (int)$arFields['TO_USER_ID'];

            \Bitrix\Pull\Event::add($arPullMessage['toUserId'], Array(
                'module_id' => 'im',
                'command' => ($completeDelete? 'messageDeleteComplete': 'messageDelete'),
                'params' => $arPullMessage,
                'push' => $completeDelete? Array('badge' => 'Y'): Array(),
                'extra' => \Bitrix\Im\Common::getPullExtra()
            ));

            $arPullMessage['dialogId'] = (int)$arFields['TO_USER_ID'];
            $arPullMessage['fromUserId'] = (int)$arFields['TO_USER_ID'];
            $arPullMessage['toUserId'] = (int)$arFields['FROM_USER_ID'];

            \Bitrix\Pull\Event::add($arPullMessage['toUserId'], Array(
                'module_id' => 'im',
                'command' => ($completeDelete? 'messageDeleteComplete': 'messageDelete'),
                'params' => $arPullMessage,
                'push' => $completeDelete? Array('badge' => 'Y'): Array(),
                'extra' => \Bitrix\Im\Common::getPullExtra()
            ));
        }
        else
        {
            $arPullMessage['dialogId'] = 'chat'.$arPullMessage['chatId'];
            $arPullMessage['chatId'] = (int)$message['CHAT_ID'];

            \Bitrix\Pull\Event::add(array_keys($relations), Array(
                'module_id' => 'im',
                'command' => ($completeDelete? 'messageDeleteComplete': 'messageDelete'),
                'params' => $arPullMessage,
                'push' => $completeDelete? Array('badge' => 'Y'): Array(),
                'extra' => \Bitrix\Im\Common::getPullExtra()
            ));
        }

        if ($message['MESSAGE_TYPE'] == IM_MESSAGE_OPEN || $message['MESSAGE_TYPE'] == IM_MESSAGE_OPEN_LINE)
        {
            CPullWatch::AddToStack('IM_PUBLIC_'.$message['CHAT_ID'], Array(
                'module_id' => 'im',
                'command' => ($completeDelete? 'messageDeleteComplete': 'messageDelete'),
                'params' => $arPullMessage,
                'push' => $completeDelete? Array('badge' => 'Y'): Array(),
                'extra' => \Bitrix\Im\Common::getPullExtra()
            ));
        }

        foreach(GetModuleEvents("im", "OnAfterMessagesDelete", true) as $arEvent)
            ExecuteModuleEventEx($arEvent, array(intval($id), $arFields, $deleteFlags));

        return true;
    }

Блог разработчика

9 Августа 2016 ResizeImageGet и простой водяной знак налету

Сегодня поговорим о том как проще всего воткнуть водяной знак на картинки в Битрикс. Например, на все изображения каталога.

21 Июля 2016 Добавление вкладки в CRM коробки Битрикс24

В этом посте я покажу, как легко и просто добавить вкладку в сущность CRM. И не просто добавить, а вывести там свой контент.

21 Июля 2016 Как просто обращаться из коробки Битрикс24 на сайт на базе Битрикс

К примеру вам хочется внутренним скриптом дернуть с сайта-магазина информацию, которая там, в свою очередь, закрыта некоторыми правами. Например, админскими. Можно конечно мутить свой REST, или иной формат общения, но проще всего воспользоваться штатным инструментом:

Текст сообщения*
Загрузить изображение