From 91365f81542b46e5bd0e51f0ae322ef79826589f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 2 Aug 2021 09:58:37 -0400
Subject: [PATCH] account_manager: fix forEachDevices

We need to wait that all devices are found before stopping
forEachDevices. This fix ut_call.

Change-Id: Ic695869957fbd1a6f28e11fa6ffb59d6447841e7
GitLab: https://git.jami.net/savoirfairelinux/ring-project/-/issues/1282
---
 src/jamidht/account_manager.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/jamidht/account_manager.cpp b/src/jamidht/account_manager.cpp
index 1805258599..d20f0f9f29 100644
--- a/src/jamidht/account_manager.cpp
+++ b/src/jamidht/account_manager.cpp
@@ -724,7 +724,7 @@ AccountManager::forEachDevice(
 
     struct State
     {
-        unsigned remaining {0};
+        unsigned remaining {1}; // Note: state is initialized to 1, because we need to wait that the get is finished
         std::set<dht::PkId> treatedDevices {};
         std::function<void(const std::shared_ptr<dht::crypto::PublicKey>&)> onDevice;
         std::function<void(bool)> onEnd;
@@ -767,7 +767,9 @@ AccountManager::forEachDevice(
             });
             return true;
         },
-        [state](bool /*ok*/) { state->ended(); });
+        [state](bool /*ok*/) {
+            state->found({});
+        });
 }
 
 void
-- 
GitLab