From 457e9b4fc823fd07f6831828fc9cbacf8847f2e8 Mon Sep 17 00:00:00 2001 From: Alek Rudnik Date: Thu, 6 May 2021 15:52:32 +0200 Subject: [PATCH] [EGD-3542] Fix issue with sending text messages form new message window Fixed too short timeout for sending sms Fixed flow for switching to thred window to asynchornous one Fixed some minor issues connected to new sms error handling --- .../windows/NewMessage.cpp | 35 +++++++++++-------- .../windows/NewMessage.hpp | 1 - module-cellular/at/src/ATFactory.cpp | 20 +++++------ .../service-cellular/ServiceCellular.cpp | 8 ++--- module-services/service-db/DBServiceAPI.cpp | 21 ----------- .../service-db/service-db/DBServiceAPI.hpp | 5 --- .../service-desktop/tests/test-contacts.cpp | 6 ---- 7 files changed, 35 insertions(+), 61 deletions(-) diff --git a/module-apps/application-messages/windows/NewMessage.cpp b/module-apps/application-messages/windows/NewMessage.cpp index 5048c3090e9c26fe337811c468ab5b955d2fcc3d..80c6fe4973cf5e06f2785e53e698ceb94f0bb4ae 100644 --- a/module-apps/application-messages/windows/NewMessage.cpp +++ b/module-apps/application-messages/windows/NewMessage.cpp @@ -126,6 +126,7 @@ namespace gui LOG_ERROR("Failed to send the SMS."); return false; } + setFocusItem(nullptr); // to make sure it is not possible to send text message multiple times return switchToThreadWindow(number.getView()); } @@ -142,22 +143,28 @@ namespace gui bool NewMessageWindow::switchToThreadWindow(const utils::PhoneNumber::View &number) { - auto thread = DBServiceAPI::ThreadGetByNumber(application, number, getThreadTimeout.count()); - if (!thread) { - LOG_FATAL("No thread and thread not created!"); - return false; - } + auto query = std::make_unique(number); + auto task = app::AsyncQuery::createFromQuery(std::move(query), db::Interface::Name::SMSThread); + task->setCallback([this](auto response) { + const auto result = dynamic_cast(response); + if (result == nullptr) { + return false; + } + // clear data only when message is sent + contact = nullptr; + phoneNumber.clear(); + recipient->clear(); + message->clear(); + setFocusItem(body); - // clear data only when message is sent - contact = nullptr; - phoneNumber.clear(); - recipient->clear(); - message->clear(); - setFocusItem(body); + const auto &thread = result->getThread(); + auto switchData = std::make_unique(std::make_unique(thread)); + switchData->ignoreCurrentWindowOnStack = true; + application->switchWindow(gui::name::window::thread_view, std::move(switchData)); + return true; + }); + task->execute(application, this); - auto switchData = std::make_unique(std::move(thread)); - switchData->ignoreCurrentWindowOnStack = true; - application->switchWindow(gui::name::window::thread_view, std::move(switchData)); return true; } diff --git a/module-apps/application-messages/windows/NewMessage.hpp b/module-apps/application-messages/windows/NewMessage.hpp index ef84f85996e459ca079396e9627f74a2af368b93..75b48e8afedc74c5072d3717d474650406d10d6a 100644 --- a/module-apps/application-messages/windows/NewMessage.hpp +++ b/module-apps/application-messages/windows/NewMessage.hpp @@ -38,7 +38,6 @@ namespace gui -> bool; void storeMessageDraft(const utils::PhoneNumber::View &number, const UTF8 &text); void storeMessageDraft(SMSRecord &sms, const UTF8 &text); - static inline constexpr std::chrono::milliseconds getThreadTimeout{1000}; gui::Text *recipient = nullptr; gui::Text *message = nullptr; gui::VBox *body = nullptr; diff --git a/module-cellular/at/src/ATFactory.cpp b/module-cellular/at/src/ATFactory.cpp index 966ef4a9f102f33f1f8fbdd9d371b283788c35bc..0762818e4cc4a7311a829d535a33fb8fad8435e1 100644 --- a/module-cellular/at/src/ATFactory.cpp +++ b/module-cellular/at/src/ATFactory.cpp @@ -28,7 +28,7 @@ namespace at {AT::CRC_ON, {"AT+CRC=1"}}, {AT::CALLER_NUMBER_PRESENTATION, {"AT+CLIP=1", default_long_timeout}}, {AT::SMS_TEXT_FORMAT, {"AT+CMGF=1"}}, - {AT::SMS_UCSC2, {"AT+CSCS=\"UCS2\"", 1s}}, + {AT::SMS_UCSC2, {"AT+CSCS=\"UCS2\""}}, {AT::SMS_GSM, {"AT+CSCS=\"GSM\""}}, {AT::QSCLK_ON, {"AT+QSCLK=1"}}, {AT::QDAI, {"AT+QDAI?"}}, @@ -39,9 +39,9 @@ namespace at {AT::CMGD, {"AT+CMGD="}}, {AT::CNUM, {"AT+CNUM"}}, {AT::CIMI, {"AT+CIMI"}}, - {AT::QCMGR, {"AT+QCMGR=", 12s}}, - {AT::ATH, {"ATH", 90s}}, - {AT::ATA, {"ATA", 90s}}, + {AT::QCMGR, {"AT+QCMGR=", 180s}}, + {AT::ATH, {"ATH", 100s}}, + {AT::ATA, {"ATA", 100s}}, {AT::ATD, {"ATD", 6s}}, {AT::IPR, {"AT+IPR="}}, {AT::CMUX, {"AT+CMUX="}}, @@ -50,11 +50,11 @@ namespace at {AT::CFUN_MIN_FUNCTIONALITY, {"AT+CFUN=0", default_long_timeout}}, {AT::CFUN_FULL_FUNCTIONALITY, {"AT+CFUN=1", default_long_timeout}}, {AT::CFUN_DISABLE_TRANSMITTING, {"AT+CFUN=4", default_long_timeout}}, - {AT::CMGS, {"AT+CMGS=\"", 120s}}, // verified in docs - {AT::QCMGS, {"AT+QCMGS=\"", 120s}}, // verified in docs + {AT::CMGS, {"AT+CMGS=\"", 180s}}, // + {AT::QCMGS, {"AT+QCMGS=\"", 180s}}, {AT::CREG, {"AT+CREG?"}}, {AT::QNWINFO, {"AT+QNWINFO"}}, - {AT::COPS, {"AT+COPS", 180s}}, + {AT::COPS, {"AT+COPS", 200s}}, {AT::QSIMSTAT, {"AT+QSIMSTAT?"}}, {AT::SIM_DET, {"AT+QSIMDET?"}}, {AT::SIM_DET_ON, {"AT+QSIMDET=1,0"}}, @@ -67,9 +67,9 @@ namespace at {AT::QIGETERROR, {"AT+QIGETERROR"}}, {AT::VTS, {"AT+VTS=", default_long_timeout}}, {AT::QLDTMF, {"AT+QLDTMF=1,"}}, - {AT::CUSD_OPEN_SESSION, {"AT+CUSD=1", 120s}}, - {AT::CUSD_CLOSE_SESSION, {"AT+CUSD=2", 120s}}, - {AT::CUSD_SEND, {"AT+CUSD=1,", 120s}}, + {AT::CUSD_OPEN_SESSION, {"AT+CUSD=1", 150s}}, + {AT::CUSD_CLOSE_SESSION, {"AT+CUSD=2", 150s}}, + {AT::CUSD_SEND, {"AT+CUSD=1,", 150s}}, {AT::SET_SMS_STORAGE, {"AT+CPMS=\"SM\",\"SM\",\"SM\""}}, {AT::CPIN, {"AT+CPIN=", default_long_timeout}}, {AT::GET_CPIN, {"AT+CPIN?", default_long_timeout}}, diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 58758951e2d99b053fdd7cb423c29c1ebda9898e..96456e5137d937ec39e9110ba979ad1e937ba4aa 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -986,7 +986,7 @@ bool ServiceCellular::handle_audio_conf_procedure() auto ServiceCellular::handle(db::query::SMSSearchByTypeResult *response) -> bool { if (response->getResults().size() > 0) { - LOG_DEBUG("sending %ud last queued message(s)", static_cast(response->getResults().size())); + LOG_DEBUG("sending %u last queued message(s)", static_cast(response->getResults().size())); if (Store::GSM::get()->simCardInserted() == false) { auto message = std::make_shared(); bus.sendUnicast(std::move(message), app::manager::ApplicationManager::ServiceName); @@ -1378,10 +1378,10 @@ auto ServiceCellular::sendSMS(SMSRecord record) -> bool record.type = SMSType::OUTBOX; } else { - LOG_INFO("SMS sending failed."); + LOG_ERROR("SMS sending failed."); record.type = SMSType::FAILED; - if (checkSmsCenter(*channel)) { - LOG_ERROR("SMS center check"); + if (!checkSmsCenter(*channel)) { + LOG_ERROR("SMS center check failed"); } } DBServiceAPI::GetQuery(this, db::Interface::Name::SMS, std::make_unique(std::move(record))); diff --git a/module-services/service-db/DBServiceAPI.cpp b/module-services/service-db/DBServiceAPI.cpp index d162be5b676a474b0105512f1b49eb26d9984154..8d2514ec9d8000a5ac0c1b5574bafd508ca8e111 100644 --- a/module-services/service-db/DBServiceAPI.cpp +++ b/module-services/service-db/DBServiceAPI.cpp @@ -26,27 +26,6 @@ struct NotesRecord; -auto DBServiceAPI::ThreadGetByNumber(sys::Service *serv, - const utils::PhoneNumber::View &phoneNumber, - std::uint32_t timeout) -> std::unique_ptr -{ - auto [code, msg] = DBServiceAPI::GetQueryWithReply( - serv, db::Interface::Name::SMSThread, std::make_unique(phoneNumber), timeout); - - if (code == sys::ReturnCodes::Success && msg != nullptr) { - auto queryResponse = dynamic_cast(msg.get()); - assert(queryResponse != nullptr); - - auto threadResponse = queryResponse->getResult(); - auto threadResult = dynamic_cast(threadResponse.get()); - assert(threadResult != nullptr); - - return std::make_unique(threadResult->getThread()); - } - - return nullptr; -} - auto DBServiceAPI::ContactGetByID(sys::Service *serv, uint32_t contactID) -> std::unique_ptr> { ContactRecord rec; diff --git a/module-services/service-db/service-db/DBServiceAPI.hpp b/module-services/service-db/service-db/DBServiceAPI.hpp index 17333b516ce26225745864ed2a33793b4949c203..7ca46c1ef2621cb8d3cdcb17c4763cbf30c9b061 100644 --- a/module-services/service-db/service-db/DBServiceAPI.hpp +++ b/module-services/service-db/service-db/DBServiceAPI.hpp @@ -47,11 +47,6 @@ class DBServiceAPI success }; - [[deprecated]] static auto ThreadGetByNumber(sys::Service *serv, - const utils::PhoneNumber::View &phoneNumber, - std::uint32_t timeout = DefaultTimeoutInMs) - -> std::unique_ptr; - /** * Queries the database. * @param serv Sender service. diff --git a/module-services/service-desktop/tests/test-contacts.cpp b/module-services/service-desktop/tests/test-contacts.cpp index 1798e7961731ffde0fe4432ab96a9f803f270d3c..46a65432af561202f42ece6e69d23e1107ac72e5 100644 --- a/module-services/service-desktop/tests/test-contacts.cpp +++ b/module-services/service-desktop/tests/test-contacts.cpp @@ -35,12 +35,6 @@ std::pair DBServiceAPI::GetQuery(sys::Service *serv, return std::make_pair(true, 0); } -auto DBServiceAPI::ThreadGetByNumber(sys::Service *serv, - const utils::PhoneNumber::View &phoneNumber, - std::uint32_t timeout) -> std::unique_ptr -{ - return nullptr; -} auto DBServiceAPI::GetQueryWithReply(sys::Service *serv, db::Interface::Name database,