Verified Commit f859197a authored by Phobos D'thorga's avatar Phobos D'thorga 🐲
Browse files

* Added the object, QXmppCarbonManager, so that carbon copies of the right...

* Added the object, QXmppCarbonManager, so that carbon copies of the right messages are sent to all of the right end-points when this is applicable and required.See the XMPP standard, XEP-0280, for further details or the relevant QXmpp article on said object.
* Updated the code which makes use of QXmppMamManager so that archived messages for both sides of the chat are now properly shown. There is still much work to be done in this area, of course.
parent de513ee3
Pipeline #992 passed with stages
in 34 minutes and 53 seconds
......@@ -446,7 +446,7 @@ namespace Network {
struct GkXmppArchiveMsg {
bool presented = false;
QXmppArchiveMessage message;
QXmppArchiveMessage message; // TODO: Implement proper functionality for this or remove it completely!
};
struct GkClientSettings {
......
......@@ -90,6 +90,7 @@ GkXmppClient::GkXmppClient(const GkUserConn &connection_details, QPointer<GekkoF
m_vCardManager(findExtension<QXmppVCardManager>()),
m_xmppArchiveMgr(findExtension<QXmppArchiveManager>()),
m_xmppMamMgr(findExtension<QXmppMamManager>()),
m_xmppCarbonMgr(findExtension<QXmppCarbonManager>()),
m_xmppLogger(QXmppLogger::getLogger()),
m_discoMgr(findExtension<QXmppDiscoveryManager>()),
QXmppClient(parent)
......@@ -108,6 +109,7 @@ GkXmppClient::GkXmppClient(const GkUserConn &connection_details, QPointer<GekkoF
m_transferManager = std::make_unique<QXmppTransferManager>();
m_xmppArchiveMgr = std::make_unique<QXmppArchiveManager>();
m_xmppMamMgr = std::make_unique<QXmppMamManager>();
m_xmppCarbonMgr = std::make_unique<QXmppCarbonManager>();
addExtension(m_rosterManager.get());
addExtension(m_versionMgr.get());
......@@ -137,10 +139,16 @@ GkXmppClient::GkXmppClient(const GkUserConn &connection_details, QPointer<GekkoF
addExtension(m_xmppMamMgr.get());
}
if (m_xmppCarbonMgr) {
addExtension(m_xmppCarbonMgr.get());
m_xmppCarbonMgr->setCarbonsEnabled(true);
}
//
// Booleans and other variables
m_askToReconnectAuto = false;
m_sslIsEnabled = false;
m_isMuc = false;
sys::error_code ec;
fs::path slash = "/";
native_slash = slash.make_preferred().native();
......@@ -293,6 +301,11 @@ GkXmppClient::GkXmppClient(const GkUserConn &connection_details, QPointer<GekkoF
// the most minimal of in-band user registration is supported by said server!
//
QObject::connect(this, SIGNAL(messageReceived(const QXmppMessage &)), this, SLOT(recvXmppMsgUpdate(const QXmppMessage &)));
if (m_xmppCarbonMgr->carbonsEnabled()) {
QObject::connect(m_xmppCarbonMgr.get(), SIGNAL(messageSent(const QXmppMessage &)), this, SLOT(recvXmppMsgUpdate(const QXmppMessage &)));
QObject::connect(m_xmppCarbonMgr.get(), SIGNAL(messageReceived(const QXmppMessage &)), this, SLOT(recvXmppMsgUpdate(const QXmppMessage &)));
}
QObject::connect(m_registerManager.get(), SIGNAL(registrationFormReceived(const QXmppRegisterIq &)),
this, SLOT(handleRegistrationForm(const QXmppRegisterIq &)));
......@@ -874,34 +887,39 @@ void GkXmppClient::getArchivedMessages(const QString &to, const QString &node, c
Q_UNUSED(node);
Q_UNUSED(end);
if (!m_rosterList.isEmpty()) {
for (const auto &roster: m_rosterList) {
updateRecordedMsgHistory(roster.bareJid);
if (!start.isValid()) {
if (to == roster.bareJid && jid != m_connDetails.jid) {
if (!roster.messages.isEmpty()) {
QList<QXmppMessage> msg_history;
for (const auto &message: roster.messages) {
msg_history.push_back(message.message);
}
try {
if (!m_rosterList.isEmpty()) {
for (const auto &roster: m_rosterList) {
updateRecordedMsgHistory(roster.bareJid);
if (!start.isValid()) {
if (to == roster.bareJid && jid != m_connDetails.jid) {
if (!roster.messages.isEmpty()) {
QList<QXmppMessage> msg_history;
for (const auto &message: roster.messages) {
msg_history.push_back(message.message);
}
if (!msg_history.isEmpty()) {
const auto min_timestamp = gkStringFuncs->calcMinTimestampForXmppMsgHistory(msg_history);
gkEventLogger->publishEvent(tr("Minimum date required for message archive retrieval is: %1").arg(QDateTime(min_timestamp).toString("dd MMM yyyy @ hh:mm:ss.zzz")),
GkSeverity::Debug, "", false, true, false, false);
m_xmppMamMgr->retrieveArchivedMessages(roster.bareJid, "", m_connDetails.jid, min_timestamp, QDateTime(), resultSetQuery);
if (!msg_history.isEmpty()) {
const auto min_timestamp = gkStringFuncs->calcMinTimestampForXmppMsgHistory(msg_history);
gkEventLogger->publishEvent(tr("Minimum date required for message archive retrieval is: %1").arg(QDateTime(min_timestamp).toString("dd MMM yyyy @ hh:mm:ss.zzz")),
GkSeverity::Debug, "", false, true, false, false);
m_xmppMamMgr->retrieveArchivedMessages(roster.bareJid, "", m_connDetails.jid, min_timestamp, QDateTime(), resultSetQuery);
return;
return;
}
}
}
break;
break;
}
}
}
}
m_xmppMamMgr->retrieveArchivedMessages(to, "", jid, QDateTime::currentDateTime().addDays(-28), QDateTime::currentDateTime(), resultSetQuery);
} catch (const std::exception &e) {
gkEventLogger->publishEvent(QString::fromStdString(e.what()), GkSeverity::Fatal, "", false, true, false, true, false);
}
m_xmppMamMgr->retrieveArchivedMessages(to, "", jid, QDateTime::currentDateTime().addDays(-28), QDateTime::currentDateTime(), resultSetQuery);
return;
}
......@@ -1049,7 +1067,7 @@ void GkXmppClient::vCardReceived(const QXmppVCardIq &vCard)
}
}
} catch (const std::exception &e) {
gkEventLogger->publishEvent(QString::fromStdString(e.what()), GkSeverity::Fatal, "", false, true, false, true);
gkEventLogger->publishEvent(QString::fromStdString(e.what()), GkSeverity::Fatal, "", false, true, false, true, false);
}
return;
......@@ -1099,7 +1117,7 @@ void GkXmppClient::clientVCardReceived()
}
}
} catch (const std::exception &e) {
gkEventLogger->publishEvent(QString::fromStdString(e.what()), GkSeverity::Fatal, "", false, true, false, true);
gkEventLogger->publishEvent(QString::fromStdString(e.what()), GkSeverity::Fatal, "", false, true, false, true, false);
}
return;
......@@ -1388,15 +1406,9 @@ void GkXmppClient::updateClientVCardForm(const QString &first_name, const QStrin
* @brief GkXmppClient::sendXmppMsg is a utility function to send messages to all the resources associated with the specified
* bareJid(s) within the contained QXmppMessage stanza.
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param bareJid The identity of the user in question, for the message archive with which we are processing for.
* @param msg The QXmppMessage to process and ultimately, transmit.
* @param beginTimestamp The beginning timestamp, from which to filter the search results beginning at in obtaining the
* message history for a given bareJid. This is a Internet bandwidth/data saving measure.
* @param endTimestamp The end timestamp, from which to filter the search results up towards in obtaining the message
* history for a given bareJid. This is a Internet bandwidth/data saving measure.
*/
void GkXmppClient::sendXmppMsg(const QString &bareJid, const QXmppMessage &msg, const QDateTime &beginTimestamp,
const QDateTime &endTimestamp)
void GkXmppClient::sendXmppMsg(const QXmppMessage &msg)
{
if (msg.isXmppStanza()) {
sendPacket(msg);
......@@ -1981,7 +1993,7 @@ void GkXmppClient::recvXmppMsgUpdate(const QXmppMessage &message)
return;
}
} catch (const std::exception &e) {
gkEventLogger->publishEvent(QString::fromStdString(e.what()), GkSeverity::Fatal, "", false, true, false, true);
gkEventLogger->publishEvent(QString::fromStdString(e.what()), GkSeverity::Fatal, "", false, true, false, true, false);
}
return;
......
......@@ -65,6 +65,7 @@
#include <qxmpp/QXmppRegisterIq.h>
#include <qxmpp/QXmppMucManager.h>
#include <qxmpp/QXmppVCardManager.h>
#include <qxmpp/QXmppCarbonManager.h>
#include <qxmpp/QXmppRosterManager.h>
#include <qxmpp/QXmppArchiveManager.h>
#include <qxmpp/QXmppVersionManager.h>
......@@ -139,12 +140,6 @@ public:
bool deleteUserAccount();
QString obtainAvatarFilePath();
//
// QXmppMamManager handling
void getArchivedMessages(const QString &to = QString(), const QString &node = QString(), const QString &jid = QString(),
const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime(),
const QXmppResultSetQuery &resultSetQuery = QXmppResultSetQuery());
//
// vCard management
QByteArray processImgToByteArray(const QString &filePath);
......@@ -176,10 +171,15 @@ public slots:
void updateClientVCardForm(const QString &first_name, const QString &last_name, const QString &email,
const QString &callsign, const QByteArray &avatar_pic, const QString &img_type);
//
// QXmppMamManager handling
void getArchivedMessages(const QString &to = QString(), const QString &node = QString(), const QString &jid = QString(),
const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime(),
const QXmppResultSetQuery &resultSetQuery = QXmppResultSetQuery());
//
// Message handling
void sendXmppMsg(const QString &bareJid, const QXmppMessage &msg, const QDateTime &beginTimestamp,
const QDateTime &endTimestamp);
void sendXmppMsg(const QXmppMessage &msg);
private slots:
//
......@@ -328,6 +328,7 @@ private:
QXmppConfiguration config;
bool m_askToReconnectAuto;
bool m_sslIsEnabled;
bool m_isMuc;
std::shared_ptr<QXmppRegistrationManager> m_registerManager;
std::unique_ptr<QXmppMucManager> m_mucManager;
std::unique_ptr<QXmppMucRoom> m_pRoom;
......@@ -335,6 +336,7 @@ private:
std::unique_ptr<QXmppMamManager> m_xmppMamMgr;
std::unique_ptr<QXmppTransferManager> m_transferManager;
std::unique_ptr<QXmppVCardManager> m_vCardManager;
std::unique_ptr<QXmppCarbonManager> m_xmppCarbonMgr;
QScopedPointer<QXmppLogger> m_xmppLogger;
GekkoFyre::Network::GkXmpp::GkNetworkState m_netState;
......
......@@ -114,8 +114,7 @@ GkXmppMessageDialog::GkXmppMessageDialog(QPointer<GekkoFyre::StringFuncs> string
//
// Setup and initialize signals and slots...
QObject::connect(this, SIGNAL(updateToolbar(const QString &)), this, SLOT(updateToolbarStatus(const QString &)));
QObject::connect(this, SIGNAL(sendXmppMsg(const QString &, const QXmppMessage &, const QDateTime &, const QDateTime &)),
m_xmppClient, SLOT(sendXmppMsg(const QString &, const QXmppMessage &, const QDateTime &, const QDateTime &)));
QObject::connect(this, SIGNAL(sendXmppMsg(const QXmppMessage &)), m_xmppClient, SLOT(sendXmppMsg(const QXmppMessage &)));
QObject::connect(m_xmppClient, SIGNAL(xmppMsgUpdate(const QXmppMessage &)), this, SLOT(recvXmppMsg(const QXmppMessage &)));
QObject::connect(m_xmppClient, SIGNAL(updateMsgHistory()), this, SLOT(updateMsgHistory()));
QObject::connect(m_xmppClient, SIGNAL(msgArchiveSuccReceived()), this, SLOT(msgArchiveSuccReceived()));
......@@ -162,7 +161,10 @@ GkXmppMessageDialog::GkXmppMessageDialog(QPointer<GekkoFyre::StringFuncs> string
QObject::connect(m_xmppClient, &QXmppClient::connected, this, [=]() {
ui->textEdit_tx_msg_dialog->setEnabled(true);
getArchivedMessages(); // Now gather any data possible from the given XMPP server via the Internet!
//
// Now gather any data possible from the given XMPP server via the Internet!
getArchivedMessages();
});
QObject::connect(m_xmppClient, &QXmppClient::disconnected, this, [=]() {
......@@ -345,7 +347,7 @@ void GkXmppMessageDialog::submitMsgEnterKey()
if (!bareJid.isEmpty()) {
const auto toMsg = createXmppMessageIq(bareJid, gkConnDetails.jid, plaintext);
if (toMsg.isXmppStanza()) {
emit sendXmppMsg(bareJid, toMsg, toMsg.stamp(), QDateTime::currentDateTimeUtc());
emit sendXmppMsg(toMsg);
}
}
}
......@@ -466,6 +468,8 @@ QXmppMessage GkXmppMessageDialog::createXmppMessageIq(const QString &to, const Q
xmppMsg.setTo(to);
xmppMsg.setBody(message);
xmppMsg.setStamp(QDateTime::currentDateTimeUtc());
xmppMsg.setPrivate(false);
xmppMsg.setReceiptRequested(true);
xmppMsg.setType(QXmppMessage::Chat);
return xmppMsg;
......@@ -482,6 +486,7 @@ void GkXmppMessageDialog::msgArchiveSuccReceived()
emit updateMamArchive(bareJid);
}
emit updateMamArchive(gkConnDetails.jid);
startupSucc = true;
}
......@@ -513,7 +518,7 @@ void GkXmppMessageDialog::procMamArchive(const QString &bareJid)
void GkXmppMessageDialog::getArchivedMessages()
{
for (const auto &bareJid: m_bareJids) {
m_xmppClient->getArchivedMessages(gkConnDetails.jid, QString(), bareJid);
m_xmppClient->getArchivedMessages(gkConnDetails.jid, QString(), bareJid); // Get archived messages sent by the Jid in question!
}
return;
......@@ -538,9 +543,11 @@ void GkXmppMessageDialog::getArchivedMessagesFromDb(const QString &bareJid, cons
auto rosterMap = m_xmppClient->getRosterMap();
if (!rosterMap.isEmpty()) {
std::lock_guard<std::mutex> lock_guard(m_archivedMsgsFromDbMtx);
gkXmppRecvMsgsTableViewModel->removeData();
// gkXmppRecvMsgsTableViewModel->removeData();
for (auto roster = rosterMap.begin(); roster != rosterMap.end(); ++roster) {
if (roster->bareJid == bareJid) {
gkEventLogger->publishEvent(tr("Gathering archived messages for XMPP user, \"%1\", from the database!").arg(roster->bareJid), GkSeverity::Debug,
"", false, true, false, false, false);
if (!roster->messages.isEmpty()) {
for (auto iter = roster->messages.begin(); iter != roster->messages.end(); ++iter) {
if (!iter->presented && insertData) {
......
......@@ -119,8 +119,7 @@ signals:
//
// Message handling and QXmppArchiveManager-related
void sendXmppMsg(const QString &bareJid, const QXmppMessage &msg, const QDateTime &beginTimestamp,
const QDateTime &endTimestamp);
void sendXmppMsg(const QXmppMessage &msg);
//
// QXmppMamManager handling
......
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