forked from blue/squawk
ref(omemo): add qomemo/variant
This commit is contained in:
parent
006752b31c
commit
12ffe8e8e6
18 changed files with 366 additions and 222 deletions
1
qomemo/variant/CMakeLists.txt
Normal file
1
qomemo/variant/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
target_sources(squawk PRIVATE xep0384.cpp xep0384.h conversations.cpp conversations.h omemo_base.cpp omemo_base.h)
|
78
qomemo/variant/conversations.cpp
Normal file
78
qomemo/variant/conversations.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "conversations.h"
|
||||
|
||||
#include "qomemo/device.h"
|
||||
#include "shared/qxmppfactories.h"
|
||||
|
||||
#include <QXmppIq.h>
|
||||
|
||||
using namespace QXmpp::Omemo;
|
||||
using namespace QXmpp::Factories;
|
||||
|
||||
QXmppElement Variant::Conversations::deviceToXml(const Device &device) {
|
||||
auto result = createElement("device");
|
||||
result.setAttribute("id", QString::number(device.id));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Device Variant::Conversations::deviceFromXml(const QXmppElement &xml) {
|
||||
Device result{};
|
||||
|
||||
if (!elementMatches(xml, "device"))
|
||||
return result;
|
||||
|
||||
result.id = xml.attribute("id").toInt();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QXmppElement
|
||||
Variant::Conversations::deviceListToXml(const DeviceList &deviceList) {
|
||||
auto element = createElement("list", "eu.siacs.conversations.axolotl");
|
||||
|
||||
for (const auto &device : deviceList.devices) {
|
||||
element.appendChild(deviceToXml(device));
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
DeviceList Variant::Conversations::deviceListFromXml(const QXmppElement &xml) {
|
||||
DeviceList result{};
|
||||
|
||||
if (!elementMatches(xml, "list", "eu.siacs.conversations.axolotl"))
|
||||
return result;
|
||||
|
||||
auto deviceElement = xml.firstChildElement("device");
|
||||
while (!deviceElement.isNull()) {
|
||||
result.devices.push_back(deviceFromXml(deviceElement));
|
||||
deviceElement = deviceElement.nextSiblingElement("device");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QXmppIq Variant::Conversations::deviceListSetIq(const DeviceList &deviceList) {
|
||||
QXmppIq iq{};
|
||||
|
||||
iq.setType(QXmppIq::Set);
|
||||
|
||||
auto item = createElement("item");
|
||||
item.appendChild(deviceListToXml(deviceList));
|
||||
|
||||
auto publish = createElement("publish");
|
||||
publish.setAttribute("node", "eu.siacs.conversations.axolotl.devicelist");
|
||||
publish.appendChild(item);
|
||||
|
||||
auto pubSub = createElement("pubsub", "http://jabber.org/protocol/pubsub");
|
||||
pubSub.appendChild(publish);
|
||||
pubSub.appendChild(createOpenPublishOptions());
|
||||
|
||||
iq.extensions().push_back(pubSub);
|
||||
|
||||
return iq;
|
||||
}
|
23
qomemo/variant/conversations.h
Normal file
23
qomemo/variant/conversations.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "omemo_base.h"
|
||||
|
||||
namespace QXmpp::Omemo::Variant {
|
||||
|
||||
class Conversations : public Base {
|
||||
public:
|
||||
~Conversations() override = default;
|
||||
|
||||
QXmppElement deviceToXml(const Device &device) override;
|
||||
Device deviceFromXml(const QXmppElement &xml) override;
|
||||
|
||||
QXmppElement deviceListToXml(const DeviceList &deviceList) override;
|
||||
DeviceList deviceListFromXml(const QXmppElement &xml) override;
|
||||
QXmppIq deviceListSetIq(const DeviceList &deviceList) override;
|
||||
};
|
||||
|
||||
} // namespace QXmpp::Omemo::Variant
|
5
qomemo/variant/omemo_base.cpp
Normal file
5
qomemo/variant/omemo_base.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "omemo_base.h"
|
31
qomemo/variant/omemo_base.h
Normal file
31
qomemo/variant/omemo_base.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class QXmppElement;
|
||||
class QXmppIq;
|
||||
|
||||
namespace QXmpp::Omemo {
|
||||
|
||||
class Device;
|
||||
class DeviceList;
|
||||
|
||||
namespace Variant {
|
||||
|
||||
class Base {
|
||||
public:
|
||||
virtual ~Base() = default;
|
||||
|
||||
virtual QXmppElement deviceToXml(const Device& device) = 0;
|
||||
virtual Device deviceFromXml(const QXmppElement& xml) = 0;
|
||||
|
||||
virtual QXmppElement deviceListToXml(const DeviceList& deviceList) = 0;
|
||||
virtual DeviceList deviceListFromXml(const QXmppElement& xml) = 0;
|
||||
virtual QXmppIq deviceListSetIq(const DeviceList& deviceList) = 0;
|
||||
};
|
||||
|
||||
} // namespace Variant
|
||||
|
||||
} // namespace QXmpp::Omemo
|
5
qomemo/variant/xep0384.cpp
Normal file
5
qomemo/variant/xep0384.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "xep0384.h"
|
7
qomemo/variant/xep0384.h
Normal file
7
qomemo/variant/xep0384.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace QXmpp::Omemo {}
|
Loading…
Add table
Add a link
Reference in a new issue