Skip to content

Commit

Permalink
tmp FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
lnjX committed Oct 28, 2024
1 parent 963ec63 commit 03ae40b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/client/QXmppMamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <unordered_map>

#include <QDomElement>
#include <QTimer>

using namespace QXmpp;
using namespace QXmpp::Private;
Expand Down Expand Up @@ -324,9 +325,10 @@ QXmppTask<QXmppMamManager::RetrieveResult> QXmppMamManager::retrieveMessages(con
// because some decryptMessage() jobs could finish instantly
state.runningDecryptionJobs = encryptedCount;

int size = state.messages.size();
auto size = state.messages.size();
for (auto i = 0; i < size; i++) {
if (!messagesEncrypted[i]) {
state.processedMessages[i] = parseMamMessage(state.messages.at(i), Unencrypted);
continue;
}

Expand All @@ -347,8 +349,13 @@ QXmppTask<QXmppMamManager::RetrieveResult> QXmppMamManager::retrieveMessages(con
// finish promise if this was the last job
state.runningDecryptionJobs--;
if (state.runningDecryptionJobs == 0) {
state.finish();
d->ongoingRequests.erase(itr);
QTimer::singleShot(0, [this, queryId] {
auto itr = d->ongoingRequests.find(queryId.toStdString());
Q_ASSERT(itr != d->ongoingRequests.end());

itr->second.finish();
d->ongoingRequests.erase(itr);
});
}
});
}
Expand Down
5 changes: 5 additions & 0 deletions tests/qxmppmammanager/tst_qxmppmammanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class EncryptionExtension : public QXmppE2eeExtension
}
QXmppTask<MessageDecryptResult> decryptMessage(QXmppMessage &&m) override
{
m.setBody(m.e2eeFallbackBody());
m.setE2eeFallbackBody({});
return makeReadyTask<MessageDecryptResult>(std::move(m));
}

Expand Down Expand Up @@ -343,6 +345,9 @@ void tst_QXmppMamManager::retrieveMessagesEncrypted()

// check results
auto retrieved = expectFutureVariant<QXmppMamManager::RetrievedMessages>(task);
for (const auto &m : retrieved.messages) {
qDebug() << m.body();
}
QCOMPARE(retrieved.messages.size(), 2);
QCOMPARE(retrieved.messages.at(0).body(), "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.");
QCOMPARE(retrieved.messages.at(1).body(), "What man art thou that thus bescreen'd in night so stumblest on my counsel?");
Expand Down

0 comments on commit 03ae40b

Please sign in to comment.