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 ...@@ -572,6 +572,7 @@ class DB
$forward_date = self::getTimestamp($message->getForwardDate()); $forward_date = self::getTimestamp($message->getForwardDate());
$photo = $message->getPhoto(); $photo = $message->getPhoto();
$entities = $message->getEntities();
$new_chat_member = $message->getNewChatMember(); $new_chat_member = $message->getNewChatMember();
$new_chat_photo = $message->getNewChatPhoto(); $new_chat_photo = $message->getNewChatPhoto();
...@@ -596,14 +597,11 @@ class DB ...@@ -596,14 +597,11 @@ class DB
$type = $chat->getType(); $type = $chat->getType();
if ($migrate_to_chat_id) { if ($migrate_to_chat_id) {
$type = 'supergroup'; $type = 'supergroup';
$sth2->bindParam(':id', $migrate_to_chat_id, \PDO::PARAM_INT); $sth2->bindParam(':id', $migrate_to_chat_id, \PDO::PARAM_INT);
$sth2->bindParam(':oldid', $chat_id, \PDO::PARAM_INT); $sth2->bindParam(':oldid', $chat_id, \PDO::PARAM_INT);
} else { } else {
$sth2->bindParam(':id', $chat_id, \PDO::PARAM_INT); $sth2->bindParam(':id', $chat_id, \PDO::PARAM_INT);
$sth2->bindParam(':oldid', $migrate_to_chat_id, \PDO::PARAM_INT); $sth2->bindParam(':oldid', $migrate_to_chat_id, \PDO::PARAM_INT);
} }
...@@ -643,21 +641,21 @@ class DB ...@@ -643,21 +641,21 @@ class DB
$sth = self::$pdo->prepare('INSERT IGNORE INTO `' . TB_MESSAGE . '` $sth = self::$pdo->prepare('INSERT IGNORE INTO `' . TB_MESSAGE . '`
( (
`id`, `user_id`, `date`, `chat_id`, `forward_from`, `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`, `photo`, `sticker`, `video`, `voice`, `caption`, `contact`,
`location`, `venue`, `new_chat_member`, `left_chat_member`, `location`, `venue`, `new_chat_member`, `left_chat_member`,
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`, `new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_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 ( VALUES (
:message_id, :user_id, :date, :chat_id, :forward_from, :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, :photo, :sticker, :video, :voice, :caption, :contact,
:location, :venue, :new_chat_member, :left_chat_member, :location, :venue, :new_chat_member, :left_chat_member,
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created, :new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
:supergroup_chat_created, :channel_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(); $message_id = $message->getMessageId();
...@@ -689,6 +687,7 @@ class DB ...@@ -689,6 +687,7 @@ class DB
$channel_chat_created = $message->getChannelChatCreated(); $channel_chat_created = $message->getChannelChatCreated();
$migrate_from_chat_id = $message->getMigrateFromChatId(); $migrate_from_chat_id = $message->getMigrateFromChatId();
$migrate_to_chat_id = $message->getMigrateToChatId(); $migrate_to_chat_id = $message->getMigrateToChatId();
$pinned_message = $message->getPinnedMessage();
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
...@@ -700,9 +699,22 @@ class DB ...@@ -700,9 +699,22 @@ class DB
if ($reply_to_message_id) { if ($reply_to_message_id) {
$reply_chat_id = $chat_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_chat', $reply_chat_id, \PDO::PARAM_INT);
$sth->bindParam(':reply_to_message', $reply_to_message_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(':text', $text, \PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, \PDO::PARAM_STR);
$sth->bindParam(':audio', $audio, \PDO::PARAM_STR); $sth->bindParam(':audio', $audio, \PDO::PARAM_STR);
$sth->bindParam(':document', $document, \PDO::PARAM_STR); $sth->bindParam(':document', $document, \PDO::PARAM_STR);
...@@ -748,6 +760,8 @@ class DB ...@@ -748,6 +760,8 @@ class DB
$sth->bindParam(':channel_chat_created', $channel_chat_created, \PDO::PARAM_INT); $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_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(':migrate_to_chat_id', $migrate_to_chat_id, \PDO::PARAM_INT);
$sth->bindParam(':pinned_message', $pinned_message, \PDO::PARAM_INT);
$status = $sth->execute(); $status = $sth->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
......
...@@ -17,7 +17,7 @@ class InlineKeyboardMarkup extends Entity ...@@ -17,7 +17,7 @@ class InlineKeyboardMarkup extends Entity
protected $inline_keyboard; protected $inline_keyboard;
/* /*
* @todo: check for InlineKeyboardButton elements * @todo check for InlineKeyboardButton elements
*/ */
public function __construct($data = array()) public function __construct($data = array())
{ {
......
...@@ -250,6 +250,9 @@ class Message extends Entity ...@@ -250,6 +250,9 @@ class Message extends Entity
} }
$this->pinned_message = isset($data['pinned_message']) ? $data['pinned_message'] : null; $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; $this->entities = isset($data['entities']) ? $data['entities'] : null;
if (!empty($this->entities)) { if (!empty($this->entities)) {
......
...@@ -20,12 +20,12 @@ class MessageEntity extends Entity ...@@ -20,12 +20,12 @@ class MessageEntity extends Entity
public function __construct(array $data) public function __construct(array $data)
{ {
$this->type = isset($data['type']) ? $data['type'] : null; $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!'); throw new TelegramException('type is empty!');
} }
$this->offset = isset($data['offset']) ? $data['offset'] : null; $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!'); throw new TelegramException('offset is empty!');
} }
......
...@@ -19,6 +19,9 @@ class ReplyKeyboardMarkup extends Entity ...@@ -19,6 +19,9 @@ class ReplyKeyboardMarkup extends Entity
protected $one_time_keyboard; protected $one_time_keyboard;
protected $selective; protected $selective;
/*
* @todo check for KeyboardButton elements
*/
public function __construct($data = array()) public function __construct($data = array())
{ {
if (isset($data['keyboard'])) { if (isset($data['keyboard'])) {
......
...@@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS `message` (
`reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Chat identifier.', `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.', `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', `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', `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', `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', `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` ( ...@@ -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', `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_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.', `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`), PRIMARY KEY (`chat_id`, `id`),
KEY `user_id` (`user_id`), KEY `user_id` (`user_id`),
KEY `forward_from` (`forward_from`), 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