Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logout method #15

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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