From 8f9bb3a71e6847dae837c7991f71296360c21906 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Fri, 6 Jan 2017 00:50:16 +0300 Subject: [PATCH] Small problems fixes. --- .../Resources/config/services.yml | 1 - .../Telegram/PrivateMessageProcessor.php | 19 +++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml index 61bbe9d..70c799d 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml @@ -135,4 +135,3 @@ services: - @doctrine.orm.entity_manager - @twig - %point_id% - - %point_login% \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/Telegram/PrivateMessageProcessor.php b/src/Skobkin/Bundle/PointToolsBundle/Service/Telegram/PrivateMessageProcessor.php index a030c54..54d6b26 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Service/Telegram/PrivateMessageProcessor.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/Telegram/PrivateMessageProcessor.php @@ -75,11 +75,6 @@ class PrivateMessageProcessor */ private $pointUserId; - /** - * @var string - */ - private $pointUserLogin; - public function __construct( TgLog $client, @@ -87,8 +82,7 @@ class PrivateMessageProcessor AccountFactory $accountFactory, EntityManagerInterface $em, \Twig_Environment $twig, - int $pointUserId, - string $pointUserLogin + int $pointUserId ) { $this->client = $client; @@ -97,7 +91,6 @@ class PrivateMessageProcessor $this->em = $em; $this->twig = $twig; $this->pointUserId = $pointUserId; - $this->pointUserLogin = $pointUserLogin; $this->userRepo = $em->getRepository('SkobkinPointToolsBundle:User'); $this->subscriptionRepo = $em->getRepository('SkobkinPointToolsBundle:Subscription'); @@ -167,7 +160,6 @@ class PrivateMessageProcessor case '/sub': case 'sub': - case 'subscribers': if (array_key_exists(1, $words)) { if (null !== $user = $this->userRepo->findUserByLogin($words[1])) { $this->sendUserSubscribers($sendMessage, $user); @@ -175,8 +167,11 @@ class PrivateMessageProcessor $this->sendError($sendMessage, 'User not found'); } } else { - $user = $this->userRepo->findUserByLogin($this->pointUserLogin); - $this->sendUserSubscribers($sendMessage, $user); + if ($user = $account->getUser()) { + $this->sendUserSubscribers($sendMessage, $user); + } else { + $this->sendError($sendMessage, 'Account not linked', 'You must /link your account first to be able to use this command.'); + } } break; @@ -298,7 +293,7 @@ class PrivateMessageProcessor private function createResponseMessage(Message $message, string $parseMode = self::PARSE_MODE_MARKDOWN, bool $disableWebPreview = false): SendMessage { $sendMessage = new SendMessage(); - $sendMessage->chat_id = $message->chat->id; + $sendMessage->chat_id = (string) $message->chat->id; $sendMessage->parse_mode = $parseMode; $sendMessage->disable_web_page_preview = $disableWebPreview;