diff options
author | Kadah_Coba <kadah.coba@gmail.com> | 2019-02-13 00:28:57 -0800 |
---|---|---|
committer | Kadah_Coba <kadah.coba@gmail.com> | 2019-02-13 00:28:57 -0800 |
commit | 396f172636db85093f97fafa8906b3ad4cf6eecd (patch) | |
tree | 738900c252df3abb08c35c776488038ca0f370f3 /indra/newview | |
parent | 18d8be556c03bf6f7db175e51cce93ece37c45d2 (diff) |
Updated LLViewerDisplayName to coroutine
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llviewerdisplayname.cpp | 47 | ||||
-rw-r--r-- | indra/newview/llviewerdisplayname.h | 6 |
2 files changed, 31 insertions, 22 deletions
diff --git a/indra/newview/llviewerdisplayname.cpp b/indra/newview/llviewerdisplayname.cpp index e390e8776d..24291de6df 100644 --- a/indra/newview/llviewerdisplayname.cpp +++ b/indra/newview/llviewerdisplayname.cpp @@ -35,7 +35,6 @@ // library includes #include "llavatarnamecache.h" -#include "llhttpclient.h" #include "llhttpnode.h" #include "llnotificationsutil.h" #include "llui.h" // getLanguage() @@ -56,19 +55,6 @@ namespace LLViewerDisplayName void doNothing() { } } -class LLSetDisplayNameResponder : public LLHTTPClient::Responder -{ - LOG_CLASS(LLSetDisplayNameResponder); -private: - // only care about errors - /*virtual*/ void httpFailure() - { - LL_WARNS() << dumpResponse() << LL_ENDL; - LLViewerDisplayName::sSetDisplayNameSignal(false, "", LLSD()); - LLViewerDisplayName::sSetDisplayNameSignal.disconnect_all_slots(); - } -}; - void LLViewerDisplayName::set(const std::string& display_name, const set_name_slot_t& slot) { // TODO: simple validation here @@ -83,11 +69,6 @@ void LLViewerDisplayName::set(const std::string& display_name, const set_name_sl return; } - // People API can return localized error messages. Indicate our - // language preference via header. - LLSD headers; - headers[HTTP_OUT_HEADER_ACCEPT_LANGUAGE] = LLUI::getLanguage(); - // People API requires both the old and new value to change a variable. // Our display name will be in cache before the viewer's UI is available // to request a change, so we can use direct lookup without callback. @@ -113,7 +94,33 @@ void LLViewerDisplayName::set(const std::string& display_name, const set_name_sl // communicates with the back-end. LLSD body; body["display_name"] = change_array; - LLHTTPClient::post(cap_url, body, new LLSetDisplayNameResponder, headers); + LLCoros::instance().launch("LLViewerDisplayName::SetDisplayNameCoro", + boost::bind(&LLViewerDisplayName::setDisplayNameCoro, cap_url, body)); +} + +void LLViewerDisplayName::setDisplayNameCoro(const std::string& cap_url, const LLSD& body) +{ + LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t + httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("SetDisplayNameCoro", httpPolicy)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpHeaders::ptr_t httpHeaders(new LLCore::HttpHeaders); + + // People API can return localized error messages. Indicate our + // language preference via header. + httpHeaders->append(HTTP_OUT_HEADER_ACCEPT_LANGUAGE, LLUI::getLanguage()); + + LLSD result = httpAdapter->postAndSuspend(httpRequest, cap_url, body, httpHeaders); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + LL_WARNS() << "Unable to set display name. Status: " << status.toString() << LL_ENDL; + LLViewerDisplayName::sSetDisplayNameSignal(false, "", LLSD()); + LLViewerDisplayName::sSetDisplayNameSignal.disconnect_all_slots(); + } } class LLSetDisplayNameReply : public LLHTTPNode diff --git a/indra/newview/llviewerdisplayname.h b/indra/newview/llviewerdisplayname.h index 16d59ae43b..337aaa68b6 100644 --- a/indra/newview/llviewerdisplayname.h +++ b/indra/newview/llviewerdisplayname.h @@ -45,8 +45,10 @@ namespace LLViewerDisplayName // Sends an update to the server to change a display name // and call back when done. May not succeed due to service // unavailable or name not available. - void set(const std::string& display_name, const set_name_slot_t& slot); - + void set(const std::string& display_name, const set_name_slot_t& slot); + + void setDisplayNameCoro(const std::string& cap_url, const LLSD& body); + void addNameChangedCallback(const name_changed_signal_t::slot_type& cb); } |