summaryrefslogtreecommitdiff
path: root/yc.cpp
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-02-04 15:49:43 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-04 15:49:43 +0100
commite8f49da15071be2b17982f7f483abae197509f45 (patch)
treed1061b98693792ca517341a9c1698c6f2a7c82ff /yc.cpp
parent23cc4be5bc02328fe73ccbd67493dd71ef2e2b8f (diff)
downloadyachat6-e8f49da15071be2b17982f7f483abae197509f45.tar.gz
Implement out messages
Diffstat (limited to 'yc.cpp')
-rw-r--r--yc.cpp54
1 files changed, 36 insertions, 18 deletions
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<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)