Skip to content
Snippets Groups Projects
Commit d2f1f81c authored by Sébastien Blin's avatar Sébastien Blin
Browse files

ringaccount: remove presence only if all values for all devices has expired

Change-Id: I4dda17d658aaa5324827625cef4971499119ec84
parent e2ac73b3
No related branches found
No related tags found
No related merge requests found
...@@ -125,8 +125,8 @@ struct RingAccount::BuddyInfo ...@@ -125,8 +125,8 @@ struct RingAccount::BuddyInfo
/* the buddy id */ /* the buddy id */
dht::InfoHash id; dht::InfoHash id;
/* the presence timestamps */ /* number of devices connected on the DHT */
std::set<dht::InfoHash> devices; uint32_t devices_cnt {};
/* The disposable object to update buddy info */ /* The disposable object to update buddy info */
std::future<size_t> listenToken; std::future<size_t> listenToken;
...@@ -1988,20 +1988,19 @@ RingAccount::trackPresence(const dht::InfoHash& h, BuddyInfo& buddy) ...@@ -1988,20 +1988,19 @@ RingAccount::trackPresence(const dht::InfoHash& h, BuddyInfo& buddy)
if (not dht_.isRunning()) { if (not dht_.isRunning()) {
return; return;
} }
buddy.listenToken = dht_.listen<DeviceAnnouncement>(h, [this, h](DeviceAnnouncement&& dev, bool expired){ buddy.listenToken = dht_.listen<DeviceAnnouncement>(h, [this, h](DeviceAnnouncement&&, bool expired){
bool wasConnected, isConnected; bool wasConnected, isConnected;
{ {
std::lock_guard<std::mutex> lock(buddyInfoMtx); std::lock_guard<std::mutex> lock(buddyInfoMtx);
auto buddy = trackedBuddies_.find(h); auto buddy = trackedBuddies_.find(h);
if (buddy == trackedBuddies_.end()) if (buddy == trackedBuddies_.end())
return true; return true;
wasConnected = not buddy->second.devices.empty(); wasConnected = buddy->second.devices_cnt > 0;
if (expired) { if (expired)
buddy->second.devices.erase(dev.dev); --buddy->second.devices_cnt;
} else { else
buddy->second.devices.emplace(dev.dev); ++buddy->second.devices_cnt;
} isConnected = buddy->second.devices_cnt > 0;
isConnected = not buddy->second.devices.empty();
} }
if (isConnected and not wasConnected) { if (isConnected and not wasConnected) {
onTrackedBuddyOnline(h); onTrackedBuddyOnline(h);
...@@ -2019,7 +2018,7 @@ RingAccount::getTrackedBuddyPresence() ...@@ -2019,7 +2018,7 @@ RingAccount::getTrackedBuddyPresence()
std::lock_guard<std::mutex> lock(buddyInfoMtx); std::lock_guard<std::mutex> lock(buddyInfoMtx);
std::map<std::string, bool> presence_info; std::map<std::string, bool> presence_info;
for (const auto& buddy_info_p : trackedBuddies_) for (const auto& buddy_info_p : trackedBuddies_)
presence_info.emplace(buddy_info_p.first.toString(), not buddy_info_p.second.devices.empty()); presence_info.emplace(buddy_info_p.first.toString(), buddy_info_p.second.devices_cnt > 0);
return presence_info; return presence_info;
} }
...@@ -2290,7 +2289,7 @@ RingAccount::doRegister_() ...@@ -2290,7 +2289,7 @@ RingAccount::doRegister_()
dhtPeerConnector_->onDhtConnected(ringDeviceId_); dhtPeerConnector_->onDhtConnected(ringDeviceId_);
for (auto& buddy : trackedBuddies_) { for (auto& buddy : trackedBuddies_) {
buddy.second.devices.clear(); buddy.second.devices_cnt = 0;
trackPresence(buddy.first, buddy.second); trackPresence(buddy.first, buddy.second);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment