Skip to content

Commit e989530

Browse files
authored
Merge pull request #15 from QuasarApp/fix_cb
Added logout method
2 parents 69b3b83 + b5d0b91 commit e989530

File tree

7 files changed

+35
-3
lines changed

7 files changed

+35
-3
lines changed

src/qTbot/src/public/qTbot/filewaiter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace qTbot {
1717
* @brief The FileWaiter class. This is a simple storage for the shared pointer of files.
1818
* All added files will be removed (shared object) after finish donwload or upload.
1919
*/
20-
class FileWaiter: public QObject
20+
class QTBOT_EXPORT FileWaiter: public QObject
2121
{
2222
Q_OBJECT
2323
public:

src/qTbot/src/public/qTbot/ibot.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ IBot::~IBot() {
2121
delete _manager;
2222
}
2323

24+
void IBot::logout() {
25+
setToken({});
26+
}
27+
2428
const QByteArray &IBot::token() const {
2529
return _token;
2630
}

src/qTbot/src/public/qTbot/ibot.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class QTBOT_EXPORT IBot: public QObject
4545
*/
4646
virtual bool login(const QByteArray& token) = 0;
4747

48+
/**
49+
* @brief login This method remove login token of bot.
50+
*/
51+
virtual void logout();
52+
4853
/**
4954
* @brief sendMessage This method sents text to the selected chat.
5055
* @param chatId This is selected chat id
@@ -223,6 +228,11 @@ class QTBOT_EXPORT IBot: public QObject
223228
*/
224229
void sigReceiveUpdate(const QSharedPointer<iUpdate>& );
225230

231+
/**
232+
* @brief sigStopRequire just custm event for stop bot if tou use services.
233+
*/
234+
void sigStopRequire();
235+
226236
private:
227237
void doRemoveFinishedRequests();
228238

src/qTbot/src/public/qTbot/itelegrambot.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,14 @@ bool ITelegramBot::sendMessageRequest(const QSharedPointer<iRequest> &rquest,
505505
if (chatId) {
506506
_lastMessageId[chatId] = messageID;
507507
}
508+
509+
return;
508510
}
509511
}
512+
513+
if (msgIdCB) {
514+
msgIdCB(-1);
515+
}
510516
});
511517
}
512518

src/qTbot/src/public/qTbot/messages/telegramlocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace qTbot {
1616
/**
1717
* @brief The TelegramLocation class just simple struct with latitude and longitude
1818
*/
19-
class TelegramLocation: public IJsonBasedObject
19+
class QTBOT_EXPORT TelegramLocation: public IJsonBasedObject
2020
{
2121
public:
2222
TelegramLocation();

src/qTbot/src/public/qTbot/telegramrestbot.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <QJsonArray>
1414
#include <QTimer>
1515
#include <qTbot/messages/telegrammsg.h>
16+
#include <limits>
1617

1718
namespace qTbot {
1819

@@ -28,13 +29,22 @@ bool TelegramRestBot::login(const QByteArray &token) {
2829
}
2930

3031
_lanstUpdateTime = QDateTime::currentMSecsSinceEpoch();
32+
_run = true;
3133

3234
startUpdates();
3335

3436
return true;
3537
}
3638

39+
void TelegramRestBot::logout() {
40+
_run = false;
41+
ITelegramBot::logout();
42+
}
43+
3744
void TelegramRestBot::startUpdates() {
45+
if (!_run)
46+
return;
47+
3848
long long delta = QDateTime::currentMSecsSinceEpoch() - _lanstUpdateTime;
3949

4050

src/qTbot/src/public/qTbot/telegramrestbot.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class QTBOT_EXPORT TelegramRestBot: public ITelegramBot
2626
~TelegramRestBot();
2727

2828
// IBot interface
29-
bool login(const QByteArray &token);
29+
bool login(const QByteArray &token) override;
3030

31+
void logout() override;
3132

3233
/**
3334
* @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:
4950
private:
5051
void startUpdates();
5152

53+
bool _run = false;
5254
long long _lanstUpdateTime = 0;
5355
unsigned long long _lanstUpdateid = 0;
5456

0 commit comments

Comments
 (0)