| 1369 | } |
| 1370 | |
| 1371 | void Client::callbackTaskFinished(openmittsu::tasks::CallbackTask* callbackTask) { |
| 1372 | if (callbackTask == nullptr) { |
| 1373 | LOGGER()->error("A null callback task finished."); |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | if (dynamic_cast<openmittsu::tasks::CheckFeatureLevelCallbackTask*>(callbackTask) != nullptr) { |
| 1378 | openmittsu::utility::UniquePtrWithDelayedThreadDeletion<openmittsu::tasks::CheckFeatureLevelCallbackTask> checkFeatureLevelTask(dynamic_cast<openmittsu::tasks::CheckFeatureLevelCallbackTask*>(callbackTask)); |
| 1379 | if (checkFeatureLevelTask->hasFinishedSuccessfully()) { |
| 1380 | openmittsu::protocol::ContactId const selfIdentity = (!m_databaseWrapper.hasDatabase()) ? openmittsu::protocol::ContactId(0) : m_databaseWrapper.getSelfContact(); |
| 1381 | |
| 1382 | if (m_databaseWrapper.hasDatabase()) { |
| 1383 | m_databaseWrapper.setContactFeatureLevelBatch(checkFeatureLevelTask->getFetchedFeatureLevels()); |
| 1384 | } |
| 1385 | QHash<openmittsu::protocol::ContactId, openmittsu::protocol::FeatureLevel> result = checkFeatureLevelTask->getFetchedFeatureLevels(); |
| 1386 | QHashIterator<openmittsu::protocol::ContactId, openmittsu::protocol::FeatureLevel> i(result); |
| 1387 | while (i.hasNext()) { |
| 1388 | i.next(); |
| 1389 | LOGGER_DEBUG("Contact {} has feature level {}.", i.key().toString(), openmittsu::protocol::FeatureLevelHelper::toInt(i.value())); |
| 1390 | } |
| 1391 | |
| 1392 | if (result.contains(selfIdentity)) { |
| 1393 | openmittsu::protocol::FeatureLevel const selfFeatureLevel = result.value(selfIdentity); |
| 1394 | openmittsu::protocol::FeatureLevel const openMittsuFeatureLevel = openmittsu::protocol::FeatureLevelHelper::latestSupported(); |
| 1395 | |
| 1396 | if (openmittsu::protocol::FeatureLevelHelper::lessThan(selfFeatureLevel, openMittsuFeatureLevel)) { |
| 1397 | if ((!m_databaseWrapper.hasDatabase()) || (m_serverConfiguration == nullptr)) { |
| 1398 | LOGGER()->error("Wanted to update feature level, but either database or server config is null!"); |
| 1399 | return; |
| 1400 | } |
| 1401 | |
| 1402 | std::shared_ptr<openmittsu::backup::IdentityBackup> const backupData = m_databaseWrapper.getBackup(); |
| 1403 | openmittsu::crypto::BasicCryptoBox basicCryptoBox(backupData->getClientLongTermKeyPair(), m_serverConfiguration->getServerLongTermPublicKey()); |
| 1404 | openmittsu::tasks::SetFeatureLevelCallbackTask* setFeatureLevelTask = new openmittsu::tasks::SetFeatureLevelCallbackTask(m_serverConfiguration, basicCryptoBox, backupData->getClientContactId(), openMittsuFeatureLevel); |
| 1405 | OPENMITTSU_CONNECT(setFeatureLevelTask, finished(openmittsu::tasks::CallbackTask*), this, callbackTaskFinished(openmittsu::tasks::CallbackTask*)); |
| 1406 | setFeatureLevelTask->start(); |
| 1407 | } |
| 1408 | } |
| 1409 | } else { |
| 1410 | LOGGER()->error("Checking for supported feature levels of contacts failed: {}", checkFeatureLevelTask->getErrorMessage().toStdString()); |
| 1411 | } |
| 1412 | } else if (dynamic_cast<openmittsu::tasks::CheckContactActivityStatusCallbackTask*>(callbackTask) != nullptr) { |
| 1413 | openmittsu::utility::UniquePtrWithDelayedThreadDeletion<openmittsu::tasks::CheckContactActivityStatusCallbackTask> checkContactIdStatusTask(dynamic_cast<openmittsu::tasks::CheckContactActivityStatusCallbackTask*>(callbackTask)); |
| 1414 | if (checkContactIdStatusTask->hasFinishedSuccessfully()) { |
| 1415 | if (!m_databaseWrapper.hasDatabase()) { |
| 1416 | LOGGER()->error("Wanted to update feature levels, but the database is null!"); |
| 1417 | return; |
| 1418 | } |
| 1419 | |
| 1420 | m_databaseWrapper.setContactAccountStatusBatch(checkContactIdStatusTask->getFetchedStatus()); |
| 1421 | } else { |
| 1422 | LOGGER()->error("Checking for status of contacts failed: {}", checkContactIdStatusTask->getErrorMessage().toStdString()); |
| 1423 | } |
| 1424 | } else if (dynamic_cast<openmittsu::tasks::SetFeatureLevelCallbackTask*>(callbackTask) != nullptr) { |
| 1425 | openmittsu::utility::UniquePtrWithDelayedThreadDeletion<openmittsu::tasks::SetFeatureLevelCallbackTask> setFeatureLevelTask(dynamic_cast<openmittsu::tasks::SetFeatureLevelCallbackTask*>(callbackTask)); |
| 1426 | if (setFeatureLevelTask->hasFinishedSuccessfully()) { |
| 1427 | LOGGER()->info("Updated feature level for used Client ID to latest support version {}.", openmittsu::protocol::FeatureLevelHelper::toInt(openmittsu::protocol::FeatureLevelHelper::latestSupported())); |
| 1428 | } else { |
nothing calls this directly
no test coverage detected