Skip to content

Commit

Permalink
Merge pull request #1467 from r3bers/patch-1
Browse files Browse the repository at this point in the history
Fix to handling ForwardOrigin in DB layer.
  • Loading branch information
TiiFuchs authored May 28, 2024
2 parents 596cc9c + 73250c2 commit c3e099e
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
use Longman\TelegramBot\Entities\ChosenInlineResult;
use Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginChannel;
use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginChat;
use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginHiddenUser;
use Longman\TelegramBot\Entities\MessageOrigin\MessageOriginUser;
use Longman\TelegramBot\Entities\MessageReactionCountUpdated;
use Longman\TelegramBot\Entities\MessageReactionUpdated;
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery;
Expand Down Expand Up @@ -1273,15 +1277,31 @@ public static function insertMessageRequest(Message $message): bool
}

// Insert the forwarded message user in users table
$forward_date = $message->getForwardDate() ? self::getTimestamp($message->getForwardDate()) : null;

if ($forward_from = $message->getForwardFrom()) {
self::insertUser($forward_from);
$forward_from = $forward_from->getId();
}
if ($forward_from_chat = $message->getForwardFromChat()) {
self::insertChat($forward_from_chat);
$forward_from_chat = $forward_from_chat->getId();
$forward_from = null;
$forward_from_chat = null;
$forward_from_message_id = null;
$forward_signature = null;
$forward_sender_name = null;
$forward_date = null;

if ($forward_origin = $message->getForwardOrigin()) {
$forward_date = self::getTimestamp($forward_origin->getDate());

if ($forward_origin instanceof MessageOriginUser) {
self::insertUser($forward_origin->getSenderUser());
$forward_from = $forward_origin->getSenderUser()->getId();
} elseif ($forward_origin instanceof MessageOriginHiddenUser) {
$forward_sender_name = $forward_origin->getSenderUserName();
} elseif ($forward_origin instanceof MessageOriginChat) {
self::insertChat($forward_origin->getChat());
$forward_from_chat = $forward_origin->getChat()->getId();
$forward_signature = $forward_origin->getAuthorSignature();
} elseif ($forward_origin instanceof MessageOriginChannel) {
self::insertChat($forward_origin->getChat());
$forward_from_chat = $forward_origin->getChat()->getId();
$forward_from_message_id = $forward_origin->getMessageId();
$forward_signature = $forward_origin->getAuthorSignature();
}
}

$via_bot_id = null;
Expand Down Expand Up @@ -1359,9 +1379,9 @@ public static function insertMessageRequest(Message $message): bool
$sth->bindValue(':date', $date);
$sth->bindValue(':forward_from', $forward_from);
$sth->bindValue(':forward_from_chat', $forward_from_chat);
$sth->bindValue(':forward_from_message_id', $message->getForwardFromMessageId());
$sth->bindValue(':forward_signature', $message->getForwardSignature());
$sth->bindValue(':forward_sender_name', $message->getForwardSenderName());
$sth->bindValue(':forward_from_message_id', $forward_from_message_id);
$sth->bindValue(':forward_signature', $forward_signature);
$sth->bindValue(':forward_sender_name', $forward_sender_name);
$sth->bindValue(':forward_date', $forward_date);
$sth->bindValue(':is_topic_message', $message->getIsTopicMessage());

Expand Down

0 comments on commit c3e099e

Please sign in to comment.