From ce702f32fb0a859b88e5ecb332d518956d814b20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 30 Oct 2017 17:08:38 -0400
Subject: [PATCH] migration: add daemon's contacts from old conversations

Change-Id: Id3c506c932ae91ec767944fa1dc5d90584ba7157
---
 src/database.cpp | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/database.cpp b/src/database.cpp
index 321e5e8c..46fb2c0d 100644
--- a/src/database.cpp
+++ b/src/database.cpp
@@ -41,6 +41,7 @@
 #include "api/interaction.h"
 
 // Lrc for migrations
+#include "dbus/configurationmanager.h"
 #include "person.h"
 #include "account.h"
 #include "accountmodel.h"
@@ -490,7 +491,8 @@ Database::migrateTextHistory()
                 auto account = AccountModel::instance().getById(peersObject["accountId"].toString().toUtf8());
                 if (!account) continue;
                 auto accountUri = account->username();
-                if (accountUri.startsWith("ring:")) {
+                auto isARingContact = accountUri.startsWith("ring:");
+                if (isARingContact) {
                     accountUri = accountUri.mid(QString("ring:").length());
                 }
                 auto accountIds = select("id", "profiles","uri=:uri", {{":uri", accountUri.toStdString()}}).payloads;
@@ -501,9 +503,15 @@ Database::migrateTextHistory()
                                {":status", "status"}},
                                {{":uri", peersObject["uri"].toString().toStdString()}, {":alias", ""},
                                {":photo", ""}, {":type", "RING"},
-                               {":status", "NONTRUSTED"}});
-                    // NOTE: this profile is in a case where it's not a contact for the daemon. So we choose to remove this contact from
-                    // conversations.
+                               {":status", "TRUSTED"}});
+                    // NOTE: this profile is in a case where it's not a contact for the daemon but a conversation with an account.
+                    // So we choose to add the profile to daemon's contacts
+                    if(isARingContact) {
+                        ConfigurationManager::instance().addContact(
+                            peersObject["accountId"].toString(),
+                            peersObject["uri"].toString()
+                        );
+                    }
                     contactIds = select("id", "profiles","uri=:uri", {{":uri", peersObject["uri"].toString().toStdString()}}).payloads;
                 }
                 if (accountIds.empty()) {
-- 
GitLab