15 private static array $listMessages = [];
16 private static int $blogAuthorId = 0;
17 private const LIMIT = 20;
27 $moduleId ===
'socialnetwork'
28 && str_starts_with($contextId,
'sonet_comment_')
30 if ($isCommentContext)
34 $xmlId = is_string($contextParameters[
'xmlId'] ??
null) ? $contextParameters[
'xmlId'] :
null;
37 return [
'messages' => []];
40 if (isset(self::$listMessages[$xmlId]))
42 return [
'messages' => self::$listMessages[$xmlId]];
45 if (str_starts_with($xmlId,
'BLOG_') && Loader::includeModule(
'blog'))
47 $postId = (int) mb_substr($xmlId, 5);
48 $postMessages = self::getPostContext($postId);
49 foreach ($postMessages as $postMessage)
51 $messages[] = [
'content' => $postMessage];
55 str_starts_with($xmlId,
'TASK_')
56 && Loader::includeModule(
'tasks')
57 && Loader::includeModule(
'forum')
60 $postMessages = self::getTaskContext($xmlId);
61 foreach ($postMessages as $postMessage)
63 $messages[] = [
'content' => $postMessage];
67 $messages[0] = self::modifyOriginalMessage($messages[0] ?? []);
71 self::$listMessages[$xmlId] = $messages;
74 return [
'messages' => $messages];
77 return [
'messages' => []];
80 private static function getPostContext(
int $postId): array
84 $textParser = new \CTextParser();
86 $post = \CBlogPost::getByID($postId);
89 self::setBlogAuthorId((
int)$post[
'AUTHOR_ID']);
91 $messages[] = $textParser->clearAllTags($post[
'DETAIL_TEXT']);
93 $comments = self::getLastComments($postId);
95 $messages = array_merge($messages, $comments);
101 private static function getTaskContext(
string $xmlId): array
103 $taskId = (int) mb_substr($xmlId, 5);
105 $textParser = new \CTextParser();
109 $task = \Bitrix\Tasks\Internals\Registry\TaskRegistry::getInstance()->getObject($taskId);
110 self::setBlogAuthorId($task->getCreatedBy());
111 $messages[] = $textParser->clearAllTags($task->getDescription());
113 $liveFeedEntity = \Bitrix\Socialnetwork\Livefeed\Provider::init([
114 'ENTITY_TYPE' => \
Bitrix\Socialnetwork\Livefeed\Provider::DATA_ENTITY_TYPE_TASKS_TASK,
115 'ENTITY_ID' => $taskId,
119 $logId = (int) $liveFeedEntity->getLogId();
122 $comments = self::getForumComments($xmlId);
124 $messages = array_merge($messages, array_reverse($comments));
131 private static function getForumComments(
string $xmlId): array
133 $textParser = new \CTextParser();
137 $query = MessageTable::query();
139 ->setSelect([
'ID',
'POST_MESSAGE'])
140 ->where(
'XML_ID', $xmlId)
141 ->whereNull(
'SERVICE_TYPE')
142 ->whereNull(
'PARAM1')
143 ->setOrder([
'POST_DATE' =>
'desc'])
144 ->setLimit(self::LIMIT);
146 $postMessages = $query->exec()->fetchCollection();
147 foreach ($postMessages as $postMessage)
149 $comments[] = $textParser->clearAllTags($postMessage->getPostMessage());
155 private static function getLastComments(
int $postId): array
157 $textParser = new \CTextParser();
161 $queryCommentObject = \CBlogComment::getList(
164 'PUBLISH_STATUS' => BLOG_PUBLISH_STATUS_PUBLISH,
165 'POST_ID' => $postId,
166 '!=POST_TEXT' => \
Bitrix\Socialnetwork\CommentAux\TaskInfo::POST_TEXT,
170 'nTopCount' => self::LIMIT
174 while ($commentData = $queryCommentObject->fetch())
176 $comments[] = $textParser->clearAllTags($commentData[
'POST_TEXT']);
182 private static function modifyOriginalMessage(array $message): array
184 $message[
'is_original_message'] =
true;
186 if (self::$blogAuthorId)
188 $author =
new Author(self::$blogAuthorId);
189 $message[
'meta'] = $author->toMeta();
195 private static function setBlogAuthorId(
int $userId): void