workaround for ejabberd history fetching

This commit is contained in:
Blue 2019-07-01 09:31:38 +03:00
parent eba33bea8a
commit 9834fc33e8
4 changed files with 24 additions and 20 deletions

View File

@ -263,7 +263,7 @@ void Core::Account::handleNewContact(Core::Contact* contact)
QObject::connect(contact, SIGNAL(nameChanged(const QString&)), this, SLOT(onContactNameChanged(const QString&)));
QObject::connect(contact, SIGNAL(subscriptionStateChanged(Shared::SubscriptionState)),
this, SLOT(onContactSubscriptionStateChanged(Shared::SubscriptionState)));
QObject::connect(contact, SIGNAL(needHistory(const QString&, const QString&)), this, SLOT(onContactNeedHistory(const QString&, const QString&)));
QObject::connect(contact, SIGNAL(needHistory(const QString&, const QString&, const QDateTime&)), this, SLOT(onContactNeedHistory(const QString&, const QString&, const QDateTime&)));
QObject::connect(contact, SIGNAL(historyResponse(const std::list<Shared::Message>&)), this, SLOT(onContactHistoryResponse(const std::list<Shared::Message>&)));
}
@ -519,8 +519,6 @@ void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMess
QString jid = itr->second;
std::map<QString, Contact*>::const_iterator citr = contacts.find(jid);
logMessage(msg, "MAM MESSAGE:");
if (citr != contacts.end()) {
Contact* cnt = citr->second;
if (msg.id().size() > 0 && msg.body().size() > 0) {
@ -564,7 +562,7 @@ void Core::Account::requestArchive(const QString& jid, int count, const QString&
}
}
void Core::Account::onContactNeedHistory(const QString& before, const QString& after)
void Core::Account::onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at)
{
Contact* contact = static_cast<Contact*>(sender());
QXmppResultSetQuery query;
@ -572,13 +570,18 @@ void Core::Account::onContactNeedHistory(const QString& before, const QString& a
if (before.size() > 0) {
query.setBefore(before);
}
if (after.size() > 0) {
QDateTime start;
if (after.size() > 0) { //there is some strange behavior of ejabberd server returning empty result set
if (at.isValid()) { //there can be some useful information about it here https://github.com/processone/ejabberd/issues/2924
start = at;
} else {
query.setAfter(after);
}
}
qDebug() << "Remote query from" << after << ", to" << before;
QString q = am->retrieveArchivedMessages("", "", contact->jid, QDateTime(), QDateTime(), query);
QString q = am->retrieveArchivedMessages("", "", contact->jid, start, QDateTime(), query);
achiveQueries.insert(std::make_pair(q, contact->jid));
}
@ -588,15 +591,6 @@ void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResu
std::map<QString, QString>::const_iterator itr = achiveQueries.find(queryId);
QString jid = itr->second;
qDebug() << "MAM RESULTS:";
qDebug() << "complete:" << complete;
qDebug() << "count:" << resultSetReply.count();
qDebug() << "first:" << resultSetReply.first();
qDebug() << "last:" << resultSetReply.last();
qDebug() << "index:" << resultSetReply.index();
qDebug() << "isNull:" << resultSetReply.isNull();
achiveQueries.erase(itr);
std::map<QString, Contact*>::const_iterator citr = contacts.find(jid);
if (citr != contacts.end()) {

View File

@ -106,7 +106,7 @@ private slots:
void onContactNameChanged(const QString& name);
void onContactSubscriptionStateChanged(Shared::SubscriptionState state);
void onContactHistoryResponse(const std::list<Shared::Message>& list);
void onContactNeedHistory(const QString& before, const QString& after);
void onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at);
void onMamLog(QXmppLogger::MessageType type, const QString &msg);

View File

@ -156,12 +156,14 @@ void Core::Contact::performRequest(int count, const QString& before)
emit needHistory(before, "");
break;
case chunk:
case beginning:
case beginning: {
if (count != -1) {
requestCache.emplace_back(requestedCount, before);
requestedCount = -1;
}
emit needHistory("", archive->newestId());
Shared::Message msg = archive->newest();
emit needHistory("", msg.getId(), msg.getTime());
}
break;
case end:
if (count != -1) {
@ -180,6 +182,10 @@ void Core::Contact::performRequest(int count, const QString& before)
requestCache.emplace_back(requestedCount, before);
requestedCount = -1;
emit needHistory(archive->oldestId(), "");
} catch (Archive::Empty e) {
requestCache.emplace_back(requestedCount, before);
requestedCount = -1;
emit needHistory(archive->oldestId(), "");
}
if (found) {
@ -204,6 +210,8 @@ void Core::Contact::performRequest(int count, const QString& before)
responseCache.insert(responseCache.begin(), arc.begin(), arc.end());
} catch (Archive::NotFound e) {
qDebug("requesting id hasn't been found in archive, skipping");
} catch (Archive::Empty e) {
qDebug("requesting id hasn't been found in archive, skipping");
}
nextRequest();
break;
@ -301,6 +309,8 @@ void Core::Contact::flushMessagesToArchive(bool finished, const QString& firstId
found = true;
} catch (Archive::NotFound e) {
} catch (Archive::Empty e) {
}
if (!found || requestedCount > responseCache.size()) {
if (archiveState == complete) {

View File

@ -62,7 +62,7 @@ signals:
void nameChanged(const QString& name);
void subscriptionStateChanged(Shared::SubscriptionState state);
void historyResponse(const std::list<Shared::Message>& messages);
void needHistory(const QString& before, const QString& after);
void needHistory(const QString& before, const QString& after, const QDateTime& afterTime = QDateTime());
public:
const QString jid;