mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-22 01:56:44 +00:00
GODT-1770: handle UserBadEvent in CLI and gRPC.
This commit is contained in:
@ -880,6 +880,24 @@ void QMLBackend::onLoginAlreadyLoggedIn(QString const &userID) {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] userID The userID.
|
||||
/// \param[in] errorMessage. Unused
|
||||
//****************************************************************************************************************************************************
|
||||
void QMLBackend::onUserBadEvent(QString const &userID, QString const &errorMessage) {
|
||||
HANDLE_EXCEPTION(
|
||||
Q_UNUSED(errorMessage);
|
||||
SPUser const user = users_->getUserWithID(userID);
|
||||
if (!user)
|
||||
app().log().error(QString("Received bad event for unknown user %1").arg(user->id()));
|
||||
user->setState(UserState::SignedOut);
|
||||
emit userBadEvent(tr("%1 was logged out because of an internal error.").arg(user->primaryEmailOrUsername()));
|
||||
emit selectUser(userID);
|
||||
emit showMainWindow();
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
@ -987,5 +1005,6 @@ void QMLBackend::connectGrpcEvents() {
|
||||
|
||||
// user events
|
||||
connect(client, &GRPCClient::userDisconnected, this, &QMLBackend::userDisconnected);
|
||||
connect(client, &GRPCClient::userBadEvent, this, &QMLBackend::onUserBadEvent);
|
||||
users_->connectGRPCEvents();
|
||||
}
|
||||
|
||||
@ -181,6 +181,7 @@ public slots: // slot for signals received from gRPC that need transformation in
|
||||
void onGenericError(bridgepp::ErrorInfo const &info); ///< Slot for generic errors received from the gRPC service.
|
||||
void onLoginFinished(QString const &userID, bool wasSignedOut); ///< Slot for LoginFinished gRPC event.
|
||||
void onLoginAlreadyLoggedIn(QString const &userID); ///< Slot for the LoginAlreadyLoggedIn gRPC event.
|
||||
void onUserBadEvent(QString const& userID, QString const& errorMessage); ///< Slot for the userBadEvent gRPC event.
|
||||
|
||||
signals: // Signals received from the Go backend, to be forwarded to QML
|
||||
void toggleAutostartFinished(); ///< Signal for the 'toggleAutostartFinished' gRPC stream event.
|
||||
@ -223,6 +224,7 @@ signals: // Signals received from the Go backend, to be forwarded to QML
|
||||
void addressChangedLogout(QString const &address); ///< Signal for the 'addressChangedLogout' gRPC stream event.
|
||||
void apiCertIssue(); ///< Signal for the 'apiCertIssue' gRPC stream event.
|
||||
void userDisconnected(QString const &username); ///< Signal for the 'userDisconnected' gRPC stream event.
|
||||
void userBadEvent(QString const &message); ///< Signal for the 'userBadEvent' gRPC stream event.
|
||||
void internetOff(); ///< Signal for the 'internetOff' gRPC stream event.
|
||||
void internetOn(); ///< Signal for the 'internetOn' gRPC stream event.
|
||||
void resetFinished(); ///< Signal for the 'resetFinished' gRPC stream event.
|
||||
@ -232,6 +234,7 @@ signals: // Signals received from the Go backend, to be forwarded to QML
|
||||
void showMainWindow(); ///< Signal for the 'showMainWindow' gRPC stream event.
|
||||
void hideMainWindow(); ///< Signal for the 'hideMainWindow' gRPC stream event.
|
||||
void genericError(QString const &title, QString const &description); ///< Signal for the 'genericError' gRPC stream event.
|
||||
void selectUser(QString const); ///< Signal that request the given user account to be displayed.
|
||||
|
||||
// This signal is emitted when an exception is intercepted is calls triggered by QML. QML engine would intercept the exception otherwise.
|
||||
void fatalError(QString const &function, QString const &message) const; ///< Signal emitted when an fatal error occurs.
|
||||
|
||||
@ -161,6 +161,17 @@ User *UserList::get(int row) const {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] userID The userID.
|
||||
/// \return The primary email address (or if unknown the username) of the user.
|
||||
/// \return An empty string if the user cannot be found.
|
||||
//****************************************************************************************************************************************************
|
||||
QString UserList::primaryEmailOrUsername(QString const &userID) const {
|
||||
SPUser const user = this->getUserWithID(userID);
|
||||
return user ? user->primaryEmailOrUsername() : QString();
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] userID The userID.
|
||||
//****************************************************************************************************************************************************
|
||||
|
||||
@ -54,6 +54,7 @@ signals:
|
||||
|
||||
public:
|
||||
Q_INVOKABLE bridgepp::User *get(int row) const;
|
||||
Q_INVOKABLE QString primaryEmailOrUsername(QString const& userID) const; ///< Return the primary email or username of a user
|
||||
|
||||
public slots: ///< handler for signals coming from the gRPC service
|
||||
void onUserChanged(QString const &userID);
|
||||
|
||||
@ -399,4 +399,20 @@ Item {
|
||||
signIn.username = username
|
||||
rightContent.showSignIn()
|
||||
}
|
||||
|
||||
function selectUser(userID) {
|
||||
var users = Backend.users;
|
||||
for (var i = 0; i < users.count; i++) {
|
||||
var user = users.get(i)
|
||||
if (user.id !== userID) {
|
||||
continue;
|
||||
}
|
||||
accounts.currentIndex = i;
|
||||
if (user.state === EUserState.SignedOut)
|
||||
showSignIn(user.primaryEmailOrUsername())
|
||||
return;
|
||||
}
|
||||
console.error("User with ID ", userID, " was not found in the account list")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -86,6 +86,10 @@ ApplicationWindow {
|
||||
root.showAndRise()
|
||||
}
|
||||
|
||||
function onSelectUser(userID) {
|
||||
root.selectUser(userID)
|
||||
}
|
||||
|
||||
function onLoginFinished(index, wasSignedOut) {
|
||||
var user = Backend.users.get(index)
|
||||
if (user && !wasSignedOut) {
|
||||
@ -182,6 +186,7 @@ ApplicationWindow {
|
||||
function showLocalCacheSettings() { contentWrapper.showLocalCacheSettings() }
|
||||
function showSettings() { contentWrapper.showSettings() }
|
||||
function showHelp() { contentWrapper.showHelp() }
|
||||
function selectUser(userID) { contentWrapper.selectUser(userID) }
|
||||
|
||||
function showSignIn(username) {
|
||||
if (contentLayout.currentIndex == 1) return
|
||||
|
||||
@ -80,6 +80,7 @@ QtObject {
|
||||
root.addressChanged,
|
||||
root.apiCertIssue,
|
||||
root.noActiveKeyForRecipient,
|
||||
root.userBadEvent,
|
||||
root.genericError
|
||||
]
|
||||
|
||||
@ -1101,6 +1102,33 @@ QtObject {
|
||||
]
|
||||
}
|
||||
|
||||
property Notification userBadEvent: Notification {
|
||||
title: qsTr("User was logged out")
|
||||
brief: title
|
||||
description: "#PlaceHolderText"
|
||||
icon: "./icons/ic-exclamation-circle-filled.svg"
|
||||
type: Notification.NotificationType.Danger
|
||||
group: Notifications.Group.Connection
|
||||
|
||||
Connections {
|
||||
target: Backend
|
||||
function onUserBadEvent(message) {
|
||||
root.userBadEvent.description = message
|
||||
root.userBadEvent.active = true
|
||||
}
|
||||
}
|
||||
|
||||
action: [
|
||||
Action {
|
||||
text: qsTr("OK")
|
||||
|
||||
onTriggered: {
|
||||
root.userBadEvent.active = false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
property Notification genericError: Notification {
|
||||
title: "#PlaceholderText#"
|
||||
description: "#PlaceholderText#"
|
||||
|
||||
Reference in New Issue
Block a user