16 private const PARAMS_TO_COPY_WHITELIST = [
17 Message\Params::ATTACH => Message\Params::ATTACH,
18 Message\Params::URL_ID => Message\Params::URL_ID,
19 Message\Params::IS_DELETED => Message\Params::IS_DELETED,
20 Message\Params::URL_ONLY => Message\Params::URL_ONLY,
21 Message\Params::LARGE_FONT => Message\Params::LARGE_FONT,
22 Message\Params::FORWARD_CONTEXT_ID => Message\Params::FORWARD_CONTEXT_ID,
23 Message\Params::FORWARD_ID => Message\Params::FORWARD_ID,
24 Message\Params::FORWARD_USER_ID => Message\Params::FORWARD_USER_ID,
25 Message\Params::REPLY_ID => Message\Params::REPLY_ID,
32 $this->toChat = $toChat;
44 foreach ($forwardingMessages as $forwardingMessage)
46 if ($forwardingMessage->getChat()->hasAccess($this->getContext()->getUserId()))
48 $forwardMessageResult = $this->createForwardMessage($forwardingMessage);
49 if ($forwardMessageResult->hasResult())
51 $messageMap = $forwardMessageResult->getResult();
52 $uuidMap[$messageMap[
'uuid']] = $messageMap[
'id'];
55 $result->addErrors($forwardMessageResult->getErrors());
59 return $result->setResult($uuidMap);
66 private function createForwardMessage(
Message $forwardingMessage):
Result
68 $paramsResult = $this->createParamsForForwardMessage($forwardingMessage);
69 if (!$paramsResult->hasResult())
75 'MESSAGE_TYPE' => $this->toChat->getType(),
77 'PARAMS' => $paramsResult->getResult(),
78 'TO_CHAT_ID' => $this->toChat->getChatId(),
79 'FROM_USER_ID' => $this->getContext()->getUserId(),
85 $messageId = \CIMMessenger::Add($messageConfig);
91 return $result->setResult([
101 private function createParamsForForwardMessage(Message $forwardingMessage):
Result
105 $newParams = $this->getForwardingMessageParams($forwardingMessage);
107 if ($this->isOriginalMessage($newParams))
109 $userId = $forwardingMessage->isSystem() ? 0 : $forwardingMessage->getAuthorId();
110 $newParams[Message\Params::FORWARD_ID] = $forwardingMessage->getId();
111 $newParams[Message\Params::FORWARD_CONTEXT_ID] = $forwardingMessage->getContextId();
112 $newParams[Message\Params::FORWARD_USER_ID] = $userId;
118 foreach ($forwardingMessage->getFiles() as $file)
120 $copy = $file->getCopyToChat($this->toChat);
121 if ($copy instanceof FileItem)
123 $newFileIds[] = $copy->getId();
127 $newParams[Message\Params::FILE_ID] = $newFileIds;
130 return $result->setResult($newParams);
138 private function isOriginalMessage(array $messageParams): bool
150 private function getForwardingMessageParams(Message $message): array
153 foreach ($message->getParams() as $param)
155 if (isset(self::PARAMS_TO_COPY_WHITELIST[$param->getName()]))
157 $value = $param->getValue();
160 $value = $value ?
'Y' :
'N';
162 $result[$param->getName()] = $value;