M module-apps/application-call/ApplicationCall.cpp => module-apps/application-call/ApplicationCall.cpp +12 -19
@@ 215,30 215,23 @@ namespace app
{
LOG_INFO("add contact information: %s", number.c_str());
- auto searchResults = DBServiceAPI::ContactSearch(this, UTF8{}, UTF8{}, number);
- if (const auto resultsSize = searchResults->size(); resultsSize > 1) {
- LOG_FATAL("Found more than one contact for number %s", number.c_str());
- for (auto i : *searchResults) {
- LOG_FATAL("ContactID = %" PRIu32, i.ID);
- }
- }
- else if (resultsSize == 1) {
- const auto &contactRecord = searchResults->front();
+ auto numberView = utils::PhoneNumber(number).getView();
+ auto searchResults = DBServiceAPI::MatchContactByPhoneNumber(this, numberView);
+ if (searchResults != nullptr) {
LOG_INFO("Found contact matching search num %s : contact ID %" PRIu32 " - %s %s",
number.c_str(),
- contactRecord.ID,
- contactRecord.primaryName.c_str(),
- contactRecord.alternativeName.c_str());
- app::manager::Controller::sendAction(
- this,
- app::manager::actions::AddContact,
- std::make_unique<PhonebookItemData>(std::make_shared<ContactRecord>(contactRecord)));
+ searchResults->ID,
+ searchResults->primaryName.c_str(),
+ searchResults->alternativeName.c_str());
+ app::manager::Controller::sendAction(this,
+ app::manager::actions::EditContact,
+ std::make_unique<PhonebookItemData>(std::move(searchResults)));
}
else {
- ContactRecord contactRecord;
- contactRecord.numbers.emplace_back(ContactRecord::Number(utils::PhoneNumber(number).getView()));
+ auto contactRecord = std::make_shared<ContactRecord>();
+ contactRecord->numbers.emplace_back(std::move(numberView));
- auto data = std::make_unique<PhonebookItemData>(std::make_shared<ContactRecord>(contactRecord));
+ auto data = std::make_unique<PhonebookItemData>(std::move(contactRecord));
data->ignoreCurrentWindowOnStack = true;
app::manager::Controller::sendAction(
this, manager::actions::AddContact, std::move(data), manager::OnSwitchBehaviour::RunInBackground);
M module-services/service-db/DBServiceAPI.cpp => module-services/service-db/DBServiceAPI.cpp +3 -3
@@ 137,9 137,9 @@ auto DBServiceAPI::MatchContactByPhoneNumber(sys::Service *serv, const utils::Ph
{
auto msg = std::make_shared<DBContactNumberMessage>(numberView);
- auto ret = sys::Bus::SendUnicast(msg, service::name::db, serv, DefaultTimeoutInMs);
+ auto ret = sys::Bus::SendUnicast(std::move(msg), service::name::db, serv, DefaultTimeoutInMs);
auto contactResponse = dynamic_cast<DBContactNumberResponseMessage *>(ret.second.get());
- if (contactResponse == nullptr) {
+ if (contactResponse == nullptr || contactResponse->retCode != sys::ReturnCodes::Success) {
LOG_ERROR("DB response error, return code: %s", c_str(ret.first));
return nullptr;
}
@@ 241,7 241,7 @@ auto DBServiceAPI::ContactSearch(sys::Service *serv, UTF8 primaryName, UTF8 alte
(alternativeName.length() > 0) ? alternativeName.c_str() : "",
(number.length() > 0) ? number.c_str() : "");
- auto ret = sys::Bus::SendUnicast(msg, service::name::db, serv, DefaultTimeoutInMs);
+ auto ret = sys::Bus::SendUnicast(std::move(msg), service::name::db, serv, DefaultTimeoutInMs);
auto contactResponse = dynamic_cast<DBContactResponseMessage *>(ret.second.get());
if (contactResponse == nullptr) {
LOG_ERROR("DB response error, return code: %s", c_str(ret.first));
M module-services/service-db/ServiceDB.cpp => module-services/service-db/ServiceDB.cpp +1 -1
@@ 334,7 334,7 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys::
if (ret.has_value()) {
responseMsg = std::make_shared<DBContactNumberResponseMessage>(
- sys::ReturnCodes::Success, std::make_unique<ContactRecord>(ret->contact));
+ sys::ReturnCodes::Success, std::make_unique<ContactRecord>(std::move(ret->contact)));
}
else {
responseMsg = std::make_shared<DBContactNumberResponseMessage>(sys::ReturnCodes::Failure,