diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-08-28 00:20:54 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-09-18 10:35:30 +0200 |
| commit | 5bbe04c9ca091a0626f34afe5e3ba2141e2963de (patch) | |
| tree | 35e76183618fe557b4ded5735fb846e3c6cf3995 /xxcc.cpp | |
| parent | d32b9e93572c5e6999a7323139de38cc1a7197cf (diff) | |
| download | xxcc-5bbe04c9ca091a0626f34afe5e3ba2141e2963de.tar.gz | |
WIP OMEMO TrustDb/JidDb
Diffstat (limited to 'xxcc.cpp')
| -rw-r--r-- | xxcc.cpp | 95 |
1 files changed, 74 insertions, 21 deletions
@@ -6,32 +6,56 @@ #include "conversation.h" #include "message.h" #include <QXmppMessage.h> +#include <QXmppOmemoElement_p.h> #include <QXmppRosterManager.h> #include <QXmppUtils.h> #include <QKeyEvent> #include <QPushButton> #include <QScroller> +#include <iostream> #include <stdexcept> #include <utility> +#include <variant> xxcc::xxcc(QWidget *const parent) : QWidget(parent), selected(nullptr) { - const auto pairs = creds.load(); - ui.setupUi(this); QScroller::grabGesture(ui.conversations_list, QScroller::TouchGesture); QScroller::grabGesture(ui.messages, QScroller::TouchGesture); - connectAccounts(pairs); - retrieveConversations(); + + creds.load().then(this, + [=] (Credentials::PairListResult &&result) + { + if (std::holds_alternative<Credentials::PairList>(result)) + { + const auto &pairs = std::get<Credentials::PairList>(result); + + connectAccounts(pairs); + retrieveConversations(); + } + else if (std::holds_alternative<Credentials::Error>(result)) + { + const auto &error = std::get<Credentials::Error>(result); + + std::cerr << qPrintable(error.description) << std::endl; + } + }); + + connect(ui.accounts, &QPushButton::released, this, [this] { Accounts a(clients, this); a.connect(&a, &Accounts::new_account, this, &xxcc::addAccount); - a.connect(&a, &Accounts::new_account, &creds, &Credentials::store); + a.connect(&a, &Accounts::new_account, this, + [&] (Client *c) + { + creds.store(c); + }); + a.exec(); }); @@ -157,9 +181,9 @@ void xxcc::addInMessage(const QXmppMessage &msg) ui.messages); } -void xxcc::addOutMessage(const QXmppMessage &msg) +void xxcc::addOutMessage(const QString &msg, const QDateTime &dt) { - new Message(msg.body(), msg.stamp().toLocalTime(), Direction::Out, + new Message(msg, dt.toLocalTime(), Direction::Out, ui.messages); } @@ -194,6 +218,8 @@ void xxcc::addAccount(Client *const c) throw std::runtime_error("Expected non-null QXmppRosterManager"); } +#include <QDebug> + void xxcc::send(void) { if (!selected) @@ -201,30 +227,52 @@ void xxcc::send(void) const auto from = selected->jidBare(), to = ui.jid->text(), msg = ui.chatinput->toPlainText(); - + const bool enc = ui.omemo->isChecked(); QXmppMessage out(from, to, msg); + const auto dt = QDateTime::currentDateTimeUtc(); + + out.setE2eeFallbackBody("[xxcc: This is an OMEMO-encrypted message]"); + out.setStamp(dt); + // TODO: QXmpp forces OMEMO 2 (XEP-0384 version >= 0.8.0). + // This breaks compatibility with Dino and Gajim, who still use 0.1.0. + // out.setEncryptionMethod(QXmpp::Omemo0); + + selected->sendSensitive(std::move(out)).then(this, + [=](const QXmpp::SendResult &&result) mutable + { + qDebug() << "result.index(): " << result.index(); - out.setStamp(QDateTime::currentDateTimeUtc()); - selected->sendPacket(out); - addOutMessage(out); - storeMessage(out, Direction::Out); - ui.chatinput->clear(); + if (std::holds_alternative<QXmpp::SendSuccess>(result)) + { + const auto &success = std::get<QXmpp::SendSuccess>(result); + qDebug() << "acknowledged: " << success.acknowledged; + addOutMessage(msg, dt); + storeMessage(from, to, msg, dt, Direction::Out); + ui.chatinput->clear(); + } + else if (std::holds_alternative<QXmppError>(result)) + { + const auto &error = std::get<QXmppError>(result); + qDebug() << error.description; + } + }); } -void xxcc::storeMessage(const QXmppMessage &msg, const Direction dir) const +void xxcc::storeMessage(const QString &from, const QString &to, + const QString &msg, const QDateTime &dt, const Direction dir) const { QString jid, contact; switch (dir) { case Direction::In: - jid = QXmppUtils::jidToBareJid(msg.to()); - contact = QXmppUtils::jidToBareJid(msg.from()); + jid = QXmppUtils::jidToBareJid(to); + contact = QXmppUtils::jidToBareJid(from); break; case Direction::Out: - jid = msg.from(); - contact = msg.to(); + jid = from; + contact = to; break; } @@ -235,15 +283,20 @@ void xxcc::storeMessage(const QXmppMessage &msg, const Direction dir) const const auto &db = c->database(); JidDb::Message m; - m.body = msg.body(); - m.dt = msg.stamp(); + m.body = msg; + m.dt = dt; m.direction = dir; m.contact = contact; - db.storeMessage(m); + db.store(m); } } } +void xxcc::storeMessage(const QXmppMessage &msg, const Direction dir) const +{ + storeMessage(msg.from(), msg.to(), msg.body(), msg.stamp(), dir); +} + void xxcc::retrieveConversations() { for (const auto c : clients) |
