feat(GODT-3121): suggestions are transferred to QML.

This commit is contained in:
Xavier Michelon 2023-11-29 17:43:50 +01:00
parent 2e2648fcd5
commit cfd07cf893
6 changed files with 18 additions and 6 deletions

View File

@ -360,11 +360,11 @@ Status GRPCService::SetMainExecutable(ServerContext *, StringValue const *reques
//****************************************************************************************************************************************************
grpc::Status GRPCService::RequestKnowledgeBaseSuggestions(ServerContext*, StringValue const* request, Empty*) {
app().log().info(QString("RequestKnowledgeBaseSuggestions: %1").arg(QString::fromStdString(request->value()).left(10) + "..."));
QList<bridgepp::KnowledgeBaseSuggestion> suggestions(3);
for (qsizetype i = 0; i < 3; ++i) {
QList<bridgepp::KnowledgeBaseSuggestion> suggestions;
for (qsizetype i = 1; i <= 3; ++i) {
suggestions.push_back( {
.title = QString("Suggested link %1").arg(i),
.url = "https://proton.me/support/bridge"
.url = QString("https://proton.me/support/bridge#%1").arg(i),
});
}
qtProxy_.sendDelayedEvent(newKnowledgeBaseSuggestionsEvent(suggestions));

View File

@ -1315,6 +1315,7 @@ void QMLBackend::connectGrpcEvents() {
connect(client, &GRPCClient::certificateInstallCanceled, this, &QMLBackend::certificateInstallCanceled);
connect(client, &GRPCClient::certificateInstallFailed, this, &QMLBackend::certificateInstallFailed);
connect(client, &GRPCClient::showMainWindow, [&]() { this->showMainWindow("gRPC showMainWindow event"); });
connect(client, &GRPCClient::knowledgeBasSuggestionsReceived, this, &QMLBackend::receivedKnowledgeBaseSuggestions);
// cache events
connect(client, &GRPCClient::cantMoveDiskCache, this, &QMLBackend::cantMoveDiskCache);

View File

@ -279,6 +279,7 @@ signals: // Signals received from the Go backend, to be forwarded to QML
void selectUser(QString const& userID, bool forceShowWindow); ///< Signal emitted in order to selected a user with a given ID in the list.
void genericError(QString const &title, QString const &description); ///< Signal for the 'genericError' gRPC stream event.
void imapLoginWhileSignedOut(QString const& username); ///< Signal for the notification of IMAP login attempt on a signed out account.
void receivedKnowledgeBaseSuggestions(QList<bridgepp::KnowledgeBaseSuggestion> const& suggestions); ///< Signal for the reception of knowledgebase article suggestions.
// This signal is emitted when an exception is intercepted is calls triggered by QML. QML engine would intercept the exception otherwise.
void fatalError(bridgepp::Exception const& e) const; ///< Signal emitted when an fatal error occurs.

View File

@ -155,7 +155,12 @@ SettingsView {
function onReportBugFinished() {
sendButton.loading = false;
}
function onReceivedKnowledgeBaseSuggestions(suggestions) {
console.error("QML: onReceivedKnowledgeBaseSuggestions() - len = %1".arg(suggestions.length))
console.error("QML: %1: %2".arg(suggestions[0].title).arg(suggestions[0].url))
console.error("QML: %1: %2".arg(suggestions[1].title).arg(suggestions[1].url))
console.error("QML: %1: %2".arg(suggestions[2].title).arg(suggestions[2].url))
}
target: Backend
}
}

View File

@ -1182,7 +1182,7 @@ void GRPCClient::processAppEvent(AppEvent const &event) {
.title = QString::fromUtf8(suggestion.title())
});
}
emit knowledgeBasSuggestions(suggestions);
emit knowledgeBasSuggestionsReceived(suggestions);
break;
}
default:

View File

@ -46,6 +46,11 @@ typedef std::unique_ptr<grpc::ClientContext> UPClientContext;
/// \brief A struct for knowledge base suggestion.
//****************************************************************************************************************************************************
struct KnowledgeBaseSuggestion {
// The following lines make the type transmissible to QML (but not instanciable there)
Q_GADGET
Q_PROPERTY(QString url MEMBER url)
Q_PROPERTY(QString title MEMBER title)
public:
QString url; ///< The URL of the knowledge base article
QString title; ///< The title of the knowledge base article.
};
@ -116,7 +121,7 @@ signals: // app related signals
void certificateInstallCanceled();
void certificateInstallFailed();
void showMainWindow();
void knowledgeBasSuggestions(QList<KnowledgeBaseSuggestion> const& suggestions);
void knowledgeBasSuggestionsReceived(QList<KnowledgeBaseSuggestion> const& suggestions);
public: // cache related calls