added logout method
All checks were successful
buildbot/DocsGenerator Build finished.
buildbot/WindowsCMakeBuilder Build finished.
buildbot/AndroidBuilder_v8Qt6 Build finished.
buildbot/LinuxCMakeBuilderQt6 Build finished.
buildbot/IOSCMakeBuilder Build finished.

This commit is contained in:
Andrei Yankovich 2023-11-21 21:05:43 +01:00
parent 3a3460945c
commit b5d0b9164e
4 changed files with 27 additions and 1 deletions

View File

@ -21,6 +21,10 @@ IBot::~IBot() {
delete _manager;
}
void IBot::logout() {
setToken({});
}
const QByteArray &IBot::token() const {
return _token;
}

View File

@ -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<iUpdate>& );
/**
* @brief sigStopRequire just custm event for stop bot if tou use services.
*/
void sigStopRequire();
private:
void doRemoveFinishedRequests();

View File

@ -13,6 +13,7 @@
#include <QJsonArray>
#include <QTimer>
#include <qTbot/messages/telegrammsg.h>
#include <limits>
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;

View File

@ -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;