diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-04 15:49:43 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-04 15:49:43 +0100 |
| commit | e8f49da15071be2b17982f7f483abae197509f45 (patch) | |
| tree | d1061b98693792ca517341a9c1698c6f2a7c82ff | |
| parent | 23cc4be5bc02328fe73ccbd67493dd71ef2e2b8f (diff) | |
Implement out messages
| -rw-r--r-- | ChatView.qml | 15 | ||||
| -rw-r--r-- | ContactList.qml | 10 | ||||
| -rw-r--r-- | EncryptionPopup.qml | 1 | ||||
| -rw-r--r-- | yc.cpp | 54 | ||||
| -rw-r--r-- | yc.h | 5 |
5 files changed, 63 insertions, 22 deletions
diff --git a/ChatView.qml b/ChatView.qml index f06d4f7..7445572 100644 --- a/ChatView.qml +++ b/ChatView.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 +import org.yachat.app 1.0 Page { @@ -13,6 +14,7 @@ Page header: CustToolbar { + id: header title: destination } @@ -33,6 +35,15 @@ Page { textarea.forceActiveFocus() } + + Connections + { + target: Yc + function onSent() + { + textarea.text = ""; + } + } } Button @@ -45,6 +56,10 @@ Page { text: qsTr("Send") enabled: textarea.length > 1 + onClicked: + { + Yc.send(header.title, textarea.text, false) + } } } } diff --git a/ContactList.qml b/ContactList.qml index 574bb7e..43c3456 100644 --- a/ContactList.qml +++ b/ContactList.qml @@ -50,10 +50,14 @@ Page width: parent.width text: model.to + " <i>(" + model.jid + "</i>)" anchors.horizontalCenter: parent.horizontalCenter - onClicked: stack.push("qrc:/org/yachat/app/ChatView.qml", + onClicked: { - destination: model.to - }) + Yc.startChat(model.jid, model.to) + stack.push( + "qrc:/org/yachat/app/ChatView.qml", + {destination: model.to} + ) + } } } } diff --git a/EncryptionPopup.qml b/EncryptionPopup.qml index effaf4e..1598f98 100644 --- a/EncryptionPopup.qml +++ b/EncryptionPopup.qml @@ -18,6 +18,7 @@ Popup ComboBox { + id: enccombo model: ListModel { ListElement @@ -28,37 +28,55 @@ void Yc::connectAccounts(const QList<Credentials::Pair> &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<const Conversation *>(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<QXmpp::SendSuccess>(result)) { - found = true; - break; + const auto &success = std::get<QXmpp::SendSuccess>(result); + addOutMessage(msg, dt); + storeMessage(from, to, msg, dt, Direction::Out); + Q_EMIT sent(); } - } + else if (std::holds_alternative<QXmppError>(result)) + { + const auto &error = std::get<QXmppError>(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) @@ -19,10 +19,11 @@ public: Q_INVOKABLE QStringList accounts() const; Q_INVOKABLE void addAccount(Client *c); Q_INVOKABLE void storeAccount(Client *c); + Q_INVOKABLE void send(QString to, QString msg, bool omemo); + Q_INVOKABLE void startChat(QString from, QString to); private: void connectAccounts(const QList<Credentials::Pair> &pairs); - void startChat(QString from, QString to); void addInMessage(const QXmppMessage &msg); void addOutMessage(const QString &msg, const QDateTime &dt); void storeMessage(const QString &from, const QString &to, @@ -37,6 +38,8 @@ private: signals: void newConversation(QString jid, QString to, QString lastmsg); + void sent(); + void sendError(QString error); }; #endif |
