mirror of
https://github.com/QuasarApp/qTbot.git
synced 2025-04-26 05:44:32 +00:00
fix sending
This commit is contained in:
parent
11e00f7e2d
commit
03782ba272
@ -36,6 +36,7 @@ set(QTBOT_PACKAGE_ID "quasarapp.core.qTbot")
|
||||
option(QTBOT_TESTS "This option disables or enables tests of the ${PROJECT_NAME} project" ON)
|
||||
option(QTBOT_EXAMPLE "This option disables or enables example app of the ${PROJECT_NAME} project" ON)
|
||||
option(QTBOT_PRINT_RQUESTS "This option disables or enables printing requests" OFF)
|
||||
option(QTBOT_PRINT_ERRORS "This option disables or enables printing errors" ON)
|
||||
|
||||
if (ANDROID OR IOS OR QA_WASM32)
|
||||
set(QTBOT_TESTS OFF CACHE BOOL "This option force disbled for ANDROID IOS QA_WASM32 and Not Qt projects" FORCE)
|
||||
|
@ -14,6 +14,11 @@ if (QTBOT_PRINT_RQUESTS)
|
||||
add_definitions(-DQTBOT_PRINT_RQUESTS)
|
||||
endif()
|
||||
|
||||
if (QTBOT_PRINT_ERRORS)
|
||||
add_definitions(-DQTBOT_PRINT_ERRORS)
|
||||
endif()
|
||||
|
||||
|
||||
file(GLOB_RECURSE SOURCE_CPP
|
||||
"src/*.cpp"
|
||||
"src/*.h"
|
||||
|
@ -16,6 +16,8 @@ TelegramEditMessage::TelegramEditMessage(const QVariant &idEditedMessage,
|
||||
|
||||
setRequest("editMessageText");
|
||||
addArg("message_id", idEditedMessage);
|
||||
setPriority(args.requestPriority);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ TelegramSendContact::TelegramSendContact(const TelegramArgs &args,
|
||||
addArg("first_name", firstName);
|
||||
addArg("last_name", lastName);
|
||||
addArg("phone_number", phone);
|
||||
setPriority(args.requestPriority);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ qTbot::TelegramSendFile::TelegramSendFile(const QString &request,
|
||||
const ExtraJsonObjects& extraObjects
|
||||
):
|
||||
TelegramSingleRquest(request, args.toMap(true)) {
|
||||
setPriority(args.requestPriority);
|
||||
|
||||
|
||||
for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
|
||||
@ -33,6 +34,7 @@ qTbot::TelegramSendFile::TelegramSendFile(const QString &request,
|
||||
const TelegramArgs &args,
|
||||
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects):
|
||||
TelegramSingleRquest(request, args.toMap(true)) {
|
||||
setPriority(args.requestPriority);
|
||||
|
||||
QFile readFile(file.absoluteFilePath());
|
||||
if (!readFile.open(QIODevice::ReadOnly)) {
|
||||
|
@ -18,6 +18,8 @@ TelegramSendLocation::TelegramSendLocation(const TelegramArgs &args,
|
||||
|
||||
addArg("latitude", latitude);
|
||||
addArg("longitude", longitude);
|
||||
setPriority(args.requestPriority);
|
||||
|
||||
|
||||
for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
|
||||
addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact));
|
||||
|
@ -135,7 +135,11 @@ IBot::sendRequest(const QSharedPointer<iRequest> &rquest) {
|
||||
_requestQueue.insert(makeKey(rquest->priority()),
|
||||
RequestData{rquest, "", responce});
|
||||
|
||||
_requestExecutor->start();
|
||||
if (!_requestExecutor->isActive()) {
|
||||
handleEcxecuteRequest();
|
||||
_requestExecutor->start();
|
||||
|
||||
}
|
||||
|
||||
return responce->future();
|
||||
}
|
||||
@ -145,10 +149,15 @@ IBot::sendRequest(const QSharedPointer<iRequest> &rquest,
|
||||
const QString &pathToResult) {
|
||||
auto&& responce = QSharedPointer<QPromise<QByteArray>>::create();
|
||||
responce->start();
|
||||
|
||||
_requestQueue.insert(makeKey(rquest->priority()),
|
||||
RequestData{rquest, pathToResult, responce});
|
||||
|
||||
_requestExecutor->start();
|
||||
if (!_requestExecutor->isActive()) {
|
||||
handleEcxecuteRequest();
|
||||
_requestExecutor->start();
|
||||
|
||||
}
|
||||
|
||||
return responce->future();
|
||||
|
||||
@ -217,7 +226,12 @@ void IBot::sendRequestPrivate(const QSharedPointer<iRequest> &rquest,
|
||||
promise->finish();
|
||||
|
||||
} else {
|
||||
promise->setException(HttpException(networkReplay->error(), networkReplay->errorString().toLatin1() + networkReplay->readAll()));
|
||||
QByteArray msg = networkReplay->errorString().toLatin1() + networkReplay->readAll();
|
||||
promise->setException(HttpException(networkReplay->error(), msg));
|
||||
#ifdef QTBOT_PRINT_ERRORS
|
||||
qCritical() << msg;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
setCurrentParallelActiveNetworkThreads(_currentParallelActiveNetworkThreads - 1);
|
||||
@ -255,7 +269,11 @@ void IBot::sendRequestPrivate(const QSharedPointer<iRequest> &rquest,
|
||||
connect(networkReplay, &QNetworkReply::finished, [this, promise, networkReplay, pathToResult](){
|
||||
|
||||
if (networkReplay->error() == QNetworkReply::NoError) {
|
||||
promise->setException(HttpException(networkReplay->error(), networkReplay->errorString().toLatin1()));
|
||||
QByteArray msg = networkReplay->errorString().toLatin1();
|
||||
promise->setException(HttpException(networkReplay->error(), msg));
|
||||
#ifdef QTBOT_PRINT_ERRORS
|
||||
qCritical() << msg;
|
||||
#endif
|
||||
} else {
|
||||
promise->addResult(pathToResult.toUtf8()); // wil not work with UTF 8 path names
|
||||
promise->finish();
|
||||
|
@ -299,6 +299,7 @@ QFuture<QByteArray> ITelegramBot::getFile(const QString &fileId, FileType fileTy
|
||||
|
||||
if (!localFilePath.isEmpty()) {
|
||||
QPromise<QByteArray> fileDataResult;
|
||||
fileDataResult.start();
|
||||
|
||||
if (fileType == FileType::Ram) {
|
||||
QFile localFile(localFilePath);
|
||||
@ -353,18 +354,21 @@ QFuture<QByteArray> ITelegramBot::getFile(const QString &fileId, FileType fileTy
|
||||
}
|
||||
|
||||
future.then([this, fileId, fileType, longWay](const QByteArray& header){
|
||||
handleFileHeader(header);
|
||||
handleFileHeader(header);
|
||||
|
||||
auto&& future = getFile(fileId, fileType);
|
||||
auto&& future = getFile(fileId, fileType);
|
||||
|
||||
if (!future.isValid()) {
|
||||
longWay->setException(InternalException("Failed to wrote file into internal cache!"));
|
||||
return;
|
||||
};
|
||||
if (!future.isValid()) {
|
||||
longWay->setException(InternalException("Failed to wrote file into internal cache!"));
|
||||
return;
|
||||
};
|
||||
|
||||
future.then([longWay](const QByteArray& data){
|
||||
longWay->addResult(data);
|
||||
});
|
||||
future.then([longWay](const QByteArray& data){
|
||||
longWay->addResult(data);
|
||||
longWay->finish();
|
||||
}).onFailed([longWay](const QException& exep){
|
||||
longWay->setException(exep);
|
||||
});
|
||||
|
||||
|
||||
}).onFailed([longWay](const QException& exep){
|
||||
|
Loading…
x
Reference in New Issue
Block a user