Fix inconsistent displayed name (#13645)

* Add get_json_string_field helper

Introduce get_json_string_field in OrcaCloudServiceAgent.cpp to safely extract string fields from JSON objects.

* Add resolve_display_name helper

Introduce resolve_display_name to normalize provider metadata labels for the UI. The helper returns the first non-empty value from display_name, nickname, full_name, name, falling back to username, resolving human-facing label across varying provider payloads.

* Replace safe_str anonymous function

Replace get_json_string_field for better readability.

* Replace resolution flow for nickname with function

Consolidate both flows into one function for easier maintenance and more consistency.

* Update OrcaCloudServiceAgent.hpp

* Add OrcaCloudServiceAgent display name tests

Add unit tests verifying OrcaCloudServiceAgent resolves a user's display name from various session JSON shapes.
This commit is contained in:
Andrew
2026-05-13 17:58:08 +08:00
committed by GitHub
parent a167702038
commit 33be9775dc
3 changed files with 151 additions and 31 deletions
+4 -3
View File
@@ -88,8 +88,8 @@ public:
std::string access_token;
std::string refresh_token;
std::string user_id;
// Orca auth semantics: user_name is unique orca cloud username(orca_xxxxx), user_nickname is
// the display name shown in the UI when available.
// Orca auth semantics: user_name is the unique Orca Cloud username (orca_xxxxx),
// user_nickname is the display name shown in the UI when available.
std::string user_name;
std::string user_nickname;
std::string user_avatar;
@@ -276,13 +276,14 @@ public:
bool refresh_now(const std::string& refresh_token, const std::string& reason, bool async = false);
bool refresh_session_with_token(const std::string& refresh_token);
// Session state helpers
// Session state helpers. nickname is the human-facing UI label after provider fallback resolution.
bool set_user_session(const std::string& token,
const std::string& user_id,
const std::string& username,
const std::string& nickname,
const std::string& avatar,
const std::string& refresh_token = "");
// Accepts either nested Orca cloud / GoTrue session JSON or flat WebView token JSON.
bool set_user_session(const nlohmann::json& session_json, bool notify_login = true);
void clear_session();