From 81ab7f5e8929589b352a5f621cfb98fcb2929cec Mon Sep 17 00:00:00 2001 From: Mio Date: Tue, 20 Mar 2018 15:10:39 +0800 Subject: Make TgLongPoll constructed with user-specified parameters for getUpdates() instead of hard-code --- include/tgbot/net/TgLongPoll.h | 7 +++++-- src/net/TgLongPoll.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/tgbot/net/TgLongPoll.h b/include/tgbot/net/TgLongPoll.h index 949a2a4..3c0988a 100644 --- a/include/tgbot/net/TgLongPoll.h +++ b/include/tgbot/net/TgLongPoll.h @@ -36,8 +36,8 @@ namespace TgBot { class TgLongPoll { public: - TgLongPoll(const Api* api, const EventHandler* eventHandler); - TgLongPoll(const Bot& bot); + TgLongPoll(const Api* api, const EventHandler* eventHandler, int32_t, int32_t, const std::shared_ptr>&); + TgLongPoll(const Bot& bot, int32_t = 100, int32_t = 60, const std::shared_ptr>& = nullptr); /** * Starts long poll. After new update will come, this method will parse it and send to EventHandler which invokes your listeners. Designed to be executed in a loop. @@ -46,6 +46,9 @@ public: private: int32_t _lastUpdateId = 0; + int32_t _limit; + int32_t _timeout; + std::shared_ptr> _stringarrayptr; const Api* _api; const EventHandler* _eventHandler; }; diff --git a/src/net/TgLongPoll.cpp b/src/net/TgLongPoll.cpp index 91bf058..8d93991 100644 --- a/src/net/TgLongPoll.cpp +++ b/src/net/TgLongPoll.cpp @@ -24,14 +24,16 @@ namespace TgBot { -TgLongPoll::TgLongPoll(const Api* api, const EventHandler* eventHandler) : _api(api), _eventHandler(eventHandler) { +TgLongPoll::TgLongPoll(const Api* api, const EventHandler* eventHandler, int32_t limit, int32_t timeout, const std::shared_ptr>& stringarrayptr) + : _api(api), _eventHandler(eventHandler), _limit(limit), _timeout(timeout), _stringarrayptr(stringarrayptr) { } -TgLongPoll::TgLongPoll(const Bot& bot) : TgLongPoll(&bot.getApi(), &bot.getEventHandler()) { +TgLongPoll::TgLongPoll(const Bot& bot, int32_t limit, int32_t timeout, const std::shared_ptr>& stringarrayptr) : + TgLongPoll(&bot.getApi(), &bot.getEventHandler(), limit, timeout, stringarrayptr) { } void TgLongPoll::start() { - std::vector updates = _api->getUpdates(_lastUpdateId, 100, 60); + std::vector updates = _api->getUpdates(_lastUpdateId, _limit, _timeout, _stringarrayptr); for (Update::Ptr& item : updates) { if (item->updateId >= _lastUpdateId) { _lastUpdateId = item->updateId + 1; -- cgit v1.2.3