- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/lib/recent.php
- Класс: BitrixImRecent
- Вызов: Recent::getList
static function getList($userId = null, $options = [])
{
$userId = BitrixImCommon::getUserId($userId);
if (!$userId)
{
return false;
}
$generalChatId = CIMChat::GetGeneralChatId();
$viewCommonUsers = (bool)CIMSettings::GetSetting(CIMSettings::SETTINGS, 'viewCommonUsers');
$onlyOpenlinesOption = $options['ONLY_OPENLINES'] ?? null;
$skipChatOption = $options['SKIP_CHAT'] ?? null;
$skipDialogOption = $options['SKIP_DIALOG'] ?? null;
$lastMessageDateOption = $options['LAST_MESSAGE_DATE'] ?? null;
$withoutCommonUsers = !$viewCommonUsers || $onlyOpenlinesOption === 'Y';
$unreadOnly = isset($options['UNREAD_ONLY']) && $options['UNREAD_ONLY'] === 'Y';
$shortInfo = isset($options['SHORT_INFO']) && $options['SHORT_INFO'] === 'Y';
$showOpenlines = (
BitrixMainLoader::includeModule('imopenlines')
&& (
$onlyOpenlinesOption === 'Y'
|| $options['SKIP_OPENLINES'] !== 'Y'
)
);
$ormParams = self::getOrmParams([
'USER_ID' => $userId,
'SHOW_OPENLINES' => $showOpenlines,
'WITHOUT_COMMON_USERS' => $withoutCommonUsers,
'UNREAD_ONLY' => $unreadOnly,
'SHORT_INFO' => $shortInfo,
]);
if ($onlyOpenlinesOption === 'Y')
{
$ormParams['filter'][] = [
'=ITEM_TYPE' => IM_MESSAGE_OPEN_LINE
];
}
else
{
$skipTypes = [];
if ($options['SKIP_OPENLINES'] === 'Y')
{
$skipTypes[] = IM_MESSAGE_OPEN_LINE;
}
if ($skipChatOption === 'Y')
{
$skipTypes[] = IM_MESSAGE_OPEN;
$skipTypes[] = IM_MESSAGE_CHAT;
}
if ($skipDialogOption === 'Y')
{
$skipTypes[] = IM_MESSAGE_PRIVATE;
}
if (!empty($skipTypes))
{
$ormParams['filter'][] = [
'!@ITEM_TYPE' => $skipTypes
];
}
}
if ($lastMessageDateOption instanceof BitrixMainTypeDateTime)
{
$ormParams['filter']['<=DATE_MESSAGE'] = $lastMessageDateOption;
}
else if (isset($options['OFFSET']))
{
$ormParams['offset'] = $options['OFFSET'];
}
if (isset($options['LIMIT']))
{
$ormParams['limit'] = (int)$options['LIMIT'];
}
else
{
$ormParams['limit'] = 50;
}
$ormParams['order'] = [
'PINNED' => 'DESC',
'DATE_MESSAGE' => 'DESC',
];
$orm = BitrixImModelRecentTable::getList($ormParams);
$counter = 0;
$result = [];
$files = [];
$rows = $orm->fetchAll();
$rows = self::prepareRows($rows, $userId);
foreach ($rows as $row)
{
$counter++;
$isUser = $row['ITEM_TYPE'] == IM_MESSAGE_PRIVATE;
$id = $isUser? (int)$row['ITEM_ID']: 'chat'.$row['ITEM_ID'];
if ($isUser)
{
if (isset($result[$id]) && !$row['ITEM_MID'])
{
continue;
}
}
else if (isset($result[$id]))
{
continue;
}
$item = self::formatRow($row, [
'GENERAL_CHAT_ID' => $generalChatId,
'WITHOUT_COMMON_USERS' => $withoutCommonUsers,
'GET_ORIGINAL_TEXT' => $options['GET_ORIGINAL_TEXT'] ?? null,
'SHORT_INFO' => $shortInfo,
]);
if (!$item)
{
continue;
}
$result[$id] = $item;
}
$result = array_values($result);
if ($options['JSON'])
{
foreach ($result as $index => $item)
{
$result[$index] = self::jsonRow($item);
}
$objectToReturn = [
'items' => $result,
'hasMorePages' => $ormParams['limit'] == $counter, // TODO remove this later
'hasMore' => $ormParams['limit'] == $counter
];
if (!isset($options['LAST_MESSAGE_DATE']))
{
$objectToReturn['birthdayList'] = BitrixImIntegrationIntranetUser::getBirthdayForToday();
}
return $objectToReturn;
}
return [
'ITEMS' => $result,
'HAS_MORE_PAGES' => $ormParams['limit'] == $counter, // TODO remove this later
'HAS_MORE' => $ormParams['limit'] == $counter
];
}