From 74214fd6b960ba01907ca016ad1f766880d1fb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Mon, 28 Mar 2022 13:32:51 -0400 Subject: [PATCH] misc: cleanup some warnings Change-Id: Iba7379b89e33525a86619241b74dbf82f3c07d7d --- src/authority/storagehelper.cpp | 5 +---- src/contactmodel.cpp | 17 ++++++----------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/authority/storagehelper.cpp b/src/authority/storagehelper.cpp index 41ae87ce..d8110196 100644 --- a/src/authority/storagehelper.cpp +++ b/src/authority/storagehelper.cpp @@ -356,10 +356,8 @@ getAccountAvatar(const QString& accountId) QString filePath; filePath = accountLocalPath + "profile.vcf"; QFile file(filePath); - if (!file.open(QIODevice::ReadOnly)) { - qWarning() << "Can't open file: " << filePath; + if (!file.open(QIODevice::ReadOnly)) return {}; - } const auto vCard = lrc::vCard::utils::toHashMap(file.readAll()); const auto photo = (vCard.find(vCard::Property::PHOTO_PNG) == vCard.end()) ? vCard[vCard::Property::PHOTO_JPEG] @@ -384,7 +382,6 @@ buildContactFromProfile(const QString& accountId, QString filePath = accountLocalPath + "profiles/" + peer_uri + ".vcf"; file.setFileName(filePath); if (!file.open(QIODevice::ReadOnly)) { - qWarning().noquote() << "Can't open file: " << filePath; return {profileInfo, "", true, false}; } // rename it diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index fa98b7f1..0f043043 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -523,18 +523,15 @@ ContactModel::sendDhtMessage(const QString& contactUri, const QString& body) con const QString ContactModel::bestNameForContact(const QString& contactUri) const { - try { - auto contact = getContact(contactUri); + std::lock_guard<std::mutex> lk(pimpl_->contactsMtx_); + if (pimpl_->contacts.contains(contactUri)) { + auto contact = pimpl_->contacts.value(contactUri); auto alias = contact.profileInfo.alias.simplified(); - if (alias.isEmpty()) { return bestIdFromContactInfo(contact); } return alias; - } catch (const std::out_of_range& e) { - qDebug() << "ContactModel::bestNameForContact" << e.what(); } - return contactUri; } @@ -547,13 +544,11 @@ ContactModel::avatar(const QString& uri) const const QString ContactModel::bestIdForContact(const QString& contactUri) const { - try { - auto contact = getContact(contactUri); + std::lock_guard<std::mutex> lk(pimpl_->contactsMtx_); + if (pimpl_->contacts.contains(contactUri)) { + auto contact = pimpl_->contacts.value(contactUri); return bestIdFromContactInfo(contact); - } catch (const std::out_of_range& e) { - qDebug() << "ContactModel::bestIdForContact" << e.what(); } - return contactUri; } -- GitLab