• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/notify.php
  • Класс: BitrixImNotify
  • Вызов: Notify::get
public function get()
{
	if (!$this->chatId || !$this->totalCount)
	{
		return [
			'notifications' => [],
			'users' => [],
		];
	}
	// fetching confirm notifications
	$confirmCollection = $this->fetchConfirms();

	// fetching simple notifications
	$offset = count($confirmCollection);
	$simpleCollection = $this->fetchSimple($offset);
	$notifications = array_merge($confirmCollection, $simpleCollection);

	/*$unreadCount = BitrixImModelMessageTable::getList(
		[
			'select' => ['CNT'],
			'filter' => [
				'=CHAT_ID' => $this->chatId,
				'=NOTIFY_READ' => 'N'
			],
			'runtime' => [
				new BitrixMainORMFieldsExpressionField('CNT', 'COUNT(*)')
			]
		]
	)->fetch();*/

	$unreadCount = (new CounterService(BitrixImCommon::getUserId()))->getByChat($this->chatId);

	$result = [
		'TOTAL_COUNT' => $this->totalCount,
		'TOTAL_UNREAD_COUNT' => (int)$unreadCount,
		'CHAT_ID' => $this->chatId,
		'NOTIFICATIONS' => $notifications,
		'USERS' => $this->users,
	];

	foreach ($result['NOTIFICATIONS'] as $key => $value)
	{
		if ($value['DATE'] instanceof DateTime)
		{
			$result['NOTIFICATIONS'][$key]['DATE'] = date('c', $value['DATE']->getTimestamp());
		}

		$result['NOTIFICATIONS'][$key] = array_change_key_case($result['NOTIFICATIONS'][$key], CASE_LOWER);
	}
	$result['NOTIFICATIONS'] = array_values($result['NOTIFICATIONS']);
	$result['USERS'] = array_values($result['USERS']);
	$result = array_change_key_case($result, CASE_LOWER);

	return $result;
}