MCPcopy Create free account
hub / github.com/blizzard4591/openMittsu / callbackTaskFinished

Method callbackTaskFinished

src/network/ProtocolClient.cpp:816–893  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

814 }
815
816 void ProtocolClient::callbackTaskFinished(openmittsu::tasks::CallbackTask* callbackTask) {
817 if (dynamic_cast<openmittsu::tasks::IdentityReceiverCallbackTask*>(callbackTask) != nullptr) {
818 openmittsu::utility::UniquePtrWithDelayedThreadDeletion<openmittsu::tasks::IdentityReceiverCallbackTask> irct(dynamic_cast<openmittsu::tasks::IdentityReceiverCallbackTask*>(callbackTask));
819 if (!missingIdentityProcessors.contains(irct->getContactIdOfFetchedPublicKey())) {
820 LOGGER()->warn("IdentityReceiver CallbackTask finished for ID {}, but no MissingIdentityProcessor is registered for this ID.", irct->getContactIdOfFetchedPublicKey().toString());
821 } else {
822 std::shared_ptr<MissingIdentityProcessor> missingIdentityProcessor = missingIdentityProcessors.value(irct->getContactIdOfFetchedPublicKey());
823 missingIdentityProcessors.remove(irct->getContactIdOfFetchedPublicKey());
824 LOGGER_DEBUG("IdentityReceiverCallbackTask finished for ID {}, removing related MissingIdentityProcessor.", irct->getContactIdOfFetchedPublicKey().toString());
825
826 if (!irct->hasFinishedSuccessfully()) {
827 LOGGER()->warn("Received a message from user {} that we can not decrypt since the Identity could not be retrieved. Error: {}", irct->getContactIdOfFetchedPublicKey().toString(), irct->getErrorMessage().toStdString());
828 missingIdentityProcessor->identityFetcherTaskFinished(irct->getContactIdOfFetchedPublicKey(), false);
829 } else {
830 missingIdentityProcessor->identityFetcherTaskFinished(irct->getContactIdOfFetchedPublicKey(), true);
831 if (m_cryptoBox->getKeyRegistry().hasIdentity(irct->getContactIdOfFetchedPublicKey())) {
832 LOGGER()->warn("Identity {} is already known to KeyRegistry, ignoring result of IdentityReceiverCallbackTask.", irct->getContactIdOfFetchedPublicKey().toString());
833 } else {
834 // TODO FIXME: Add new identity to database!
835 //m_cryptoBox->getKeyRegistry().addIdentity(irct->getContactIdOfFetchedPublicKey(), irct->getFetchedPublicKey());
836
837 LOGGER_DEBUG("PublicKey for Identity {} is {}.", irct->getContactIdOfFetchedPublicKey().toString(), irct->getFetchedPublicKey().toString());
838 m_messageCenterWrapper->addNewContact(irct->getContactIdOfFetchedPublicKey(), irct->getFetchedPublicKey());
839 }
840 }
841
842 if (missingIdentityProcessor->hasFinished()) {
843 if (missingIdentityProcessor->hasAssociatedGroupId()) {
844 groupsWithMissingIdentities.remove(missingIdentityProcessor->getAssociatedGroupId());
845 }
846 if (missingIdentityProcessor->hasFinishedSuccessfully()) {
847 LOGGER()->info("MissingIdentityProcessor finished successfully, now processing {} queued messages.", missingIdentityProcessor->getQueuedMessages().size());
848 std::list<openmittsu::messages::MessageWithEncryptedPayload> queuedMessages(missingIdentityProcessor->getQueuedMessages());
849 auto it = queuedMessages.cbegin();
850 auto const end = queuedMessages.cend();
851 for (; it != end; ++it) {
852 handleIncomingMessage(*it);
853 }
854 } else {
855 LOGGER()->warn("MissingIdentityProcessor failed, will now discard {} messages.", missingIdentityProcessor->getQueuedMessages().size());
856 }
857 }
858 }
859 } else if (dynamic_cast<openmittsu::tasks::MessageCallbackTask*>(callbackTask) != nullptr) {
860 openmittsu::utility::UniquePtrWithDelayedThreadDeletion<openmittsu::tasks::MessageCallbackTask> messageCallbackTask(dynamic_cast<openmittsu::tasks::MessageCallbackTask*>(callbackTask));
861 if (messageCallbackTask->getInitialMessage()->getMessageHeader().getSender() == m_ourContactId) {
862 // Sending
863 if (!messageCallbackTask->hasFinishedSuccessfully()) {
864 LOGGER()->warn("Tried sending a message to user {} that triggered a Callback Task which did not succeed. Error: {}", messageCallbackTask->getInitialMessage()->getMessageHeader().getReceiver().toString(), messageCallbackTask->getErrorMessage().toStdString());
865 messageCallbackTask->getAcknowledgmentProcessor()->sendFailed(this, messageCallbackTask->getInitialMessage()->getMessageHeader().getMessageId());
866 } else {
867 openmittsu::messages::Message* nextMessage = messageCallbackTask->getResultMessage();
868 if (dynamic_cast<openmittsu::messages::contact::ContactMessage*>(nextMessage) != nullptr) {
869 handleOutgoingMessage(dynamic_cast<openmittsu::messages::contact::ContactMessage*>(nextMessage), messageCallbackTask->getAcknowledgmentProcessor());
870 } else if (dynamic_cast<openmittsu::messages::group::UnspecializedGroupMessage*>(nextMessage) != nullptr) {
871 handleOutgoingMessage(dynamic_cast<openmittsu::messages::group::UnspecializedGroupMessage*>(nextMessage), messageCallbackTask->getAcknowledgmentProcessor());
872 } else {
873 LOGGER()->critical("MessageCallbackTask finished for an unknown and unhandled Message type.");

Callers

nothing calls this directly

Calls 15

containsMethod · 0.80
valueMethod · 0.80
removeMethod · 0.80
getSenderMethod · 0.80
getInitialMessageMethod · 0.80
getMessageIdMethod · 0.80
getResultMessageMethod · 0.80
toStringMethod · 0.45
hasIdentityMethod · 0.45
addNewContactMethod · 0.45

Tested by

no test coverage detected