diff --git a/src/authority/storagehelper.cpp b/src/authority/storagehelper.cpp index fcdcc0ad78be2a39263c56d7f00724616f7ddf89..8690270f629e767da9363417849784e897ff3b04 100644 --- a/src/authority/storagehelper.cpp +++ b/src/authority/storagehelper.cpp @@ -268,6 +268,17 @@ createOrUpdateProfile(const QString& accountId, vcard::setProfile(accountId, profileInfo, isPeer); } +void +removeProfile(const QString& accountId, const QString& peerUri) +{ + auto accountLocalPath = getPath() + accountId + QDir::separator(); + auto fileName = QString(peerUri.toUtf8().toBase64()); + auto path = accountLocalPath + "profiles" + QDir::separator() + fileName + ".vcf"; + if (!QFile::remove(path)) { + qWarning() << "Couldn't remove vcard for" << peerUri << "at" << path; + } +} + QString getAccountAvatar(const QString& accountId) { @@ -672,7 +683,7 @@ deleteObsoleteHistory(Database& db, long int date) } void -removeContact(Database& db, const QString& contactUri) +removeContactConversations(Database& db, const QString& contactUri) { // Get common conversations auto conversations = getConversationsWithPeer(db, contactUri); diff --git a/src/authority/storagehelper.h b/src/authority/storagehelper.h index 09326ac7894f31cb21ad486fd5d108ccdbd9d123..9afaa6f896e279742314a7e134de62ef551de640 100644 --- a/src/authority/storagehelper.h +++ b/src/authority/storagehelper.h @@ -113,6 +113,13 @@ void createOrUpdateProfile(const QString& accountId, const api::profile::Info& profileInfo, const bool isPeer = false); +/** + * Remove a profile vCard + * @param accountId + * @param peerUri + */ +void removeProfile(const QString& accountId, const QString& peerUri); + /** * Gets the account's avatar from the profile.vcf file * @param accountId @@ -241,7 +248,9 @@ QString getInteractionExtraDataById(Database& db, const QString& id, const QStri * @param daemon id * @param interaction */ -void updateDataTransferInteractionForDaemonId(Database& db, const QString& daemonId, api::interaction::Info& interaction); +void updateDataTransferInteractionForDaemonId(Database& db, + const QString& daemonId, + api::interaction::Info& interaction); /** * Change the body of an interaction @@ -300,10 +309,11 @@ void deleteObsoleteHistory(Database& db, long int date); /** * Remove all conversation with a contact. Remove corresponding entries in * the conversations table. + * @param accountId * @param db * @param contactUri */ -void removeContact(Database& db, const QString& contactUri); +void removeContactConversations(Database& db, const QString& contactUri); /** * count number of 'UNREAD' from 'interactions' table. diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index b73de18f01559608901c50e2e7c7b4027acfb733..bb19a1de26af3a9b54e211e2e72a97440085878c 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -325,12 +325,14 @@ ContactModel::removeContact(const QString& contactUri, bool banned) return; } pimpl_->contacts.remove(contactUri); - storage::removeContact(pimpl_->db, contactUri); + storage::removeContactConversations(pimpl_->db, contactUri); + storage::removeProfile(owner.id, contactUri); emitContactRemoved = true; } else if (owner.profileInfo.type == profile::Type::SIP) { // Remove contact from db pimpl_->contacts.remove(contactUri); - storage::removeContact(pimpl_->db, contactUri); + storage::removeContactConversations(pimpl_->db, contactUri); + storage::removeProfile(owner.id, contactUri); emitContactRemoved = true; } } @@ -862,7 +864,8 @@ ContactModelPimpl::slotContactRemoved(const QString& accountId, bannedContacts.erase(it); } } - storage::removeContact(db, contactUri); + storage::removeContactConversations(db, contactUri); + storage::removeProfile(linked.owner.id, contactUri); contacts.remove(contactUri); } } diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index bd6fd4732ee3f010ad31c31fa8705863d96dbcb3..94007e855a1e669cc37d0efe2240ab066965e6ac 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -2372,7 +2372,7 @@ ConversationModelPimpl::slotConversationReady(const QString& accountId, // remove non swarm conversation if (conversation.isLegacy()) { eraseConversation(conversation.uid); - storage::removeContact(db, member["uri"]); + storage::removeContactConversations(db, member["uri"]); invalidateModel(); emit linked.conversationRemoved(conversation.uid); emit linked.modelChanged(); @@ -2561,6 +2561,7 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri) if (removeConversation) { eraseConversation(indexOf(contactUri)); invalidateModel(); + Q_EMIT linked.conversationRemoved(contactUri); emit linked.modelChanged(); } } @@ -2604,7 +2605,7 @@ ConversationModelPimpl::addConversationRequest(const MapStringString& convReques // update conversation and remoe conversation from db conv.mode = mode; conv.uid = convId; - storage::removeContact(db, peer); + storage::removeContactConversations(db, peer); invalidateModel(); emit linked.modelChanged(); return; @@ -2756,7 +2757,7 @@ ConversationModelPimpl::addSwarmConversation(const QString& convId) eraseConversation(conv.uid); invalidateModel(); Q_EMIT linked.conversationRemoved(conv.uid); - storage::removeContact(db, participantId); + storage::removeContactConversations(db, participantId); } } catch (...) { }