Commit 21824e61 authored by Andreas Traczyk's avatar Andreas Traczyk

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
parent e216f1c5
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment