Commit a0cce00d authored by LNJ's avatar LNJ 💬

Clear presence cache on disconnect

parent 5a3e5e8a
......@@ -71,7 +71,9 @@ ClientWorker::ClientWorker(Caches *caches, Kaidan *kaidan, bool enableLogging, Q
client->addExtension(registrationManager);
connect(client, &QXmppClient::presenceReceived,
caches->presCache, &PresenceCache::updatePresenceRequested);
caches->presCache, &PresenceCache::updatePresence);
connect(client, &QXmppClient::disconnected,
caches->presCache, &PresenceCache::clear);
connect(this, &ClientWorker::credentialsUpdated, this, &ClientWorker::setCredentials);
......
......@@ -34,18 +34,13 @@
using namespace Enums;
PresenceCache::PresenceCache(QObject *parent) : QObject(parent)
PresenceCache::PresenceCache(QObject *parent)
: QObject(parent)
{
connect(this, &PresenceCache::updatePresenceRequested, this, &PresenceCache::updatePresence);
}
void PresenceCache::updatePresence(QXmppPresence presence)
{
if (presence.type() != QXmppPresence::Available &&
presence.type() != QXmppPresence::Unavailable/* &&
presence.type() != QXmppPresence::Error*/)
return;
QString jid = QXmppUtils::jidToBareJid(presence.from());
QString resource = QXmppUtils::jidToResource(presence.from());
......@@ -57,6 +52,11 @@ void PresenceCache::updatePresence(QXmppPresence presence)
emit presenceChanged(jid);
}
void PresenceCache::clear()
{
presences.clear();
}
quint8 PresenceCache::getPresenceType(QString bareJid)
{
if (!presences.contains(bareJid))
......
......@@ -56,22 +56,22 @@ public:
*/
Q_INVOKABLE quint8 getPresenceType(QString bareJid);
signals:
public slots:
/**
* Notifies about changed presences
* Updates the presence cache, it will ignore subscribe presences
*/
void presenceChanged(QString jid);
void updatePresence(QXmppPresence presence);
/**
* Is connected to updatePresence
* Clears all cached presences.
*/
void updatePresenceRequested(QXmppPresence presence);
void clear();
private slots:
signals:
/**
* @brief Updates the presence cache, it will ignore subscribe presences
* Notifies about changed presences
*/
void updatePresence(QXmppPresence presence);
void presenceChanged(QString jid);
private:
QMap<QString, QMap<QString, QXmppPresence>> presences;
......
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