forked from Silverfish/proton-bridge
feat(GODT-2540): notify user of wrong IMAP password.
This commit is contained in:
@ -34,9 +34,7 @@ SPUser User::newUser(QObject *parent) {
|
||||
/// \param[in] parent The parent object.
|
||||
//****************************************************************************************************************************************************
|
||||
User::User(QObject *parent)
|
||||
: QObject(parent)
|
||||
, imapFailureCooldownEndTime_(QDateTime::currentDateTime()) {
|
||||
|
||||
: QObject(parent) {
|
||||
}
|
||||
|
||||
|
||||
@ -355,22 +353,18 @@ QString User::stateToString(UserState state) {
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// We display a notification and pop the application window if an IMAP client tries to connect to a signed out account, but we do not want to
|
||||
/// do it repeatedly, as it's an intrusive action. This function let's you define a period of time during which the notification should not be
|
||||
/// displayed.
|
||||
///
|
||||
/// \param durationMSecs The duration of the period in milliseconds.
|
||||
/// \param[in] durationMSecs The duration of the period in milliseconds.
|
||||
//****************************************************************************************************************************************************
|
||||
void User::startImapLoginFailureCooldown(qint64 durationMSecs) {
|
||||
imapFailureCooldownEndTime_ = QDateTime::currentDateTime().addMSecs(durationMSecs);
|
||||
void User::startNotificationCooldownPeriod(User::ENotification notification, qint64 durationMSecs) {
|
||||
notificationCooldownList_[notification] = QDateTime::currentDateTime().addMSecs(durationMSecs);
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true if we currently are in a cooldown period for the notification
|
||||
/// \return true iff the notification is currently in a cooldown period.
|
||||
//****************************************************************************************************************************************************
|
||||
bool User::isInIMAPLoginFailureCooldown() const {
|
||||
return QDateTime::currentDateTime() < imapFailureCooldownEndTime_;
|
||||
bool User::isNotificationInCooldown(User::ENotification notification) const {
|
||||
return notificationCooldownList_.contains(notification) && (QDateTime::currentDateTime() < notificationCooldownList_[notification]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -62,6 +62,12 @@ typedef std::shared_ptr<class User> SPUser; ///< Type definition for shared poin
|
||||
class User : public QObject {
|
||||
|
||||
Q_OBJECT
|
||||
public: // data types
|
||||
enum class ENotification {
|
||||
IMAPLoginWhileSignedOut, ///< An IMAP client tried to login while the user is signed out.
|
||||
IMAPPasswordFailure, ///< An IMAP client provided an invalid password for the user.
|
||||
};
|
||||
|
||||
public: // static member function
|
||||
static SPUser newUser(QObject *parent); ///< Create a new user
|
||||
static QString stateToString(UserState state); ///< Return a string describing a user state.
|
||||
@ -74,8 +80,8 @@ public: // member functions.
|
||||
User &operator=(User &&) = delete; ///< Disabled move assignment operator.
|
||||
void update(User const &user); ///< Update the user.
|
||||
Q_INVOKABLE QString primaryEmailOrUsername() const; ///< Return the user primary email, or, if unknown its username.
|
||||
void startImapLoginFailureCooldown(qint64 durationMSecs); ///< Start the user cooldown period for the IMAP login attempt while signed-out notification.
|
||||
bool isInIMAPLoginFailureCooldown() const; ///< Check if the user in a IMAP login failure notification.
|
||||
void startNotificationCooldownPeriod(ENotification notification, qint64 durationMSecs); ///< Start the user cooldown period for a notification.
|
||||
bool isNotificationInCooldown(ENotification notification) const; ///< Return true iff the notification is in a cooldown period.
|
||||
|
||||
public slots:
|
||||
// slots for QML generated calls
|
||||
@ -147,7 +153,7 @@ private: // member functions.
|
||||
User(QObject *parent); ///< Default constructor.
|
||||
|
||||
private: // data members.
|
||||
QDateTime imapFailureCooldownEndTime_; ///< The end date/time for the IMAP login failure notification cooldown period.
|
||||
QMap<ENotification, QDateTime> notificationCooldownList_; ///< A list of cooldown period end time for notifications.
|
||||
QString id_; ///< The userID.
|
||||
QString username_; ///< The username
|
||||
QString password_; ///< The IMAP password of the user.
|
||||
|
||||
Reference in New Issue
Block a user