From acc0c972344650564f053cd26cbe0d75a3eb620f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 27 May 2024 11:47:43 -0400
Subject: [PATCH] contactmodel: fix contact initialization when linking a new
 device

getContacts() is called before sync is finished. This should be
done like conversations, after first initializing.
This fix the presence showing after sync.

GitLab: #1627
Change-Id: I4ec9b7e34b5bd93b9ae4437e6c6719dbc3b78a98
---
 src/libclient/accountmodel.cpp   | 3 ++-
 src/libclient/api/contactmodel.h | 2 ++
 src/libclient/contactmodel.cpp   | 5 +++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/libclient/accountmodel.cpp b/src/libclient/accountmodel.cpp
index a7f00cdf5..955650c4f 100644
--- a/src/libclient/accountmodel.cpp
+++ b/src/libclient/accountmodel.cpp
@@ -531,11 +531,12 @@ AccountModelPimpl::slotAccountStatusChanged(const QString& accountID,
         if (status != api::account::Status::INITIALIZING
             && accountInfo.status == api::account::Status::INITIALIZING) {
             // Detect when a new account is generated (keys are ready). During
-            // the generation, a Ring account got the "INITIALIZING" status.
+            // the generation, an account got the "INITIALIZING" status.
             // When keys are generated, the status will change.
             // The account is already added and initialized. Just update details from daemon
             updateAccountDetails(accountInfo);
             // This will load swarms as the account was not loaded before.
+            accountInfo.contactModel->initContacts();
             accountInfo.conversationModel->initConversations();
             Q_EMIT linked.accountAdded(accountID);
         } else if (!accountInfo.profileInfo.uri.isEmpty()) {
diff --git a/src/libclient/api/contactmodel.h b/src/libclient/api/contactmodel.h
index 1d33f7353..ca74537cc 100644
--- a/src/libclient/api/contactmodel.h
+++ b/src/libclient/api/contactmodel.h
@@ -62,6 +62,8 @@ public:
                  const BehaviorController& behaviorController);
     ~ContactModel();
 
+    void initContacts();
+
     /**
      * Ask the daemon to add a contact.
      * @param contactInfo
diff --git a/src/libclient/contactmodel.cpp b/src/libclient/contactmodel.cpp
index e9641655b..5655b6c10 100644
--- a/src/libclient/contactmodel.cpp
+++ b/src/libclient/contactmodel.cpp
@@ -237,6 +237,11 @@ ContactModel::ContactModel(const account::Info& owner,
 
 ContactModel::~ContactModel() {}
 
+void
+ContactModel::initContacts() {
+    pimpl_->fillWithJamiContacts();
+}
+
 const ContactModel::ContactInfoMap&
 ContactModel::getAllContacts() const
 {
-- 
GitLab