diff --git a/src/jami/jami.h b/src/jami/jami.h index 13dcf98ee70764630a17fc64e840e1e6b898a63e..6c88ae1d428842bb8e6de11aabbcab1b57952f76 100644 --- a/src/jami/jami.h +++ b/src/jami/jami.h @@ -42,7 +42,8 @@ enum InitFlag { LIBJAMI_FLAG_IOS_EXTENSION = 1 << 4, LIBJAMI_FLAG_NO_LOCAL_AUDIO = 1 << 6, LIBJAMI_FLAG_NO_LOCAL_VIDEO = 1 << 7, - LIBJAMI_FLAG_NO_LOCAL_MEDIA = LIBJAMI_FLAG_NO_LOCAL_AUDIO | LIBJAMI_FLAG_NO_LOCAL_VIDEO + LIBJAMI_FLAG_NO_LOCAL_MEDIA = LIBJAMI_FLAG_NO_LOCAL_AUDIO | LIBJAMI_FLAG_NO_LOCAL_VIDEO, + LIBJAMI_FLAG_NO_AUTOSYNC = 1 << 8 }; /** diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index f3033a17a6c5ec2043322119f454988e8fe4f6de..ae9570523aa66bc8b478c2494d3e069a59b662b2 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -1087,16 +1087,18 @@ JamiAccount::loadAccount(const std::string& archive_password, [this](const std::string& uri, bool confirmed) { if (!id_.first) return; - dht::ThreadPool::io().run([w=weak(), uri, confirmed] { - if (auto shared = w.lock()) { - if (auto cm = shared->convModule()) { - auto activeConv = cm->getOneToOneConversation(uri); - if (!activeConv.empty()) - cm->bootstrap(activeConv); + if (jami::Manager::instance().syncOnRegister) { + dht::ThreadPool::io().run([w=weak(), uri, confirmed] { + if (auto shared = w.lock()) { + if (auto cm = shared->convModule()) { + auto activeConv = cm->getOneToOneConversation(uri); + if (!activeConv.empty()) + cm->bootstrap(activeConv); + } + emitSignal<libjami::ConfigurationSignal::ContactAdded>(shared->getAccountID(), uri, confirmed); } - emitSignal<libjami::ConfigurationSignal::ContactAdded>(shared->getAccountID(), uri, confirmed); - } - }); + }); + } }, [this](const std::string& uri, bool banned) { if (!id_.first) @@ -1930,47 +1932,49 @@ JamiAccount::doRegister_() setRegistrationState(state); }; - context.identityAnnouncedCb = [this](bool ok) { - if (!ok) - return; - accountManager_->startSync( - [this](const std::shared_ptr<dht::crypto::Certificate>& crt) { - if (!crt) - return; - auto deviceId = crt->getLongId().toString(); - if (accountManager_->getInfo()->deviceId == deviceId) - return; - - std::unique_lock<std::mutex> lk(connManagerMtx_); - initConnectionManager(); - channelHandlers_[Uri::Scheme::SYNC] - ->connect(crt->getLongId(), - "", - [this](std::shared_ptr<ChannelSocket> socket, - const DeviceId& deviceId) { - if (socket) - syncModule()->syncWith(deviceId, socket); - }); - lk.unlock(); - requestSIPConnection( - getUsername(), - crt->getLongId(), - "sync"); // For git notifications, will use the same socket as sync - }, - [this] { - deviceAnnounced_ = true; - - // Bootstrap at the end to avoid to be long to load. - dht::ThreadPool::io().run([w = weak()] { - if (auto shared = w.lock()) { - std::lock_guard<std::recursive_mutex> lock(shared->configurationMutex_); - shared->convModule()->bootstrap(); - } - }); - emitSignal<libjami::ConfigurationSignal::VolatileDetailsChanged>( - accountID_, getVolatileAccountDetails()); - }); - }; + if (jami::Manager::instance().syncOnRegister) { + context.identityAnnouncedCb = [this](bool ok) { + if (!ok) + return; + accountManager_->startSync( + [this](const std::shared_ptr<dht::crypto::Certificate>& crt) { + if (!crt) + return; + auto deviceId = crt->getLongId().toString(); + if (accountManager_->getInfo()->deviceId == deviceId) + return; + + std::unique_lock<std::mutex> lk(connManagerMtx_); + initConnectionManager(); + channelHandlers_[Uri::Scheme::SYNC] + ->connect(crt->getLongId(), + "", + [this](std::shared_ptr<ChannelSocket> socket, + const DeviceId& deviceId) { + if (socket) + syncModule()->syncWith(deviceId, socket); + }); + lk.unlock(); + requestSIPConnection( + getUsername(), + crt->getLongId(), + "sync"); // For git notifications, will use the same socket as sync + }, + [this] { + deviceAnnounced_ = true; + + // Bootstrap at the end to avoid to be long to load. + dht::ThreadPool::io().run([w = weak()] { + if (auto shared = w.lock()) { + std::lock_guard<std::recursive_mutex> lock(shared->configurationMutex_); + shared->convModule()->bootstrap(); + } + }); + emitSignal<libjami::ConfigurationSignal::VolatileDetailsChanged>( + accountID_, getVolatileAccountDetails()); + }); + }; + } setRegistrationState(RegistrationState::TRYING); dht_->run(dhtPortUsed(), config, std::move(context)); diff --git a/src/manager.cpp b/src/manager.cpp index c9e0af2727e50926b5b0944f816f90446ac29b69..c784db74ccb46f70b6e8642adc81f948e4b4d0a9 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -141,6 +141,8 @@ std::atomic_bool Manager::initialized = {false}; bool Manager::isIOSExtension = {false}; #endif +bool Manager::syncOnRegister = {true}; + static void copy_over(const std::string& srcPath, const std::string& destPath) { diff --git a/src/manager.h b/src/manager.h index dc05be7505cbb47a54d27a0e1c958bf7b39b842b..d3de5ebbf6870a85f0e77c277698eced6bcb8452 100644 --- a/src/manager.h +++ b/src/manager.h @@ -119,6 +119,8 @@ public: static bool isIOSExtension; #endif + static bool syncOnRegister; + /** * Initialisation of thread (sound) and map. * Init a new VoIPLink, audio codec and audio driver diff --git a/src/ring_api.cpp b/src/ring_api.cpp index 8afa994705e8c00f8f399c063133651eba9d8be8..b51423c2357dd3147aa4277672b72a78ad191bdb 100644 --- a/src/ring_api.cpp +++ b/src/ring_api.cpp @@ -69,6 +69,8 @@ init(enum InitFlag flags) noexcept if (flags & LIBJAMI_FLAG_IOS_EXTENSION) manager.isIOSExtension = true; #endif + if (flags & LIBJAMI_FLAG_NO_AUTOSYNC) + manager.syncOnRegister = false; return true; } catch (...) {