conversation: emit ConversationSyncFinished when all fetches done

Change-Id: If2c5e86a160998ddc25e095bba1de3add89f37e0
This commit is contained in:
Kateryna Kostiuk
2022-08-08 14:03:16 -04:00
parent 521107ed5a
commit d4ee3d52b9
2 changed files with 16 additions and 7 deletions

View File

@ -953,12 +953,8 @@ Conversation::Impl::pull()
decltype(fetchingRemotes_.begin()) it;
{
std::lock_guard<std::mutex> lk(pullcbsMtx_);
if (pullcbs_.empty()) {
if (auto account = account_.lock())
emitSignal<DRing::ConversationSignal::ConversationSyncFinished>(
account->getAccountID().c_str());
if (pullcbs_.empty())
return;
}
auto& elem = pullcbs_.front();
deviceId = std::move(std::get<0>(elem));
commitId = std::move(std::get<1>(elem));

View File

@ -269,6 +269,7 @@ public:
std::mutex replayMtx_;
std::map<std::string, std::vector<std::map<std::string, std::string>>> replay_;
std::map<std::string, uint64_t> refreshMessage;
std::atomic_int syncCnt {0};
};
ConversationModule::Impl::Impl(std::weak_ptr<JamiAccount>&& account,
@ -418,6 +419,7 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer,
return false;
}
acc->addGitSocket(channel->deviceId(), conversationId, channel);
syncCnt.fetch_add(1);
conversation->second->sync(
peer,
deviceId,
@ -438,8 +440,15 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer,
deviceId.c_str(),
conversationId.c_str());
}
std::lock_guard<std::mutex> lk(pendingConversationsFetchMtx_);
pendingConversationsFetch_.erase(conversationId);
{
std::lock_guard<std::mutex> lk(pendingConversationsFetchMtx_);
pendingConversationsFetch_.erase(conversationId);
}
if (syncCnt.fetch_sub(1) == 1) {
if (auto account = account_.lock())
emitSignal<DRing::ConversationSignal::ConversationSyncFinished>(
account->getAccountID().c_str());
}
},
commitId);
return true;
@ -1367,6 +1376,10 @@ ConversationModule::syncConversations(const std::string& peer, const std::string
pimpl_->fetchNewCommits(peer, deviceId, cid);
for (const auto& cid : toClone)
pimpl_->cloneConversation(deviceId, peer, cid);
if (pimpl_->syncCnt.load() == 0) {
if (auto acc = pimpl_->account_.lock())
emitSignal<DRing::ConversationSignal::ConversationSyncFinished>(acc->getAccountID().c_str());
}
}
void