Commit f72fe3e7 authored by LNJ's avatar LNJ 💬

djfjdslfj

parent ed2b20d9
......@@ -88,7 +88,7 @@ MessageHandler::MessageHandler(Kaidan *kaidan, QXmppClient *client, MessageModel
this, &MessageHandler::handleArchiveMessage);
connect(mamManager, &QXmppMamManager::resultsRecieved,
this, &MessageHandler::handleArchiveResults);
connect(client, &QXmppClient::connected,
connect(&client->rosterManager(), &QXmppRosterManager::rosterReceived,
this, &MessageHandler::requestLatestMessages);
#endif
}
......@@ -154,7 +154,9 @@ void MessageHandler::handleMessage(const QXmppMessage &msg)
entry.timestamp = stamp.toUTC().toString(Qt::ISODate);
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
settings->setValue("cache/latest-message", entry.timestamp);
// if the received message is newer than the currently latest message, update
if (settings->value("cache/latest-message").toDateTime() < stamp)
settings->setValue("cache/latest-message", entry.timestamp);
#endif
// save the message to the database
......@@ -277,25 +279,51 @@ void MessageHandler::handleDiscoInfo(const QXmppDiscoveryIq &info)
void MessageHandler::handleArchiveMessage(const QString&,
const QXmppMessage &message)
{
emit client->messageReceived(message);
// emit client->messageReceived(message);
handleMessage(message);
}
void MessageHandler::handleArchiveResults(const QString &queryId,
const QXmppResultSetReply &resultSetReply,
bool complete)
{
QDateTime latestMessage = settings->value("cache/latest-message", QDateTime(
{1980, 01, 01}, {00, 00}, Qt::UTC)).toDateTime();
QDateTime latestMessage = settings->value("cache/latest-message").toDateTime();
if (!jidsToQuery.isEmpty()) {
QTimer::singleShot(500, this, [this]() {
QXmppResultSetQuery queryLimit;
queryLimit.setBefore(""); // query last (newest) first
queryLimit.setMax(10);
QString jid = jidsToQuery.takeFirst();
mamManager->retrieveArchivedMessages(QString(), QString(), jid,
QDateTime(),
QDateTime::currentDateTimeUtc(),
queryLimit);
});
}
if (resultSetReply.count() > 0)
mamManager->retrieveArchivedMessages("", "", "", latestMessage, QDateTime({2100, 01, 01}, {00, 00}));
// if (resultSetReply.count() > 0)
// mamManager->retrieveArchivedMessages("", "", "", latestMessage, QDateTime({2100, 01, 01}, {00, 00}));
}
void MessageHandler::requestLatestMessages()
{
QDateTime latestMessage = settings->value("cache/latest-message", QDateTime(
{1980, 01, 01}, {00, 00}, Qt::UTC)).toDateTime();
QDateTime latestMessage = settings->value("cache/latest-message").toDateTime();
if (latestMessage == QDateTime()) {
qDebug() << "[MessageHandler] Loading latest 20 messages for each "
"contact.";
QXmppResultSetQuery queryLimit;
queryLimit.setMax(10);
queryLimit.setBefore(""); // query last (newest) first
jidsToQuery = client->rosterManager().getRosterBareJids();
QString jid = jidsToQuery.takeFirst();
mamManager->retrieveArchivedMessages(QString(), QString(), jid,
QDateTime(),
QDateTime::currentDateTimeUtc(),
queryLimit);
mamManager->retrieveArchivedMessages("", "", "", latestMessage, QDateTime({2100, 01, 01}, {00, 00}));
} else {
//mamManager->retrieveArchivedMessages("", "", "", latestMessage, QDateTime({2100, 01, 01}, {00, 00}));
}
}
#endif
......@@ -116,6 +116,7 @@ private:
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
QXmppCarbonManager *carbonManager;
QXmppMamManager *mamManager;
QStringList jidsToQuery;
#endif
QString chatPartner;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment