From fd0e02233f925cff699c08b135887a09bdc16e5c Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Thu, 6 Feb 2020 11:49:26 +0100 Subject: QXmppRegistrationManager: Handle result of deleteAccount() This adds two signals to make the result easily available to the user. --- src/client/QXmppRegistrationManager.cpp | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/client/QXmppRegistrationManager.cpp') diff --git a/src/client/QXmppRegistrationManager.cpp b/src/client/QXmppRegistrationManager.cpp index 48cd3d47..4f8e97a6 100644 --- a/src/client/QXmppRegistrationManager.cpp +++ b/src/client/QXmppRegistrationManager.cpp @@ -47,8 +47,9 @@ public: QString changePasswordIqId; QString newPassword; - QString registrationIqId; + QString deleteAccountIqIq; + QString registrationIqId; QXmppRegisterIq registrationFormToSend; }; @@ -98,16 +99,15 @@ void QXmppRegistrationManager::changePassword(const QString &newPassword) /// /// Cancels an existing registration on the server. /// -/// \returns The ID of the sent IQ, if it was sent successfully. A null string -/// is returned otherwise. +/// \sa accountDeleted() +/// \sa accountDeletionFailed() /// -QString QXmppRegistrationManager::deleteAccount() +void QXmppRegistrationManager::deleteAccount() { auto iq = QXmppRegisterIq::createUnregistrationRequest(); + d->deleteAccountIqIq = iq.id(); - if (client()->sendPacket(iq)) - return iq.id(); - return {}; + client()->sendPacket(iq); } bool QXmppRegistrationManager::supportedByServer() const @@ -258,6 +258,26 @@ bool QXmppRegistrationManager::handleStanza(const QDomElement &stanza) d->changePasswordIqId.clear(); d->newPassword.clear(); return true; + } else if (!id.isEmpty() && id == d->deleteAccountIqIq) { + QXmppIq iq; + iq.parse(stanza); + + switch (iq.type()) { + case QXmppIq::Result: + info(QStringLiteral("Account deleted successfully.")); + emit accountDeleted(); + client()->disconnectFromServer(); + break; + case QXmppIq::Error: + warning(QStringLiteral("Failed to delete account: ").append(iq.error().text())); + emit accountDeletionFailed(iq.error()); + break; + default: + break; // should never occur + } + + d->deleteAccountIqIq.clear(); + return true; } else if (QXmppRegisterIq::isRegisterIq(stanza)) { QXmppRegisterIq iq; iq.parse(stanza); -- cgit v1.2.3