openvk/Web/Events/NewMessageEvent.php
Alexander Minkin 6ec54a379d
feat: add linting of code (#1220)
* feat(lint): add php-cs-fixer for linting

Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0.

This is not the reformatting commit.

* style: format code according to PER-CS 2.0 with php-cs-fixer

* ci(actions): add lint action

Resolves #1132.
2025-01-31 18:20:13 +03:00

54 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace openvk\Web\Events;
use openvk\Web\Models\Entities\Message;
use openvk\Web\Models\Repositories\Messages;
class NewMessageEvent implements ILPEmitable
{
protected $payload;
public function __construct(Message $message)
{
$this->payload = $message->simplify();
}
public function getLongPoolSummary(): object
{
return (object) [
"type" => "newMessage",
"message" => $this->payload,
];
}
public function getVKAPISummary(int $userId): array
{
$msg = (new Messages())->get($this->payload["uuid"]);
$peer = $msg->getSender()->getId();
if ($peer === $userId) {
$peer = $msg->getRecipient()->getId();
}
/*
* Source:
* https://github.com/danyadev/longpoll-doc
*/
return [
4, # event type
$msg->getId(), # messageId
256, # checked for spam flag
$peer, # TODO calculate peer correctly
$msg->getSendTime()->timestamp(), # creation time in unix
$msg->getText(), # text (formatted)
[], # empty additional info
[], # empty attachments
$msg->getId() << 2, # id as random_id
$peer, # conversation id
0, # not edited yet
];
}
}