From b5d0b9164eea593e9ef3e56e8726627e883b316c Mon Sep 17 00:00:00 2001 From: EndrII Date: Tue, 21 Nov 2023 21:05:43 +0100 Subject: [PATCH] added logout method --- src/qTbot/src/public/qTbot/ibot.cpp | 4 ++++ src/qTbot/src/public/qTbot/ibot.h | 10 ++++++++++ src/qTbot/src/public/qTbot/telegramrestbot.cpp | 10 ++++++++++ src/qTbot/src/public/qTbot/telegramrestbot.h | 4 +++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/qTbot/src/public/qTbot/ibot.cpp b/src/qTbot/src/public/qTbot/ibot.cpp index a5fbb03..222d990 100644 --- a/src/qTbot/src/public/qTbot/ibot.cpp +++ b/src/qTbot/src/public/qTbot/ibot.cpp @@ -21,6 +21,10 @@ IBot::~IBot() { delete _manager; } +void IBot::logout() { + setToken({}); +} + const QByteArray &IBot::token() const { return _token; } diff --git a/src/qTbot/src/public/qTbot/ibot.h b/src/qTbot/src/public/qTbot/ibot.h index 3288d5a..e3f4fd8 100644 --- a/src/qTbot/src/public/qTbot/ibot.h +++ b/src/qTbot/src/public/qTbot/ibot.h @@ -45,6 +45,11 @@ public: */ virtual bool login(const QByteArray& token) = 0; + /** + * @brief login This method remove login token of bot. + */ + virtual void logout(); + /** * @brief sendMessage This method sents text to the selected chat. * @param chatId This is selected chat id @@ -223,6 +228,11 @@ signals: */ void sigReceiveUpdate(const QSharedPointer& ); + /** + * @brief sigStopRequire just custm event for stop bot if tou use services. + */ + void sigStopRequire(); + private: void doRemoveFinishedRequests(); diff --git a/src/qTbot/src/public/qTbot/telegramrestbot.cpp b/src/qTbot/src/public/qTbot/telegramrestbot.cpp index 6ec0ac5..3da9e80 100644 --- a/src/qTbot/src/public/qTbot/telegramrestbot.cpp +++ b/src/qTbot/src/public/qTbot/telegramrestbot.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace qTbot { @@ -28,13 +29,22 @@ bool TelegramRestBot::login(const QByteArray &token) { } _lanstUpdateTime = QDateTime::currentMSecsSinceEpoch(); + _run = true; startUpdates(); return true; } +void TelegramRestBot::logout() { + _run = false; + ITelegramBot::logout(); +} + void TelegramRestBot::startUpdates() { + if (!_run) + return; + long long delta = QDateTime::currentMSecsSinceEpoch() - _lanstUpdateTime; diff --git a/src/qTbot/src/public/qTbot/telegramrestbot.h b/src/qTbot/src/public/qTbot/telegramrestbot.h index 624c2f4..43e5864 100644 --- a/src/qTbot/src/public/qTbot/telegramrestbot.h +++ b/src/qTbot/src/public/qTbot/telegramrestbot.h @@ -26,8 +26,9 @@ public: ~TelegramRestBot(); // IBot interface - bool login(const QByteArray &token); + bool login(const QByteArray &token) override; + void logout() override; /** * @brief updateDelay This is interval "how many msec bot will be wait for sent next request of updates" By defaul is 1000 msecs. @@ -49,6 +50,7 @@ private slots: private: void startUpdates(); + bool _run = false; long long _lanstUpdateTime = 0; unsigned long long _lanstUpdateid = 0;