| 1331 | } |
| 1332 | |
| 1333 | void Session::watchForOffline(not_null<UserData*> user, TimeId now) { |
| 1334 | if (!now) { |
| 1335 | now = base::unixtime::now(); |
| 1336 | } |
| 1337 | if (!Data::IsUserOnline(user, now)) { |
| 1338 | return; |
| 1339 | } |
| 1340 | const auto lastseen = user->lastseen(); |
| 1341 | const auto till = lastseen.onlineTill(); |
| 1342 | const auto &[i, ok] = _watchingForOffline.emplace(user, till); |
| 1343 | if (!ok) { |
| 1344 | if (i->second == till) { |
| 1345 | return; |
| 1346 | } |
| 1347 | i->second = till; |
| 1348 | } |
| 1349 | const auto timeout = Data::OnlineChangeTimeout(lastseen, now); |
| 1350 | const auto fires = _watchForOfflineTimer.isActive() |
| 1351 | ? _watchForOfflineTimer.remainingTime() |
| 1352 | : -1; |
| 1353 | if (fires >= 0 && fires <= timeout) { |
| 1354 | return; |
| 1355 | } |
| 1356 | _watchForOfflineTimer.callOnce(std::max(timeout, crl::time(1))); |
| 1357 | } |
| 1358 | |
| 1359 | void Session::maybeStopWatchForOffline(not_null<UserData*> user) { |
| 1360 | if (Data::IsUserOnline(user)) { |
no test coverage detected