Commit 6b07ca55 authored by Jack'lul's avatar Jack'lul

'entities' and 'pinned_message' added, table structure updated, some comments updated

parent d4ccf64b
......@@ -572,6 +572,7 @@ class DB
$forward_date = self::getTimestamp($message->getForwardDate());
$photo = $message->getPhoto();
$entities = $message->getEntities();
$new_chat_member = $message->getNewChatMember();
$new_chat_photo = $message->getNewChatPhoto();
......@@ -596,14 +597,11 @@ class DB
$type = $chat->getType();
if ($migrate_to_chat_id) {
$type = 'supergroup';
$sth2->bindParam(':id', $migrate_to_chat_id, \PDO::PARAM_INT);
$sth2->bindParam(':oldid', $chat_id, \PDO::PARAM_INT);
} else {
$sth2->bindParam(':id', $chat_id, \PDO::PARAM_INT);
$sth2->bindParam(':oldid', $migrate_to_chat_id, \PDO::PARAM_INT);
}
......@@ -643,21 +641,21 @@ class DB
$sth = self::$pdo->prepare('INSERT IGNORE INTO `' . TB_MESSAGE . '`
(
`id`, `user_id`, `date`, `chat_id`, `forward_from`,
`forward_date`, `reply_to_chat`, `reply_to_message`, `text`, `audio`, `document`,
`forward_date`, `reply_to_chat`, `reply_to_message`, `text`, `entities`, `audio`, `document`,
`photo`, `sticker`, `video`, `voice`, `caption`, `contact`,
`location`, `venue`, `new_chat_member`, `left_chat_member`,
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_chat_created`,
`migrate_from_chat_id`, `migrate_to_chat_id`
`migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`
)
VALUES (
:message_id, :user_id, :date, :chat_id, :forward_from,
:forward_date, :reply_to_chat, :reply_to_message, :text, :audio, :document,
:forward_date, :reply_to_chat, :reply_to_message, :text, :entities, :audio, :document,
:photo, :sticker, :video, :voice, :caption, :contact,
:location, :venue, :new_chat_member, :left_chat_member,
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
:supergroup_chat_created, :channel_chat_created,
:migrate_from_chat_id, :migrate_to_chat_id
:migrate_from_chat_id, :migrate_to_chat_id, :pinned_message
)');
$message_id = $message->getMessageId();
......@@ -689,6 +687,7 @@ class DB
$channel_chat_created = $message->getChannelChatCreated();
$migrate_from_chat_id = $message->getMigrateFromChatId();
$migrate_to_chat_id = $message->getMigrateToChatId();
$pinned_message = $message->getPinnedMessage();
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
......@@ -700,9 +699,22 @@ class DB
if ($reply_to_message_id) {
$reply_chat_id = $chat_id;
}
$var = [];
if (is_array($entities)) {
foreach ($entities as $elm) {
$var[] = json_decode($elm, true);
}
$entities = json_encode($var);
} else {
$entities = '';
}
$sth->bindParam(':reply_to_chat', $reply_chat_id, \PDO::PARAM_INT);
$sth->bindParam(':reply_to_message', $reply_to_message_id, \PDO::PARAM_INT);
$sth->bindParam(':text', $text, \PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, \PDO::PARAM_STR);
$sth->bindParam(':audio', $audio, \PDO::PARAM_STR);
$sth->bindParam(':document', $document, \PDO::PARAM_STR);
......@@ -748,6 +760,8 @@ class DB
$sth->bindParam(':channel_chat_created', $channel_chat_created, \PDO::PARAM_INT);
$sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, \PDO::PARAM_INT);
$sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, \PDO::PARAM_INT);
$sth->bindParam(':pinned_message', $pinned_message, \PDO::PARAM_INT);
$status = $sth->execute();
} catch (PDOException $e) {
......
......@@ -17,7 +17,7 @@ class InlineKeyboardMarkup extends Entity
protected $inline_keyboard;
/*
* @todo: check for InlineKeyboardButton elements
* @todo check for InlineKeyboardButton elements
*/
public function __construct($data = array())
{
......
......@@ -250,6 +250,9 @@ class Message extends Entity
}
$this->pinned_message = isset($data['pinned_message']) ? $data['pinned_message'] : null;
if ($this->pinned_message) {
$this->pinned_message = new Message($this->pinned_message, $this->getBotName());
}
$this->entities = isset($data['entities']) ? $data['entities'] : null;
if (!empty($this->entities)) {
......
......@@ -20,12 +20,12 @@ class MessageEntity extends Entity
public function __construct(array $data)
{
$this->type = isset($data['type']) ? $data['type'] : null;
if (empty($this->type)) {
if (empty($this->type)) { // @todo check for value from this list: https://core.telegram.org/bots/api#messageentity
throw new TelegramException('type is empty!');
}
$this->offset = isset($data['offset']) ? $data['offset'] : null;
if (empty($this->offset) && $this->offset != 0) { // @todo:this is not an ideal solution?
if (empty($this->offset) && $this->offset != 0) { // @todo this is not an ideal solution?
throw new TelegramException('offset is empty!');
}
......
......@@ -19,6 +19,9 @@ class ReplyKeyboardMarkup extends Entity
protected $one_time_keyboard;
protected $selective;
/*
* @todo check for KeyboardButton elements
*/
public function __construct($data = array())
{
if (isset($data['keyboard'])) {
......
......@@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS `message` (
`reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Chat identifier.',
`reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message is a reply to another message.',
`text` TEXT DEFAULT NULL COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8',
`entities` TEXT DEFAULT NULL COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',
`audio` TEXT DEFAULT NULL COMMENT 'Audio object. Message is an audio file, information about the file',
`document` TEXT DEFAULT NULL COMMENT 'Document object. Message is a general file, information about the file',
`photo` TEXT DEFAULT NULL COMMENT 'Array of PhotoSize objects. Message is a photo, available sizes of the photo',
......@@ -106,6 +107,7 @@ CREATE TABLE IF NOT EXISTS `message` (
`channel_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the channel chat has been created',
`migrate_from_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate from chat identifier.',
`migrate_to_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate to chat identifier.',
`pinned_message` TEXT NULL DEFAULT NULL COMMENT 'Pinned message, Message object.',
PRIMARY KEY (`chat_id`, `id`),
KEY `user_id` (`user_id`),
KEY `forward_from` (`forward_from`),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment