fix sending
Some checks failed
buildbot/DocsGenerator Build finished.
buildbot/AndroidBuilder_v8Qt6 Build finished.
buildbot/LinuxCMakeBuilderQt6 Build finished.

This commit is contained in:
Andrei Yankovich 2024-12-16 23:42:32 +01:00
parent 11e00f7e2d
commit 03782ba272
8 changed files with 49 additions and 13 deletions

View File

@ -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_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_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_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) 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) set(QTBOT_TESTS OFF CACHE BOOL "This option force disbled for ANDROID IOS QA_WASM32 and Not Qt projects" FORCE)

View File

@ -14,6 +14,11 @@ if (QTBOT_PRINT_RQUESTS)
add_definitions(-DQTBOT_PRINT_RQUESTS) add_definitions(-DQTBOT_PRINT_RQUESTS)
endif() endif()
if (QTBOT_PRINT_ERRORS)
add_definitions(-DQTBOT_PRINT_ERRORS)
endif()
file(GLOB_RECURSE SOURCE_CPP file(GLOB_RECURSE SOURCE_CPP
"src/*.cpp" "src/*.cpp"
"src/*.h" "src/*.h"

View File

@ -16,6 +16,8 @@ TelegramEditMessage::TelegramEditMessage(const QVariant &idEditedMessage,
setRequest("editMessageText"); setRequest("editMessageText");
addArg("message_id", idEditedMessage); addArg("message_id", idEditedMessage);
setPriority(args.requestPriority);
} }
} }

View File

@ -19,6 +19,8 @@ TelegramSendContact::TelegramSendContact(const TelegramArgs &args,
addArg("first_name", firstName); addArg("first_name", firstName);
addArg("last_name", lastName); addArg("last_name", lastName);
addArg("phone_number", phone); addArg("phone_number", phone);
setPriority(args.requestPriority);
} }

View File

@ -19,6 +19,7 @@ qTbot::TelegramSendFile::TelegramSendFile(const QString &request,
const ExtraJsonObjects& extraObjects const ExtraJsonObjects& extraObjects
): ):
TelegramSingleRquest(request, args.toMap(true)) { TelegramSingleRquest(request, args.toMap(true)) {
setPriority(args.requestPriority);
for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) { 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 TelegramArgs &args,
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects): const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects):
TelegramSingleRquest(request, args.toMap(true)) { TelegramSingleRquest(request, args.toMap(true)) {
setPriority(args.requestPriority);
QFile readFile(file.absoluteFilePath()); QFile readFile(file.absoluteFilePath());
if (!readFile.open(QIODevice::ReadOnly)) { if (!readFile.open(QIODevice::ReadOnly)) {

View File

@ -18,6 +18,8 @@ TelegramSendLocation::TelegramSendLocation(const TelegramArgs &args,
addArg("latitude", latitude); addArg("latitude", latitude);
addArg("longitude", longitude); addArg("longitude", longitude);
setPriority(args.requestPriority);
for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) { for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact)); addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact));

View File

@ -135,7 +135,11 @@ IBot::sendRequest(const QSharedPointer<iRequest> &rquest) {
_requestQueue.insert(makeKey(rquest->priority()), _requestQueue.insert(makeKey(rquest->priority()),
RequestData{rquest, "", responce}); RequestData{rquest, "", responce});
_requestExecutor->start(); if (!_requestExecutor->isActive()) {
handleEcxecuteRequest();
_requestExecutor->start();
}
return responce->future(); return responce->future();
} }
@ -145,10 +149,15 @@ IBot::sendRequest(const QSharedPointer<iRequest> &rquest,
const QString &pathToResult) { const QString &pathToResult) {
auto&& responce = QSharedPointer<QPromise<QByteArray>>::create(); auto&& responce = QSharedPointer<QPromise<QByteArray>>::create();
responce->start(); responce->start();
_requestQueue.insert(makeKey(rquest->priority()), _requestQueue.insert(makeKey(rquest->priority()),
RequestData{rquest, pathToResult, responce}); RequestData{rquest, pathToResult, responce});
_requestExecutor->start(); if (!_requestExecutor->isActive()) {
handleEcxecuteRequest();
_requestExecutor->start();
}
return responce->future(); return responce->future();
@ -217,7 +226,12 @@ void IBot::sendRequestPrivate(const QSharedPointer<iRequest> &rquest,
promise->finish(); promise->finish();
} else { } 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); setCurrentParallelActiveNetworkThreads(_currentParallelActiveNetworkThreads - 1);
@ -255,7 +269,11 @@ void IBot::sendRequestPrivate(const QSharedPointer<iRequest> &rquest,
connect(networkReplay, &QNetworkReply::finished, [this, promise, networkReplay, pathToResult](){ connect(networkReplay, &QNetworkReply::finished, [this, promise, networkReplay, pathToResult](){
if (networkReplay->error() == QNetworkReply::NoError) { 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 { } else {
promise->addResult(pathToResult.toUtf8()); // wil not work with UTF 8 path names promise->addResult(pathToResult.toUtf8()); // wil not work with UTF 8 path names
promise->finish(); promise->finish();

View File

@ -299,6 +299,7 @@ QFuture<QByteArray> ITelegramBot::getFile(const QString &fileId, FileType fileTy
if (!localFilePath.isEmpty()) { if (!localFilePath.isEmpty()) {
QPromise<QByteArray> fileDataResult; QPromise<QByteArray> fileDataResult;
fileDataResult.start();
if (fileType == FileType::Ram) { if (fileType == FileType::Ram) {
QFile localFile(localFilePath); 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){ 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()) { if (!future.isValid()) {
longWay->setException(InternalException("Failed to wrote file into internal cache!")); longWay->setException(InternalException("Failed to wrote file into internal cache!"));
return; return;
}; };
future.then([longWay](const QByteArray& data){ future.then([longWay](const QByteArray& data){
longWay->addResult(data); longWay->addResult(data);
}); longWay->finish();
}).onFailed([longWay](const QException& exep){
longWay->setException(exep);
});
}).onFailed([longWay](const QException& exep){ }).onFailed([longWay](const QException& exep){