Move PasswordStatus out of Controller

This commit is contained in:
Tobias Fella
2023-12-02 21:04:23 +01:00
parent 65c892787e
commit 0521ff2c4d
5 changed files with 28 additions and 25 deletions

View File

@@ -65,16 +65,6 @@ class Controller : public QObject
Q_PROPERTY(QStringList accountsLoading MEMBER m_accountsLoading NOTIFY accountsLoadingChanged)
public:
/**
* @brief Defines the status after an attempt to change the password on an account.
*/
enum PasswordStatus {
Success, /**< The password was successfully changed. */
Wrong, /**< The current password entered was wrong. */
Other, /**< An unknown problem occurred. */
};
Q_ENUM(PasswordStatus)
static Controller &instance();
static Controller *create(QQmlEngine *engine, QJSEngine *)
{
@@ -162,7 +152,6 @@ Q_SIGNALS:
void quitOnLastWindowClosedChanged();
void unreadCountChanged();
void activeConnectionChanged();
void passwordStatus(Controller::PasswordStatus status);
void userConsentRequired(QUrl url);
void accountsLoadingChanged();

View File

@@ -124,12 +124,11 @@ void NeoChatConnection::changePassword(const QString &currentPassword, const QSt
QJsonObject identifier = {{"type"_ls, "m.id.user"_ls}, {"user"_ls, user()->id()}};
authData["identifier"_ls] = identifier;
NeochatChangePasswordJob *innerJob = callApi<NeochatChangePasswordJob>(newPassword, false, authData);
connect(innerJob, &BaseJob::success, this, []() {
Q_EMIT Controller::instance().passwordStatus(Controller::PasswordStatus::Success);
connect(innerJob, &BaseJob::success, this, [this]() {
Q_EMIT passwordStatus(PasswordStatus::Success);
});
connect(innerJob, &BaseJob::failure, this, [innerJob]() {
Q_EMIT Controller::instance().passwordStatus(innerJob->jsonData()["errcode"_ls] == "M_FORBIDDEN"_ls ? Controller::PasswordStatus::Wrong
: Controller::PasswordStatus::Other);
connect(innerJob, &BaseJob::failure, this, [innerJob, this]() {
Q_EMIT passwordStatus(innerJob->jsonData()["errcode"_ls] == "M_FORBIDDEN"_ls ? PasswordStatus::Wrong : PasswordStatus::Other);
});
}
});

View File

@@ -33,6 +33,16 @@ class NeoChatConnection : public Quotient::Connection
Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged)
public:
/**
* @brief Defines the status after an attempt to change the password on an account.
*/
enum PasswordStatus {
Success, /**< The password was successfully changed. */
Wrong, /**< The current password entered was wrong. */
Other, /**< An unknown problem occurred. */
};
Q_ENUM(PasswordStatus)
NeoChatConnection(QObject *parent = nullptr);
NeoChatConnection(const QUrl &server, QObject *parent = nullptr);
@@ -88,6 +98,7 @@ public:
Q_SIGNALS:
void labelChanged();
void isOnlineChanged();
void passwordStatus(NeoChatConnection::PasswordStatus status);
private:
bool m_isOnline = true;

View File

@@ -215,4 +215,17 @@ FormCard.FormCardPage {
onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")})
}
}
data: Connections {
target: root.connection
function onPasswordStatus(status) {
if (status === NeoChatConnection.Success) {
showPassiveNotification(i18n("Password changed successfully"));
} else if (status === NeoChatConnection.Wrong) {
showPassiveNotification(i18n("Wrong password entered"));
} else {
showPassiveNotification(i18n("Unknown problem while trying to change password"));
}
}
}
}

View File

@@ -110,14 +110,5 @@ FormCard.FormCardPage {
pageStack.layers.pop()
}
}
function onPasswordStatus(status) {
if (status === Controller.Success) {
showPassiveNotification(i18n("Password changed successfully"));
} else if (status === Controller.Wrong) {
showPassiveNotification(i18n("Wrong password entered"));
} else {
showPassiveNotification(i18n("Unknown problem while trying to change password"));
}
}
}
}