aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-10-21 17:01:03 +0200
committerLNJ <lnj@kaidan.im>2019-10-23 12:13:18 +0200
commitdfec49b06fc305cc55631e5473b9ba19c729cd03 (patch)
tree268083483bec5f41ce9b4dab1f0a9ece3f5258ed /src
parent91157d28b88ef3bab80100cd816c643809944a27 (diff)
downloadqxmpp-dfec49b06fc305cc55631e5473b9ba19c729cd03.tar.gz
Port away from deprecated client extension getters of the QXmppClient
This replaces the deprecated getters in the examples and in the documentation.
Diffstat (limited to 'src')
-rw-r--r--src/client/QXmppClient.cpp29
-rw-r--r--src/client/QXmppClient.h22
-rw-r--r--src/client/QXmppRosterManager.h31
-rw-r--r--src/client/QXmppVCardManager.h4
-rw-r--r--src/client/QXmppVersionManager.h4
5 files changed, 53 insertions, 37 deletions
diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp
index deef3dbc..b71fd8e9 100644
--- a/src/client/QXmppClient.cpp
+++ b/src/client/QXmppClient.cpp
@@ -361,22 +361,31 @@ QXmppRosterManager& QXmppClient::rosterManager()
/// is offline or not present in the roster, it will still send a message to
/// the bareJid.
///
+/// \note Usage of this method is discouraged because most modern clients use
+/// carbon messages (XEP-0280: Message Carbons) and MAM (XEP-0313: Message
+/// Archive Management) and so could possibly receive messages multiple times
+/// or not receive them at all.
+/// \c QXmppClient::sendPacket() should be used instead with a \c QXmppMessage.
+///
/// \param bareJid bareJid of the receiving entity
/// \param message Message string to be sent.
void QXmppClient::sendMessage(const QString& bareJid, const QString& message)
{
- QStringList resources = rosterManager().getResources(bareJid);
- if(!resources.isEmpty())
- {
- for(int i = 0; i < resources.size(); ++i)
- {
- sendPacket(QXmppMessage("", bareJid + "/" + resources.at(i), message));
+ QXmppRosterManager *rosterManager = findExtension<QXmppRosterManager>();
+
+ const QStringList resources = rosterManager
+ ? rosterManager->getResources(bareJid)
+ : QStringList();
+
+ if (!resources.isEmpty()) {
+ for (const auto &resource : resources) {
+ sendPacket(
+ QXmppMessage({}, bareJid + QStringLiteral("/") + resource, message)
+ );
}
- }
- else
- {
- sendPacket(QXmppMessage("", bareJid, message));
+ } else {
+ sendPacket(QXmppMessage({}, bareJid, message));
}
}
diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h
index 5f765602..d3726334 100644
--- a/src/client/QXmppClient.h
+++ b/src/client/QXmppClient.h
@@ -64,9 +64,9 @@ class QXmppVersionManager;
/// QXmppConfiguration::setAutoReconnectionEnabled().
///
/// Not all the managers or extensions have been enabled by default. One can
-/// enable/disable the managers using the functions addExtension() and
-/// removeExtension(). findExtension() can be used to find reference/pointer to
-/// particular instansiated and enabled manager.
+/// enable/disable the managers using the functions \c addExtension() and
+/// \c removeExtension(). \c findExtension() can be used to find reference/
+/// pointer to particular instansiated and enabled manager.
///
/// List of managers enabled by default:
/// - QXmppRosterManager
@@ -168,8 +168,8 @@ public:
signals:
- /// This signal is emitted when the client connects successfully to the XMPP
- /// server i.e. when a successful XMPP connection is established.
+ /// This signal is emitted when the client connects successfully to the
+ /// XMPP server i.e. when a successful XMPP connection is established.
/// XMPP Connection involves following sequential steps:
/// - TCP socket connection
/// - Client sends start stream
@@ -182,15 +182,15 @@ signals:
/// After all these steps a successful XMPP connection is established and
/// connected() signal is emitted.
///
- /// After the connected() signal is emitted QXmpp will send the roster request
- /// to the server. On receiving the roster, QXmpp will emit
- /// QXmppRosterManager::rosterReceived(). After this signal, QXmppRosterManager object gets
- /// populated and you can use rosterManager() to get the handle of QXmppRosterManager object.
- ///
+ /// After the connected() signal is emitted QXmpp will send the roster
+ /// request to the server. On receiving the roster, QXmpp will emit
+ /// QXmppRosterManager::rosterReceived(). After this signal,
+ /// QXmppRosterManager object gets populated and you can use
+ /// \c findExtension<QXmppRosterManager>() to get the handle of
+ /// QXmppRosterManager object.
void connected();
/// This signal is emitted when the XMPP connection disconnects.
- ///
void disconnected();
/// This signal is emitted when the XMPP connection encounters any error.
diff --git a/src/client/QXmppRosterManager.h b/src/client/QXmppRosterManager.h
index 869b6b42..6b050197 100644
--- a/src/client/QXmppRosterManager.h
+++ b/src/client/QXmppRosterManager.h
@@ -35,29 +35,32 @@
class QXmppRosterManagerPrivate;
-/// \brief The QXmppRosterManager class provides access to a connected client's roster.
+/// \brief The QXmppRosterManager class provides access to a connected client's
+/// roster.
///
/// \note It's object should not be created using it's constructor. Instead
-/// QXmppClient::rosterManager() should be used to get the reference of instantiated
-/// object this class.
+/// \c QXmppClient::findExtension<QXmppRosterManager>() should be used to get
+/// the instantiated object of this class.
///
-/// It stores all the Roster and Presence details of all the roster entries (that
-/// is all the bareJids) in the client's friend's list. It provides the
+/// It stores all the Roster and Presence details of all the roster entries
+/// (that is all the bareJids) in the client's friend's list. It provides the
/// functionality to get all the bareJids in the client's roster and Roster and
/// Presence details of the same.
///
-/// After the successful xmpp connection that after the signal QXmppClient::connected()
-/// is emitted QXmpp requests for getting the roster. Once QXmpp receives the roster
-/// the signal QXmppRosterManager::rosterReceived() is emitted and after that user can
-/// use the functions of this class to get roster entries.
+/// After the QXmpp connected successfully to the XMPP server the signal
+/// \c QXmppClient::connected() is emitted and the roster is requested from the
+/// server. Once QXmpp receives the roster the signal
+/// \c QXmppRosterManager::rosterReceived() is emitted and after that the
+/// methods of this class can be used to get the roster entries.
///
-/// Function QXmppRosterManager::isRosterReceived() tells whether the roster has been
-/// received or not.
+/// \c QXmppRosterManager::isRosterReceived() can be used to find out whether
+/// the roster has been received yet.
///
-/// The itemAdded(), itemChanged() and itemRemoved() signals are emitted whenever roster
-/// entries are added, changed or removed.
+/// The \c itemAdded(), \c itemChanged() and \c itemRemoved() signals are
+/// emitted whenever roster entries are added, changed or removed.
///
-/// The presenceChanged() signal is emitted whenever the presence for a roster item changes.
+/// The \c presenceChanged() signal is emitted whenever the presence for a
+/// roster item changes.
///
/// \ingroup Managers
diff --git a/src/client/QXmppVCardManager.h b/src/client/QXmppVCardManager.h
index 328fe4a0..55a150f7 100644
--- a/src/client/QXmppVCardManager.h
+++ b/src/client/QXmppVCardManager.h
@@ -34,8 +34,8 @@ class QXmppVCardManagerPrivate;
/// implementation of XEP-0054: vcard-temp.
///
/// \note It's object should not be created using it's constructor. Instead
-/// QXmppClient::vCardManager() should be used to get the reference of instantiated
-/// object this class.
+/// \c QXmppClient::findExtension<QXmppVCardManager>() should be used to get
+/// the instantiated object of this class.
///
/// <B>Getting vCards of entries in Roster:</B><BR>
/// It doesn't store vCards of the JIDs in the roster of connected user. Instead
diff --git a/src/client/QXmppVersionManager.h b/src/client/QXmppVersionManager.h
index eb992611..9a6fc7a8 100644
--- a/src/client/QXmppVersionManager.h
+++ b/src/client/QXmppVersionManager.h
@@ -32,6 +32,10 @@ class QXmppVersionManagerPrivate;
/// \brief The QXmppVersionManager class makes it possible to request for
/// the software version of an entity as defined by XEP-0092: Software Version.
///
+/// \note It's object should not be created using it's constructor. Instead
+/// \c QXmppClient::findExtension<QXmppVersionManager>() should be used to get
+/// the instantiated object of this class.
+///
/// \ingroup Managers
class QXMPP_EXPORT QXmppVersionManager : public QXmppClientExtension