|
12 | 12 | namespace TgBot { |
13 | 13 |
|
14 | 14 | TgLongPoll::TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t limit, std::int32_t timeout, std::shared_ptr<std::vector<std::string>> allowUpdates) |
15 | | - : _api(api), _eventHandler(eventHandler), _limit(limit), _timeout(timeout), |
16 | | - _allowUpdates(std::move(allowUpdates)) { |
| 15 | + : _api(api), _eventHandler(eventHandler), _limit(limit), _timeout(timeout) |
| 16 | + , _allowUpdates(std::move(allowUpdates)) { |
| 17 | + |
| 18 | + const_cast<TgBot::HttpClient&>(_api->_httpClient)._timeout = _timeout + 5; |
17 | 19 | } |
18 | 20 |
|
19 | | -TgLongPoll::TgLongPoll(const Bot& bot, std::int32_t limit, std::int32_t timeout, const std::shared_ptr<std::vector<std::string>>& allowUpdates) : |
20 | | - TgLongPoll(&bot.getApi(), &bot.getEventHandler(), limit, timeout, allowUpdates) { |
| 21 | +TgLongPoll::TgLongPoll(const Bot& bot, std::int32_t limit, std::int32_t timeout, const std::shared_ptr<std::vector<std::string>>& allowUpdates) |
| 22 | + : TgLongPoll(&bot.getApi(), &bot.getEventHandler(), limit, timeout, allowUpdates) { |
21 | 23 | } |
22 | 24 |
|
23 | 25 | void TgLongPoll::start() { |
24 | | - // get all unconfirmed updates |
25 | | - std::vector<Update::Ptr> updates = _api->getUpdates(0, _limit, _timeout, _allowUpdates); |
26 | | - |
27 | 26 | // handle updates |
28 | | - for (Update::Ptr& item : updates) { |
| 27 | + for (Update::Ptr& item : _updates) { |
29 | 28 | if (item->updateId >= _lastUpdateId) { |
30 | 29 | _lastUpdateId = item->updateId + 1; |
31 | 30 | } |
32 | 31 | _eventHandler->handleUpdate(item); |
33 | 32 | } |
34 | 33 |
|
35 | 34 | // confirm handled updates |
36 | | - _api->getUpdates(_lastUpdateId, _limit, _timeout, _allowUpdates); |
| 35 | + _updates = _api->getUpdates(_lastUpdateId, _limit, _timeout, _allowUpdates); |
37 | 36 | } |
38 | 37 |
|
39 | 38 | } |
0 commit comments