diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index 51a01ab84..ff582d408 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -1023,8 +1023,7 @@ QXmppTask QXmppOmemoManager::decryptMe SendError::EncryptionError }); } - auto omemoElement = message.omemoElement(); - if (!omemoElement) { + if (!message.omemoElement()) { return makeReadyTask(NotEncrypted()); } @@ -1163,9 +1162,11 @@ bool Manager::handleMessage(const QXmppMessage &message) { if (d->isStarted && message.omemoElement()) { auto future = d->decryptMessage(message); - future.then(this, [=](std::optional optionalDecryptedMessage) mutable { + future.then(this, [this, message](std::optional optionalDecryptedMessage) { if (optionalDecryptedMessage) { injectMessage(std::move(*optionalDecryptedMessage)); + } else { + Q_EMIT client()->messageReceived(message); } }); diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index d71a86c5e..d01e5ebcd 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -1074,17 +1074,6 @@ QXmppTask> ManagerPrivate::encryptStanza(const const auto &deviceId = itr.key(); const auto &device = itr.value(); - // Skip encrypting for a device if it does not respond for a while. - if (const auto unrespondedSentStanzasCount = device.unrespondedSentStanzasCount; unrespondedSentStanzasCount == UNRESPONDED_STANZAS_UNTIL_ENCRYPTION_IS_STOPPED) { - if (++(*skippedDevicesCount) == devicesCount) { - warning("OMEMO element could not be created because no recipient device responded to " % - QString::number(unrespondedSentStanzasCount) % " sent stanzas"); - interface.finish(std::nullopt); - } - - continue; - } - auto controlDeviceProcessing = [=](bool isSuccessful = true) mutable { if (isSuccessful) { ++(*successfullyProcessedDevicesCount); @@ -1103,6 +1092,19 @@ QXmppTask> ManagerPrivate::encryptStanza(const } }; + // Skip encrypting for a device if it does not respond for a while. + if (const auto unrespondedSentStanzasCount = device.unrespondedSentStanzasCount; unrespondedSentStanzasCount == UNRESPONDED_STANZAS_UNTIL_ENCRYPTION_IS_STOPPED) { + if (++(*skippedDevicesCount) == devicesCount) { + warning("OMEMO element could not be created because no recipient device responded to " % + QString::number(unrespondedSentStanzasCount) % " sent stanzas"); + interface.finish(std::nullopt); + } else { + controlDeviceProcessing(false); + } + + continue; + } + const auto address = Address(jid, deviceId); auto addOmemoEnvelope = [=](bool isKeyExchange = false) mutable { @@ -1117,7 +1119,11 @@ QXmppTask> ManagerPrivate::encryptStanza(const } else if (devices.value(jid).contains(deviceId)) { auto &deviceBeingModified = devices[jid][deviceId]; deviceBeingModified.unrespondedReceivedStanzasCount = 0; - ++deviceBeingModified.unrespondedSentStanzasCount; + + if (auto &unrespondedSentStanzasCount = deviceBeingModified.unrespondedSentStanzasCount; unrespondedSentStanzasCount + 1 <= UNRESPONDED_STANZAS_UNTIL_ENCRYPTION_IS_STOPPED) { + ++unrespondedSentStanzasCount; + } + omemoStorage->addDevice(jid, deviceId, deviceBeingModified); QXmppOmemoEnvelope omemoEnvelope; @@ -1633,13 +1639,12 @@ QXmppTask> ManagerPrivate::extractPayloadDecrypt warning("OMEMO envelope data could not be deserialized"); interface.finish(std::nullopt); } else { - BufferPtr publicIdentityKeyBuffer; + BufferPtr publicIdentityKeyBuffer(ec_public_key_get_ed(pre_key_signal_message_get_identity_key(omemoEnvelopeData.get()))); - if (ec_public_key_serialize(publicIdentityKeyBuffer.ptrRef(), pre_key_signal_message_get_identity_key(omemoEnvelopeData.get())) < 0) { + if (const auto key = publicIdentityKeyBuffer.toByteArray(); key.isEmpty()) { warning("Public Identity key could not be retrieved"); interface.finish(std::nullopt); } else { - const auto key = publicIdentityKeyBuffer.toByteArray(); auto &device = devices[senderJid][senderDeviceId]; auto &storedKeyId = device.keyId;