feat(GODT-2444): added queue system for UserBadEvent from different accounts.

This commit is contained in:
Xavier Michelon
2023-03-08 09:50:38 +01:00
parent c496d6c71c
commit 7cc2f3361d
6 changed files with 72 additions and 12 deletions

View File

@ -822,6 +822,15 @@ void QMLBackend::setMailServerSettings(int imapPort, int smtpPort, bool useSSLFo
void QMLBackend::sendBadEventUserFeedback(QString const &userID, bool doResync) {
HANDLE_EXCEPTION(
app().grpc().sendBadEventUserFeedback(userID, doResync);
// Notification dialog has just been dismissed, we remove the userID from the queue, and if there are other events in the queue, we show
// the dialog again.
badEventDisplayQueue_.removeOne(userID);
if (!badEventDisplayQueue_.isEmpty()) {
// we introduce a small delay here, so that the user notices the dialog disappear and pops up again.
QTimer::singleShot(500, [&]() { this->displayBadEventDialog(badEventDisplayQueue_.front()); });
}
)
}
@ -879,19 +888,23 @@ void QMLBackend::onLoginAlreadyLoggedIn(QString const &userID) {
//****************************************************************************************************************************************************
/// \param[in] userID The userID.
/// \param[in] errorMessage. Unused
//****************************************************************************************************************************************************
void QMLBackend::onUserBadEvent(QString const &userID, QString const &errorMessage) {
void QMLBackend::onUserBadEvent(QString const &userID, QString const& ) {
HANDLE_EXCEPTION(
if (badEventDisplayQueue_.contains(userID)) {
app().log().error("Received 'bad event' for a user that is already in the queue.");
return;
}
SPUser const user = users_->getUserWithID(userID);
if (!user)
app().log().error(QString("Received bad event for unknown user %1: %2").arg(user->id(), errorMessage));
// user->setState(UserState::SignedOut);
emit userBadEvent(userID,
tr("Bridge ran into an internal error and it is not able to proceed with the account %1. Synchronize your local database now or logout"
" to do it later. Synchronization time depends on the size of your mailbox.").arg(user->primaryEmailOrUsername()));
emit selectUser(userID);
emit showMainWindow();
if (!user) {
app().log().error(QString("Received bad event for unknown user %1."));
}
badEventDisplayQueue_.append(userID);
if (badEventDisplayQueue_.size() == 1) { // there was no other item is the queue, we can display the dialog immediately.
this->displayBadEventDialog(userID);
}
)
}
@ -1006,3 +1019,22 @@ void QMLBackend::connectGrpcEvents() {
connect(client, &GRPCClient::userBadEvent, this, &QMLBackend::onUserBadEvent);
users_->connectGRPCEvents();
}
//****************************************************************************************************************************************************
/// \param[in] userID The userID.
//****************************************************************************************************************************************************
void QMLBackend::displayBadEventDialog(QString const &userID) {
HANDLE_EXCEPTION(
SPUser const user = users_->getUserWithID(userID);
if (!user) {
return;
}
emit userBadEvent(userID,
tr("Bridge ran into an internal error and it is not able to proceed with the account %1. Synchronize your local database now or logout"
" to do it later. Synchronization time depends on the size of your mailbox.").arg(user->primaryEmailOrUsername()));
emit selectUser(userID);
emit showMainWindow();
)
}

View File

@ -241,6 +241,7 @@ signals: // Signals received from the Go backend, to be forwarded to QML
private: // member functions
void retrieveUserList(); ///< Retrieve the list of users via gRPC.
void connectGrpcEvents(); ///< Connect gRPC that need to be forwarded to QML via backend signals
void displayBadEventDialog(QString const& userID); ///< Displays the bad event dialog for a user.
private: // data members
UserList *users_ { nullptr }; ///< The user list. Owned by backend.
@ -253,6 +254,7 @@ private: // data members
int smtpPort_ { 0 }; ///< The cached value for the SMTP port.
bool useSSLForIMAP_ { false }; ///< The cached value for useSSLForIMAP.
bool useSSLForSMTP_ { false }; ///< The cached value for useSSLForSMTP.
QList<QString> badEventDisplayQueue_; ///< THe queue for displaying 'bad event feedback request dialog'.
friend class AppController;
};

View File

@ -1126,8 +1126,8 @@ QtObject {
text: qsTr("Synchronize")
onTriggered: {
Backend.sendBadEventUserFeedback(root.userBadEvent.userID, true)
root.userBadEvent.active = false
Backend.sendBadEventUserFeedback(root.userBadEvent.userID, true)
}
},
@ -1135,8 +1135,8 @@ QtObject {
text: qsTr("Logout")
onTriggered: {
Backend.sendBadEventUserFeedback(root.userBadEvent.userID, false)
root.userBadEvent.active = false
Backend.sendBadEventUserFeedback(root.userBadEvent.userID, false)
}
}
]