Basic presence with subnodes
This commit is contained in:
parent
de21036456
commit
e8eaced6e9
20 changed files with 576 additions and 77 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "account.h"
|
||||
#include <qxmpp/QXmppRosterManager.h>
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
|
@ -15,7 +16,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
{
|
||||
QObject::connect(&client, SIGNAL(connected()), this, SLOT(onClientConnected()));
|
||||
QObject::connect(&client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()));
|
||||
|
||||
QObject::connect(&client, SIGNAL(presenceReceived(const QXmppPresence&)), this, SLOT(onPresenceReceived(const QXmppPresence&)));
|
||||
|
||||
QXmppRosterManager& rm = client.rosterManager();
|
||||
|
||||
|
@ -23,6 +24,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
QObject::connect(&rm, SIGNAL(itemAdded(const QString&)), this, SLOT(onRosterItemAdded(const QString&)));
|
||||
QObject::connect(&rm, SIGNAL(itemRemoved(const QString&)), this, SLOT(onRosterItemRemoved(const QString&)));
|
||||
QObject::connect(&rm, SIGNAL(itemChanged(const QString&)), this, SLOT(onRosterItemChanged(const QString&)));
|
||||
//QObject::connect(&rm, SIGNAL(presenceChanged(const QString&, const QString&)), this, SLOT(onRosterPresenceChanged(const QString&, const QString&)));
|
||||
}
|
||||
|
||||
Account::~Account()
|
||||
|
@ -116,6 +118,9 @@ void Core::Account::onRosterItemChanged(const QString& bareJid)
|
|||
QSet<QString> newGroups = re.groups();
|
||||
QSet<QString> oldGroups;
|
||||
|
||||
|
||||
QStringList res = rm.getResources(bareJid);
|
||||
|
||||
emit changeContact(bareJid, re.name());
|
||||
|
||||
for (std::map<QString, std::set<QString>>::iterator itr = groups.begin(), end = groups.end(); itr != end; ++itr) {
|
||||
|
@ -204,3 +209,50 @@ void Core::Account::addedAccount(const QString& jid)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::Account::onPresenceReceived(const QXmppPresence& presence)
|
||||
{
|
||||
QString id = presence.from();
|
||||
QStringList comps = id.split("/");
|
||||
QString jid = comps.front();
|
||||
QString resource = comps.back();
|
||||
|
||||
switch (presence.type()) {
|
||||
case QXmppPresence::Error:
|
||||
qDebug() << "An error reported by presence from " << id;
|
||||
break;
|
||||
case QXmppPresence::Available:{
|
||||
QDateTime lastInteraction = presence.lastUserInteraction();
|
||||
if (!lastInteraction.isValid()) {
|
||||
lastInteraction = QDateTime::currentDateTime();
|
||||
}
|
||||
emit addPresence(jid, resource, {
|
||||
{"lastActivity", lastInteraction},
|
||||
{"availability", presence.availableStatusType()}, //TODO check and handle invisible
|
||||
{"status", presence.statusText()}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case QXmppPresence::Unavailable:
|
||||
emit removePresence(jid, resource);
|
||||
break;
|
||||
case QXmppPresence::Subscribe:
|
||||
qDebug("xmpp presence \"subscribe\" received, do not yet know what to do, skipping");
|
||||
case QXmppPresence::Subscribed:
|
||||
qDebug("xmpp presence \"subscribed\" received, do not yet know what to do, skipping");
|
||||
case QXmppPresence::Unsubscribe:
|
||||
qDebug("xmpp presence \"unsubscribe\" received, do not yet know what to do, skipping");
|
||||
case QXmppPresence::Unsubscribed:
|
||||
qDebug("xmpp presence \"unsubscribed\" received, do not yet know what to do, skipping");
|
||||
case QXmppPresence::Probe:
|
||||
qDebug("xmpp presence \"probe\" received, do not yet know what to do, skipping");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::onRosterPresenceChanged(const QString& bareJid, const QString& resource)
|
||||
{
|
||||
//not used for now;
|
||||
qDebug() << "presence changed for " << bareJid << " resource " << resource;
|
||||
const QXmppPresence& presence = client.rosterManager().getPresence(bareJid, resource);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ signals:
|
|||
void removeContact(const QString& jid);
|
||||
void removeContact(const QString& jid, const QString& group);
|
||||
void changeContact(const QString& jid, const QString& name);
|
||||
void addPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removePresence(const QString& jid, const QString& name);
|
||||
|
||||
private:
|
||||
QString name;
|
||||
|
@ -49,9 +51,11 @@ private slots:
|
|||
void onClientConnected();
|
||||
void onClientDisconnected();
|
||||
void onRosterReceived();
|
||||
void onRosterItemAdded(const QString &bareJid);
|
||||
void onRosterItemChanged(const QString &bareJid);
|
||||
void onRosterItemRemoved(const QString &bareJid);
|
||||
void onRosterItemAdded(const QString& bareJid);
|
||||
void onRosterItemChanged(const QString& bareJid);
|
||||
void onRosterItemRemoved(const QString& bareJid);
|
||||
void onRosterPresenceChanged(const QString& bareJid, const QString& resource);
|
||||
void onPresenceReceived(const QXmppPresence& presence);
|
||||
|
||||
private:
|
||||
void addedAccount(const QString &bareJid);
|
||||
|
|
|
@ -80,6 +80,9 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
|
|||
connect(acc, SIGNAL(removeContact(const QString&)), this, SLOT(onAccountRemoveContact(const QString&)));
|
||||
connect(acc, SIGNAL(removeContact(const QString&, const QString&)), this, SLOT(onAccountRemoveContact(const QString&, const QString&)));
|
||||
connect(acc, SIGNAL(changeContact(const QString&, const QString&)), this, SLOT(onAccountChangeContact(const QString&, const QString&)));
|
||||
connect(acc, SIGNAL(addPresence(const QString&, const QString&, const QMap<QString, QVariant>&)),
|
||||
this, SLOT(onAccountAddPresence(const QString&, const QString&, const QMap<QString, QVariant>&)));
|
||||
connect(acc, SIGNAL(removePresence(const QString&, const QString&)), this, SLOT(onAccountRemovePresence(const QString&, const QString&)));
|
||||
|
||||
QMap<QString, QVariant> map = {
|
||||
{"login", login},
|
||||
|
@ -153,3 +156,15 @@ void Core::Squawk::onAccountRemoveContact(const QString& jid, const QString& gro
|
|||
Account* acc = static_cast<Account*>(sender());
|
||||
emit removeContact(acc->getName(), jid, group);
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountAddPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
emit addPresence(acc->getName(), jid, name, data);
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountRemovePresence(const QString& jid, const QString& name)
|
||||
{
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
emit removePresence(acc->getName(), jid, name);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ signals:
|
|||
void removeContact(const QString& account, const QString& jid);
|
||||
void removeContact(const QString& account, const QString& jid, const QString& group);
|
||||
void changeContact(const QString& account, const QString& jid, const QString& name);
|
||||
void addPresence(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removePresence(const QString& account, const QString& jid, const QString& name);
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
|
@ -57,6 +59,8 @@ private slots:
|
|||
void onAccountRemoveContact(const QString& jid);
|
||||
void onAccountRemoveContact(const QString& jid, const QString& group);
|
||||
void onAccountChangeContact(const QString& jid, const QString& name);
|
||||
void onAccountAddPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void onAccountRemovePresence(const QString& jid, const QString& name);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue