qxmpp-project / qxmpp

Cross-platform C++ XMPP client and server library
411 stars 197 forks source link

How to confirm successful sending of single chat messages #581

Closed yuanshengyong closed 12 months ago

yuanshengyong commented 1 year ago

Hello, may I ask how to confirm that this message has been sent normally after calling the sendpacket interface? Currently, only group chat and errors will receive the messageReceived signal

lnjX commented 12 months ago

You can use QXmppClient::send() (see https://doc.qxmpp.org/qxmpp-1/classQXmppClient.html#a750350f089a0e45e1aee3d032e84980c).

for example, like this (untested)

QXmppMessage msg;
client->send(std::move(msg)).then(this, [](auto result) {
  if (auto success = std::get_if<QXmpp::SendSuccess>(&result)) {
    qDebug() << "Sent packet" << "got acknowledgement from local server:" << success->acknowledged;
  } else {
    auto error = std::get<QXmppError>(result);
    qDebug() << "Error sending message:" << error.description;
  }
})