diff --git a/src/client/QXmppCarbonManagerV2.cpp b/src/client/QXmppCarbonManagerV2.cpp index aedf93b66..8e1304a96 100644 --- a/src/client/QXmppCarbonManagerV2.cpp +++ b/src/client/QXmppCarbonManagerV2.cpp @@ -6,8 +6,8 @@ #include "QXmppClient.h" #include "QXmppConstants_p.h" -#include "QXmppFutureUtils_p.h" #include "QXmppMessage.h" +#include "QXmppOutgoingClient.h" #include "QXmppUtils_p.h" #include @@ -19,7 +19,6 @@ class CarbonEnableIq : public QXmppIq { public: CarbonEnableIq() - : QXmppIq() { setType(QXmppIq::Set); } @@ -62,11 +61,11 @@ auto parseIq(std::variant &&sendResult) -> std::optiona /// \brief The QXmppCarbonManagerV2 class handles message carbons as described in \xep{0280, /// Message Carbons}. /// -/// The manager automatically enables carbons when a connection is established. If the connection -/// could be resumed, no new request is done. Carbon copied messages from other devices of the same -/// account and carbon copied messages from other accounts are injected into the QXmppClient. This -/// way you can handle them like any other incoming message by implementing QXmppMessageHandler or -/// using QXmppClient::messageReceived(). +/// The manager automatically enables carbons when a connection is established. Either by using +/// \xep{0386, Bind 2} if available or by sending a normal IQ request on connection. +/// Carbon copied messages from other devices of the same account and carbon copied messages from +/// other accounts are injected into the QXmppClient. This way you can handle them like any other +/// incoming message by implementing QXmppMessageHandler or using QXmppClient::messageReceived(). /// /// Checks are done to ensure that the entity sending the carbon copy is allowed to send the /// forwarded message. @@ -79,6 +78,8 @@ auto parseIq(std::variant &&sendResult) -> std::optiona /// /// To distinguish carbon messages, you can use QXmppMessage::isCarbonMessage(). /// +/// \note Enabling via Bind 2 has been added in QXmpp 1.8. +/// /// \ingroup Managers /// /// \since QXmpp 1.5 @@ -121,18 +122,21 @@ bool QXmppCarbonManagerV2::handleStanza(const QDomElement &element, const std::o void QXmppCarbonManagerV2::onRegistered(QXmppClient *client) { + client->stream()->carbonManager().setEnableViaBind2(true); connect(client, &QXmppClient::connected, this, &QXmppCarbonManagerV2::enableCarbons); } void QXmppCarbonManagerV2::onUnregistered(QXmppClient *client) { + client->stream()->carbonManager().setEnableViaBind2(false); disconnect(client, &QXmppClient::connected, this, &QXmppCarbonManagerV2::enableCarbons); } void QXmppCarbonManagerV2::enableCarbons() { - if (client()->streamManagementState() == QXmppClient::ResumedStream) { - // skip re-enabling for resumed streams + // skip if stream could be resumed or carbons have been enabled via bind2 already + if (client()->streamManagementState() == QXmppClient::ResumedStream || + client()->stream()->carbonManager().enabled()) { return; } diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h index 476bbe58f..70e648be0 100644 --- a/src/client/QXmppClient.h +++ b/src/client/QXmppClient.h @@ -352,6 +352,7 @@ private Q_SLOTS: friend class QXmppClientExtension; friend class QXmppInternalClientExtension; + friend class QXmppCarbonManagerV2; friend class TestClient; };