aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-10-28 20:53:28 +0100
committerLinus Jahn <lnj@kaidan.im>2021-01-09 14:37:47 +0100
commita24dc912bfcf52daa0086aeee1073f0f74b2bad9 (patch)
tree6126346171056d763df00cebc41b098f9080d21c /src/client
parentf0e53ac3c1ab288502cefba91870a6ba8fe65993 (diff)
downloadqxmpp-a24dc912bfcf52daa0086aeee1073f0f74b2bad9.tar.gz
RosterManager: Cache roster when using stream management
The roster manager caches the roster items if a previous stream could be resumed now. The rosterReceived() signal is not emitted again in this case. This avoids redundant roster requests. When no stream management is used, the roster cache is cleared directly on disconnecting. If stream management is used, the cache is also accessible after disconnecting. On connecting the manager checks whether the last stream could be resumed. If the last stream hasn't been resumed, the cache is cleared and the roster is re-requested.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/QXmppRosterManager.cpp42
-rw-r--r--src/client/QXmppRosterManager.h4
2 files changed, 37 insertions, 9 deletions
diff --git a/src/client/QXmppRosterManager.cpp b/src/client/QXmppRosterManager.cpp
index 09f277c1..7cb70ff8 100644
--- a/src/client/QXmppRosterManager.cpp
+++ b/src/client/QXmppRosterManager.cpp
@@ -36,6 +36,8 @@ class QXmppRosterManagerPrivate
public:
QXmppRosterManagerPrivate();
+ void clear();
+
// map of bareJid and its rosterEntry
QMap<QString, QXmppRosterIq::Item> entries;
@@ -54,6 +56,14 @@ QXmppRosterManagerPrivate::QXmppRosterManagerPrivate()
{
}
+void QXmppRosterManagerPrivate::clear()
+{
+ entries.clear();
+ presences.clear();
+ rosterReqId.clear();
+ isRosterReceived = false;
+}
+
///
/// Constructs a roster manager.
///
@@ -102,19 +112,27 @@ bool QXmppRosterManager::acceptSubscription(const QString &bareJid, const QStrin
///
void QXmppRosterManager::_q_connected()
{
- QXmppRosterIq roster;
- roster.setType(QXmppIq::Get);
- roster.setFrom(client()->configuration().jid());
- d->rosterReqId = roster.id();
- if (client()->isAuthenticated())
- client()->sendPacket(roster);
+ // clear cache if stream has not been resumed
+ if (client()->streamManagementState() != QXmppClient::ResumedStream) {
+ d->clear();
+ }
+
+ if (!d->isRosterReceived) {
+ QXmppRosterIq roster;
+ roster.setType(QXmppIq::Get);
+ roster.setFrom(client()->configuration().jid());
+ d->rosterReqId = roster.id();
+ if (client()->isAuthenticated())
+ client()->sendPacket(roster);
+ }
}
void QXmppRosterManager::_q_disconnected()
{
- d->entries.clear();
- d->presences.clear();
- d->isRosterReceived = false;
+ // clear cache if stream cannot be resumed
+ if (client()->streamManagementState() == QXmppClient::NoStreamManagement) {
+ d->clear();
+ }
}
/// \cond
@@ -133,6 +151,9 @@ bool QXmppRosterManager::handleStanza(const QDomElement &element)
rosterIq.parse(element);
bool isInitial = (d->rosterReqId == rosterIq.id());
+ if (isInitial)
+ d->rosterReqId.clear();
+
switch (rosterIq.type()) {
case QXmppIq::Set: {
// send result iq
@@ -407,6 +428,9 @@ QXmppPresence QXmppRosterManager::getPresence(const QString &bareJid,
///
/// Function to check whether the roster has been received or not.
///
+/// On disconnecting this is reset to false if no stream management is used by
+/// the client and so the stream cannot be resumed later.
+///
/// \return true if roster received else false
///
bool QXmppRosterManager::isRosterReceived() const
diff --git a/src/client/QXmppRosterManager.h b/src/client/QXmppRosterManager.h
index c91d05f2..90022edb 100644
--- a/src/client/QXmppRosterManager.h
+++ b/src/client/QXmppRosterManager.h
@@ -101,6 +101,10 @@ Q_SIGNALS:
/// connection. That is the roster entries are empty before this signal is emitted.
/// One should use getRosterBareJids() and getRosterEntry() only after
/// this signal has been emitted.
+ ///
+ /// \note If the previous stream could be resumed, this signal is not
+ /// emitted since QXmpp 1.4. Changes since the last connection are reported
+ /// via the itemAdded(), itemChanged() and itemRemoved() signals.
void rosterReceived();
/// This signal is emitted when the presence of a particular bareJid and resource changes.