From 21824e61e12db2641026874acbb99a7e03557b4e Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Mon, 19 Jul 2021 11:54:10 -0400 Subject: [PATCH] conversationmodel: remove temp/pending convs after adding When converting a temporary or invite into a permanent conversation adding the new conversation first will make it simpler to reselect the right conversation by keeping the to-be-removed conv data until the conversationReady signal has treated. Change-Id: Ibd8abaa9b7b7769853fc25a83bda495391581c89 --- src/conversationmodel.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index deac3e49..bd6fd473 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -2370,7 +2370,7 @@ ConversationModelPimpl::slotConversationReady(const QString& accountId, try { auto& conversation = getConversationForPeerUri(member["uri"]).get(); // remove non swarm conversation - if (conversation.mode == conversation::Mode::NON_SWARM) { + if (conversation.isLegacy()) { eraseConversation(conversation.uid); storage::removeContact(db, member["uri"]); invalidateModel(); @@ -2516,10 +2516,11 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri) { auto conv = storage::getConversationsWithPeer(db, contactUri); bool addConversation = false; + bool removeConversation = false; try { auto& conversation = getConversationForPeerUri(contactUri).get(); // swarm conversation we update when receive conversation ready signal. - if (conversation.mode != conversation::Mode::NON_SWARM) { + if (conversation.isSwarm()) { QStringList swarms = ConfigurationManager::instance().getConversations(linked.owner.id); bool needsSyncing = swarms.indexOf(conversation.uid) == -1; if (conversation.needsSyncing != needsSyncing) { @@ -2537,12 +2538,8 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri) conv.push_back(storage::beginConversationWithPeer(db, contactUri)); } // remove temporary conversation that was added when receiving an incoming request - auto conversationIdx = indexOf(contactUri); - if (conversationIdx >= 0) { - eraseConversation(conversationIdx); - invalidateModel(); - emit linked.modelChanged(); - } + removeConversation = indexOf(contactUri) != -1; + // add a conversation if not exists addConversation = indexOf(conv[0]) == -1; } catch (std::out_of_range&) { @@ -2561,6 +2558,11 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri) emit linked.conversationReady(conv[0], contactUri); emit linked.newConversation(conv[0]); } + if (removeConversation) { + eraseConversation(indexOf(contactUri)); + invalidateModel(); + emit linked.modelChanged(); + } } void -- GitLab