diff --git a/src/authority/storagehelper.cpp b/src/authority/storagehelper.cpp index 9f8273572e621bcf1310c255d14694c6e88254f1..b2a59e088d9f269bfa0fe1181b416ce209bea941 100644 --- a/src/authority/storagehelper.cpp +++ b/src/authority/storagehelper.cpp @@ -29,6 +29,7 @@ #include <datatransfer_interface.h> #include <QImage> +#include <QByteArray> #include <QBuffer> #include <QJsonObject> #include <QJsonDocument> @@ -221,14 +222,17 @@ setProfile(const std::string& accountId, auto vcard = vcard::profileToVcard(profileInfo); auto accountLocalPath = getPath() + QString::fromStdString(accountId) + "/"; QString filePath; + QFile file; if (isPeer) { - filePath = accountLocalPath + "profiles/" + QString::fromStdString(profileInfo.uri) + ".vcf"; + filePath = accountLocalPath + "profiles/" + + QString(QByteArray::fromStdString(profileInfo.uri).toBase64()) + ".vcf"; + file.setFileName(filePath); } else { filePath = accountLocalPath + "profile" + ".vcf"; + file.setFileName(filePath); } - QFile file(filePath); if (!file.open(QIODevice::WriteOnly)) { - qWarning() << "Can't open file: " << filePath; + qWarning().noquote() << "Can't open file: " << filePath; return; } QTextStream(&file) << QString::fromStdString(vcard); @@ -298,12 +302,23 @@ buildContactFromProfile(const std::string & accountId, QString filePath; filePath = accountLocalPath + "profiles/" + QString::fromStdString(peer_uri) + ".vcf"; QFile file(filePath); + bool deleteOld = false; if (!file.open(QIODevice::ReadOnly)) { - qWarning() << "Can't open file: " << filePath; - return { profileInfo, "", true, false }; + qWarning().noquote() << "Can't open file: " << filePath << ". Trying Base64 file path."; + filePath = accountLocalPath + "profiles/" + QString(QByteArray::fromStdString(peer_uri).toBase64()) + ".vcf"; + file.setFileName(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning().noquote() << "Can't open file (base64 file path): " << filePath; + return { profileInfo, "", true, false }; + } + } else { + deleteOld = true; } QTextStream in(&file); QByteArray vcard = in.readAll().toUtf8(); + if (deleteOld) { + file.remove(); + } const auto vCard = lrc::vCard::utils::toHashMap(vcard); const auto alias = vCard[vCard::Property::FORMATTED_NAME]; const auto photo = (vCard.find(vCard::Property::PHOTO_PNG) == vCard.end()) ? diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index f19d3eece674726d29553afe8e82ced68c7b9a66..2ae1bce884ebdd52a8a47defabbc04bf8eb95e32 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -183,7 +183,7 @@ public Q_SLOTS: * Listen from contactModel when a new contact is added * @param uri */ - void slotContactAdded(const std::string& uri); + void slotContactAdded(const std::string& contactUri); /** * Listen from contactModel when a pending contact is accepted * @param uri @@ -1408,33 +1408,34 @@ ConversationModelPimpl::sendContactRequest(const std::string& contactUri) } void -ConversationModelPimpl::slotContactAdded(const std::string& uri) +ConversationModelPimpl::slotContactAdded(const std::string& contactUri) { auto type = linked.owner.profileInfo.type; + profile::Info profileInfo{ contactUri, {}, {}, type }; try { - auto contact = linked.owner.contactModel->getContact(uri); + auto contact = linked.owner.contactModel->getContact(contactUri); type = contact.profileInfo.type; + profileInfo.alias = contact.profileInfo.alias; } catch (...) {} - profile::Info profileInfo{ uri, {}, {}, type }; storage::createOrUpdateProfile(linked.owner.id, profileInfo, true); - auto conv = storage::getConversationsWithPeer(db, uri); + auto conv = storage::getConversationsWithPeer(db, profileInfo.uri); if (conv.empty()) { // pass conversation UID through only element - conv.emplace_back(storage::beginConversationWithPeer(db, uri)); + conv.emplace_back(storage::beginConversationWithPeer(db, profileInfo.uri)); } // Add the conversation if not already here if (indexOf(conv[0]) == -1) { - addConversationWith(conv[0], uri); + addConversationWith(conv[0], profileInfo.uri); emit linked.newConversation(conv[0]); } // delete temporary conversation if it exists and it has the uri of the added contact as uid - if (indexOf(uri) >= 0) { - conversations.erase(conversations.begin() + indexOf(uri)); + if (indexOf(profileInfo.uri) >= 0) { + conversations.erase(conversations.begin() + indexOf(profileInfo.uri)); } sortConversations(); - emit linked.conversationReady(uri); + emit linked.conversationReady(profileInfo.uri); emit linked.modelSorted(); }