23 if (!$this->isCorrectRequest(
$comment))
28 $toIncrement = $this->getRecipientsByComment(
$comment);
31 WorkflowUserCommentTable::incrementUnreadCounter(
$comment->workflowId, $toIncrement);
32 $this->incrementUsersCounters($toIncrement);
33 $this->pushCounters(
$comment->workflowId, $toIncrement);
36 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
37 $documentService->onWorkflowCommentAdded($documentId,
$comment->workflowId,
$comment->authorId);
43 if (!$this->isCorrectRequest(
$comment))
48 $userIds = WorkflowUserCommentTable::decrementUnreadCounterByDate(
$comment->workflowId,
$comment->created);
49 $this->decrementUsersCounters($userIds);
50 $this->pushCounters(
$comment->workflowId, $userIds);
53 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
54 $documentService->onWorkflowCommentDeleted($documentId,
$comment->workflowId,
$comment->authorId);
60 '=WORKFLOW_ID' => $markRead->workflowId,
61 '=USER_ID' => $markRead->userId,
64 $hasUnread = (bool)WorkflowUserCommentTable::query()->setFilter(
$filter)->fetch();
69 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
70 $documentService->onWorkflowAllCommentViewed($documentId, $markRead->workflowId, $markRead->userId);
72 WorkflowUserCommentTable::delete([
73 'WORKFLOW_ID' => $markRead->workflowId,
74 'USER_ID' => $markRead->userId,
76 $this->updateUserCounters($markRead->userId);
77 $this->pushCounters($markRead->workflowId, [$markRead->userId]);
84 if (!Loader::includeModule(
'forum'))
94 \CBPHelper::getForumId(),
97 'id' => $workflowIdInt,
98 'xml_id' =>
'WF_' .
$comment->workflowId,
103 if (!$feed->addServiceComment([
104 'POST_MESSAGE' =>
$comment->message,
107 $response->addErrors($feed->getErrors());
111 WorkflowUserCommentTable::incrementUnreadCounter(
114 WorkflowUserCommentTable::COMMENT_TYPE_SYSTEM
116 $this->incrementUsersCounters([
$comment->authorId]);
125 $workflowUsers = $this->getWorkflowUsers(
$comment->workflowId);
126 unset($workflowUsers[
$comment->authorId]);
134 $directly = array_intersect($mentions, array_keys($workflowUsers));
142 $activeUsers = array_filter(
144 static fn (
$user) =>
$user[
'TASK_STATUS'] === WorkflowUserTable::TASK_STATUS_ACTIVE,
149 return array_keys($activeUsers);
152 $author = array_filter(
154 static fn (
$user) =>
$user[
'IS_AUTHOR'] === 1,
157 return array_keys($author);
160 private function getWorkflowUsers(
string $workflowId):
array
162 $result = WorkflowUserTable::getList([
163 'select' => [
'USER_ID',
'IS_AUTHOR',
'TASK_STATUS'],
164 'filter' => [
'=WORKFLOW_ID' => $workflowId],
169 while ($row =
$result->fetch())
171 $users[(int)$row[
'USER_ID']] = [
172 'IS_AUTHOR' => (
int)$row[
'IS_AUTHOR'],
173 'TASK_STATUS' => (int)$row[
'TASK_STATUS'],
180 private function isCorrectRequest(CommentRequest
$comment): bool
185 && WorkflowStateTable::exists(
$comment->workflowId)
189 private function pushCounters(
string $workflowId,
array $touchUserIds): void
191 $userIds = WorkflowUserTable::getUserIdsByWorkflowId($workflowId);
192 $rows = WorkflowUserCommentTable::query()
193 ->setSelect([
'USER_ID',
'UNREAD_CNT'])
194 ->where(
'WORKFLOW_ID', $workflowId)
197 $values = array_combine(
198 array_column(
$rows,
'USER_ID'),
199 array_column(
$rows,
'UNREAD_CNT')
203 if (Loader::includeModule(
'forum'))
205 $topic = \CForumTopic::getList([], [
'XML_ID' =>
'WF_' . $workflowId])->fetch() ?: [];
206 $all = (int)($topic[
'POSTS'] ?? 0);
211 CommentPush::pushCounter(
217 WorkflowUserCommentTable::getCountUserUnread(
$userId),
222 WorkflowUserTable::touchWorkflowUsers($workflowId, $touchUserIds);
225 private function incrementUsersCounters(
array $userIds): void
229 $userCounters =
new WorkflowUserCounters(
$userId);
230 $userCounters->incrementComment();
234 private function decrementUsersCounters(
array $userIds): void
238 $userCounters =
new WorkflowUserCounters(
$userId);
239 $userCounters->decrementComment();
243 private function updateUserCounters(
int $userId): void
245 $userCounters =
new WorkflowUserCounters(
$userId);
246 $userCounters->setComment(WorkflowUserCommentTable::getCountUserUnread(
$userId));