feat(OMEMO): DeviceKeyStorage, DeviceService, UserDeviceList stubs

This commit is contained in:
vae 2021-05-12 15:50:52 +03:00
parent 6721b62629
commit b1a8f162ce
Signed by: vae
GPG Key ID: A9A33351400E00E5
8 changed files with 128 additions and 1 deletions

View File

@ -1,8 +1,14 @@
target_sources(squawk PRIVATE target_sources(squawk PRIVATE
device_key_storage.cpp
device_key_storage.h
device_service.cpp
device_service.h
signal.h signal.h
signal.cpp signal.cpp
qomemo.cpp qomemo.cpp
qomemo.h qomemo.h
sce.cpp sce.cpp
sce.h sce.h
user_device_list.cpp
user_device_list.h
) )

View File

@ -0,0 +1,15 @@
/*
* Created by victoria on 2021-05-12.
*/
#include "device_key_storage.h"
#include <QRandomGenerator>
int QXmpp::Omemo::DeviceKeyStorage::generateDeviceId() {
QRandomGenerator random{};
return 1 + random.bounded(INT32_MAX - 1);
}
QXmpp::Omemo::DeviceKeyStorage::DeviceKeyStorage(int deviceId)
: deviceId(deviceId) {}

View File

@ -0,0 +1,18 @@
/*
* Created by victoria on 2021-05-12.
*/
#pragma once
namespace QXmpp::Omemo {
class DeviceKeyStorage {
public:
static int generateDeviceId();
explicit DeviceKeyStorage(int deviceId);
const int deviceId;
};
} // namespace QXmpp::Omemo

30
qomemo/device_service.cpp Normal file
View File

@ -0,0 +1,30 @@
/*
* Created by victoria on 2021-05-12.
*/
#include "device_service.h"
#include <QXmppClient.h>
#include <QXmppPubSubIq.h>
#include <QDebug>
QXmpp::Omemo::DeviceService::DeviceService(QXmppClient &client, QObject *parent)
: QObject(parent), client(client) {
connect(&client, &QXmppClient::iqReceived, this,
&DeviceService::onIqReceived);
}
void QXmpp::Omemo::DeviceService::onIqReceived(const QXmppIq &iq) {
// Update OMEMO device list
}
void QXmpp::Omemo::DeviceService::fetch() {
QXmppPubSubIq fetchOwnDevices{};
fetchOwnDevices.setFrom(client.configuration().jid());
fetchOwnDevices.setTo(client.configuration().jidBare());
fetchOwnDevices.setType(QXmppIq::Get);
fetchOwnDevices.setQueryNode("urn:xmpp:omemo:1:devices");
client.sendPacket(fetchOwnDevices);
}

31
qomemo/device_service.h Normal file
View File

@ -0,0 +1,31 @@
/*
* Created by victoria on 2021-05-12.
*/
#pragma once
#include "user_device_list.h"
#include <QXmppClient.h>
namespace QXmpp::Omemo {
class DeviceService : public QObject {
Q_OBJECT
public:
DeviceService(QXmppClient& client, QObject *parent);
void fetch();
public slots:
void onIqReceived(const QXmppIq& iq);
private:
void announce();
QXmppClient& client;
QMap<QString, UserDeviceList> device_lists{};
};
} // namespace QXmpp::Omemo

View File

@ -91,4 +91,4 @@ public:
QXmppMessage message{}; QXmppMessage message{};
}; };
} // namespace QOmemo } // namespace QXmpp::Omemo

View File

@ -0,0 +1,10 @@
/*
* Created by victoria on 2021-05-12.
*/
#include "user_device_list.h"
#include <utility>
QXmpp::Omemo::UserDeviceList::UserDeviceList(QString jid)
: jid(std::move(jid)) {}

17
qomemo/user_device_list.h Normal file
View File

@ -0,0 +1,17 @@
/*
* Created by victoria on 2021-05-12.
*/
#pragma once
#include <QString>
namespace QXmpp::Omemo {
class UserDeviceList {
public:
explicit UserDeviceList(QString jid);
const QString jid;
};
} // namespace QXmpp::Omemo