From e8f49da15071be2b17982f7f483abae197509f45 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 4 Feb 2026 15:49:43 +0100 Subject: Implement out messages --- yc.cpp | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'yc.cpp') diff --git a/yc.cpp b/yc.cpp index 28e780c..783b63e 100644 --- a/yc.cpp +++ b/yc.cpp @@ -28,37 +28,55 @@ void Yc::connectAccounts(const QList &pairs) } } -void Yc::startChat(const QString from, const QString to) +void Yc::send(const QString to, const QString msg, const bool omemo) { - bool found = false; + if (!selected) + throw std::runtime_error("Expected non-null selected client"); -#if 0 - for (int i = 0; i < ui.conversations_list->count(); i++) - { - const auto it = - static_cast(ui.conversations_list->item(i)); + const auto from = selected->jidBare(); + QXmppMessage out(from, to, msg); + const auto dt = QDateTime::currentDateTimeUtc(); - if (it->from == from && it->to == to) + out.setStamp(dt); + + auto fn = [=](const QXmpp::SendResult &&result) mutable + { + if (std::holds_alternative(result)) { - found = true; - break; + const auto &success = std::get(result); + addOutMessage(msg, dt); + storeMessage(from, to, msg, dt, Direction::Out); + Q_EMIT sent(); } - } + else if (std::holds_alternative(result)) + { + const auto &error = std::get(result); - if (!found) - new Conversation(from, to, ui.conversations_list); + Q_EMIT sendError(error.description); + } + }; + if (omemo) + { + out.setE2eeFallbackBody("[xxcc: This is an OMEMO-encrypted message]"); + // 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, fn); + } + else + selected->send(std::move(out)).then(this, fn); +} + +void Yc::startChat(const QString from, const QString to) +{ for (const auto c : clients) if (c->jidBare() == from) { selected = c; break; } - - ui.sw->setCurrentIndex(Tab::Chat); - ui.jid->setText(to); - ui.messages->scrollToBottom(); -#endif } void Yc::addInMessage(const QXmppMessage &msg) -- cgit v1.2.3