Skip to content

Commit

Permalink
Merge pull request #15 from QuasarApp/fix_cb
Browse files Browse the repository at this point in the history
Added logout method
  • Loading branch information
EndrII authored Nov 25, 2023
2 parents 69b3b83 + b5d0b91 commit e989530
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/qTbot/src/public/qTbot/filewaiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace qTbot {
* @brief The FileWaiter class. This is a simple storage for the shared pointer of files.
* All added files will be removed (shared object) after finish donwload or upload.
*/
class FileWaiter: public QObject
class QTBOT_EXPORT FileWaiter: public QObject
{
Q_OBJECT
public:
Expand Down
4 changes: 4 additions & 0 deletions src/qTbot/src/public/qTbot/ibot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ IBot::~IBot() {
delete _manager;
}

void IBot::logout() {
setToken({});
}

const QByteArray &IBot::token() const {
return _token;
}
Expand Down
10 changes: 10 additions & 0 deletions src/qTbot/src/public/qTbot/ibot.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class QTBOT_EXPORT IBot: public QObject
*/
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
Expand Down Expand Up @@ -223,6 +228,11 @@ class QTBOT_EXPORT IBot: public QObject
*/
void sigReceiveUpdate(const QSharedPointer<iUpdate>& );

/**
* @brief sigStopRequire just custm event for stop bot if tou use services.
*/
void sigStopRequire();

private:
void doRemoveFinishedRequests();

Expand Down
6 changes: 6 additions & 0 deletions src/qTbot/src/public/qTbot/itelegrambot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,14 @@ bool ITelegramBot::sendMessageRequest(const QSharedPointer<iRequest> &rquest,
if (chatId) {
_lastMessageId[chatId] = messageID;
}

return;
}
}

if (msgIdCB) {
msgIdCB(-1);
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/qTbot/src/public/qTbot/messages/telegramlocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace qTbot {
/**
* @brief The TelegramLocation class just simple struct with latitude and longitude
*/
class TelegramLocation: public IJsonBasedObject
class QTBOT_EXPORT TelegramLocation: public IJsonBasedObject
{
public:
TelegramLocation();
Expand Down
10 changes: 10 additions & 0 deletions src/qTbot/src/public/qTbot/telegramrestbot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QJsonArray>
#include <QTimer>
#include <qTbot/messages/telegrammsg.h>
#include <limits>

namespace qTbot {

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


Expand Down
4 changes: 3 additions & 1 deletion src/qTbot/src/public/qTbot/telegramrestbot.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class QTBOT_EXPORT TelegramRestBot: public ITelegramBot
~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.
Expand All @@ -49,6 +50,7 @@ private slots:
private:
void startUpdates();

bool _run = false;
long long _lanstUpdateTime = 0;
unsigned long long _lanstUpdateid = 0;

Expand Down

0 comments on commit e989530

Please sign in to comment.