squawk/qomemo/qxmpp_omemo_manager.cpp

75 lines
2.1 KiB
C++
Raw Normal View History

/*
* Created by victoria on 2021-05-12.
*/
#include "qxmpp_omemo_manager.h"
2021-05-12 21:32:13 +00:00
#include "device.h"
#include "variant/conversations.h"
#include <QDomElement>
#include <QXmppClient.h>
#include <QXmppPubSubIq.h>
#include <iostream>
2021-05-12 21:32:13 +00:00
using namespace QXmpp::Omemo;
2021-05-13 14:50:59 +00:00
Manager::Manager()
2021-05-13 14:54:37 +00:00
: deviceService(new DeviceService(this)),
omemoVariant(new Variant::Conversations) {
connect(this, &Manager::deviceListReceived, deviceService.get(), &DeviceService::onDeviceListReceived);
}
bool QXmpp::Omemo::Manager::handleStanza(const QDomElement &stanza) {
2021-05-13 14:54:37 +00:00
QString str{};
QTextStream info(&str);
stanza.save(info, 4);
std::cout << str.toStdString();
if (stanza.tagName() == "iq") {
if (stanza.attribute("type") == "result") {
auto pubsub = stanza.firstChildElement("pubsub");
if (!pubsub.isNull()) {
auto items = pubsub.firstChildElement("items");
if (items.attribute("node") ==
"eu.siacs.conversations.axolotl.devicelist") {
auto item = items.firstChildElement("item");
if (!item.isNull()) {
auto list = item.firstChildElement("list");
if (!list.isNull()) {
DeviceList deviceList = omemoVariant->deviceListFromXml(list);
emit deviceListReceived(stanza.attribute("from"), deviceList);
return true;
}
}
}
}
}
}
2021-05-13 14:54:37 +00:00
return false;
}
void QXmpp::Omemo::Manager::setClient(QXmppClient *client) {
2021-05-13 14:54:37 +00:00
QXmppClientExtension::setClient(client);
2021-05-13 14:54:37 +00:00
if (!client)
return;
2021-05-13 14:54:37 +00:00
QObject::connect(client, &QXmppClient::connected, this,
&Manager::fetchOwnDevices);
}
void QXmpp::Omemo::Manager::fetchOwnDevices() {
2021-05-13 14:54:37 +00:00
QXmppPubSubIq iq{};
iq.setFrom(client()->configuration().jid());
iq.setTo(client()->configuration().jidBare());
iq.setType(QXmppIq::Get);
iq.setQueryNode("eu.siacs.conversations.axolotl.devicelist");
2021-05-13 14:54:37 +00:00
client()->sendPacket(iq);
}