Commit 52e84410 authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin
Browse files

jamiaccount: remove account on main thread



Change-Id: I86be545fb21b637accade1867ab9ff26b652dd8b
Reviewed-by: Sébastien Blin's avatarSébastien Blin <sebastien.blin@savoirfairelinux.com>
parent d1415674
...@@ -1199,18 +1199,18 @@ void ...@@ -1199,18 +1199,18 @@ void
JamiAccount::loadAccountFromFile(const std::string& archive_path, const std::string& archive_password) JamiAccount::loadAccountFromFile(const std::string& archive_path, const std::string& archive_password)
{ {
setRegistrationState(RegistrationState::INITIALIZING); setRegistrationState(RegistrationState::INITIALIZING);
auto accountId = getAccountID(); dht::ThreadPool::computation().run([w=weak(), archive_password, archive_path, accountId = getAccountID()]{
dht::ThreadPool::computation().run([w=weak(), archive_password, archive_path, accountId]{
AccountArchive archive; AccountArchive archive;
try { try {
archive = AccountArchive(archive_path, archive_password); archive = AccountArchive(archive_path, archive_password);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
JAMI_WARN("[Account %s] can't read file: %s", accountId.c_str(), ex.what()); JAMI_WARN("[Account %s] can't read file: %s", accountId.c_str(), ex.what());
runOnMainThread([w, accountId]() { if (auto this_ = w.lock()) {
if (auto this_ = w.lock()) this_->setRegistrationState(RegistrationState::ERROR_GENERIC);
this_->setRegistrationState(RegistrationState::ERROR_GENERIC); runOnMainThread([accountId]() {
Manager::instance().removeAccount(accountId); Manager::instance().removeAccount(accountId);
}); });
}
return; return;
} }
runOnMainThread([w, archive, archive_password]() mutable { runOnMainThread([w, archive, archive_password]() mutable {
...@@ -1276,7 +1276,7 @@ JamiAccount::loadAccountFromDHT(const std::string& archive_password, const std:: ...@@ -1276,7 +1276,7 @@ JamiAccount::loadAccountFromDHT(const std::string& archive_password, const std::
return true; return true;
} }
JAMI_DBG("Found archive on the DHT"); JAMI_DBG("Found archive on the DHT");
runOnMainThread([=]() { dht::ThreadPool::computation().run([=]() {
if (auto this_ = w.lock()) { if (auto this_ = w.lock()) {
try { try {
*found = true; *found = true;
...@@ -1284,7 +1284,9 @@ JamiAccount::loadAccountFromDHT(const std::string& archive_password, const std:: ...@@ -1284,7 +1284,9 @@ JamiAccount::loadAccountFromDHT(const std::string& archive_password, const std::
} catch (const std::exception& e) { } catch (const std::exception& e) {
JAMI_WARN("[Account %s] error reading archive: %s", this_->getAccountID().c_str(), e.what()); JAMI_WARN("[Account %s] error reading archive: %s", this_->getAccountID().c_str(), e.what());
this_->setRegistrationState(RegistrationState::ERROR_GENERIC); this_->setRegistrationState(RegistrationState::ERROR_GENERIC);
Manager::instance().removeAccount(this_->getAccountID()); runOnMainThread([=]() {
Manager::instance().removeAccount(this_->getAccountID());
});
} }
} }
}); });
......
Supports Markdown
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