mirror of
https://github.com/QuasarApp/qTbot.git
synced 2025-05-19 16:39:35 +00:00
continue to implement new sendRequest
This commit is contained in:
parent
c607bde041
commit
2dc9417821
@ -10,6 +10,8 @@
|
|||||||
HttpException::HttpException(QNetworkReply::NetworkError code,
|
HttpException::HttpException(QNetworkReply::NetworkError code,
|
||||||
const QByteArray &erroString) {
|
const QByteArray &erroString) {
|
||||||
|
|
||||||
|
_code = code;
|
||||||
|
|
||||||
if (erroString.size()) {
|
if (erroString.size()) {
|
||||||
_errText = erroString;
|
_errText = erroString;
|
||||||
} else {
|
} else {
|
||||||
@ -31,3 +33,7 @@ QException *HttpException::clone() const {
|
|||||||
return new HttpException(QNetworkReply::NetworkError(0),
|
return new HttpException(QNetworkReply::NetworkError(0),
|
||||||
_errText);
|
_errText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QNetworkReply::NetworkError HttpException::code() const {
|
||||||
|
return _code;
|
||||||
|
}
|
||||||
|
@ -29,8 +29,11 @@ public:
|
|||||||
void raise() const;
|
void raise() const;
|
||||||
QException *clone() const;
|
QException *clone() const;
|
||||||
|
|
||||||
|
QNetworkReply::NetworkError code() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray _errText;
|
QByteArray _errText;
|
||||||
|
QNetworkReply::NetworkError _code;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HTTPEXCEPTION_H
|
#endif // HTTPEXCEPTION_H
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
//# of this license document, but changing it is not allowed.
|
//# of this license document, but changing it is not allowed.
|
||||||
//#
|
//#
|
||||||
|
|
||||||
|
#include "httpexception.h"
|
||||||
#include "telegramrestbot.h"
|
#include "telegramrestbot.h"
|
||||||
#include "qTbot/messages/telegramupdate.h"
|
#include "qTbot/messages/telegramupdate.h"
|
||||||
#include "qTbot/messages/telegramupdateanswer.h"
|
#include "qTbot/messages/telegramupdateanswer.h"
|
||||||
@ -13,7 +14,6 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <qTbot/messages/telegrammsg.h>
|
#include <qTbot/messages/telegrammsg.h>
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
namespace qTbot {
|
namespace qTbot {
|
||||||
|
|
||||||
@ -51,13 +51,12 @@ void TelegramRestBot::startUpdates() {
|
|||||||
if (delta >= _updateDelay) {
|
if (delta >= _updateDelay) {
|
||||||
auto&& replay = sendRequest(QSharedPointer<TelegramGetUpdate>::create(_lanstUpdateid + 1));
|
auto&& replay = sendRequest(QSharedPointer<TelegramGetUpdate>::create(_lanstUpdateid + 1));
|
||||||
|
|
||||||
connect(replay.get(), &QNetworkReply::finished,
|
replay.then([this](const QByteArray &result){
|
||||||
this, std::bind(&TelegramRestBot::handleReceiveUpdates, this, replay.toWeakRef()),
|
handleReceiveUpdates(result);
|
||||||
Qt::DirectConnection);
|
}).onFailed([this](const HttpException &e){
|
||||||
|
handleReceiveUpdatesErr(e.code());
|
||||||
|
|
||||||
connect(replay.get(), &QNetworkReply::errorOccurred,
|
} );
|
||||||
this, &TelegramRestBot::handleReceiveUpdatesErr,
|
|
||||||
Qt::DirectConnection);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -82,22 +81,19 @@ void TelegramRestBot::setProcessed(const QSet<unsigned long long> &newProcessed)
|
|||||||
IBot::setProcessed(newProcessed);
|
IBot::setProcessed(newProcessed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TelegramRestBot::handleReceiveUpdates(const QWeakPointer<QNetworkReply> &replay) {
|
void TelegramRestBot::handleReceiveUpdates(const QByteArray &replay) {
|
||||||
|
auto&& telegramMsg = makeMesasge<TelegramUpdateAnswer>(replay);
|
||||||
|
if (telegramMsg->isValid()) {
|
||||||
|
|
||||||
if (auto&& sharedReplay = replay.lock()) {
|
_lanstUpdateTime = QDateTime::currentMSecsSinceEpoch();
|
||||||
auto&& telegramMsg = makeMesasge<TelegramUpdateAnswer>(sharedReplay->readAll());
|
|
||||||
if (telegramMsg->isValid()) {
|
|
||||||
|
|
||||||
_lanstUpdateTime = QDateTime::currentMSecsSinceEpoch();
|
auto && resultArray = telegramMsg->result().toArray();
|
||||||
|
for (const auto& ref: resultArray) {
|
||||||
auto && resultArray = telegramMsg->result().toArray();
|
auto&& update = IBot::makeMesasge<TelegramUpdate>(ref.toObject());
|
||||||
for (const auto& ref: resultArray) {
|
incomeNewUpdate(update);
|
||||||
auto&& update = IBot::makeMesasge<TelegramUpdate>(ref.toObject());
|
if (_lanstUpdateid < update->updateId()) {
|
||||||
incomeNewUpdate(update);
|
_lanstUpdateid = update->updateId();
|
||||||
if (_lanstUpdateid < update->updateId()) {
|
};
|
||||||
_lanstUpdateid = update->updateId();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
void setProcessed(const QSet<unsigned long long> &newProcessed) override;
|
void setProcessed(const QSet<unsigned long long> &newProcessed) override;
|
||||||
private slots:
|
private slots:
|
||||||
void handleReceiveUpdates(const QWeakPointer<QNetworkReply>& replay);
|
void handleReceiveUpdates(const QByteArray &replay);
|
||||||
void handleReceiveUpdatesErr(QNetworkReply::NetworkError err);
|
void handleReceiveUpdatesErr(QNetworkReply::NetworkError err);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user