Skip to content

Commit 0da96a5

Browse files
committed
p#494 Add search by agent ID to resident chooser
1 parent bb26aa3 commit 0da96a5

File tree

4 files changed

+118
-37
lines changed

4 files changed

+118
-37
lines changed

indra/llmessage/llcachename.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ void LLCacheName::Impl::processPendingAsks()
780780
void LLCacheName::Impl::processPendingReplies()
781781
{
782782
// First call all the callbacks, because they might send messages.
783+
// Todo: needs cleanup logic, otherwise invalid ids might stay here indefinitely
783784
for(ReplyQueue::iterator it = mReplyQueue.begin(); it != mReplyQueue.end(); ++it)
784785
{
785786
PendingReply* reply = *it;

indra/newview/llfloateravatarpicker.cpp

Lines changed: 114 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llfloaterreg.h"
3535
#include "llimview.h" // for gIMMgr
3636
#include "lltooldraganddrop.h" // for LLToolDragAndDrop
37+
#include "lltrans.h"
3738
#include "llviewercontrol.h"
3839
#include "llviewerregion.h" // getCapability()
3940
#include "llworld.h"
@@ -405,15 +406,50 @@ bool LLFloaterAvatarPicker::visibleItemsSelected() const
405406
}
406407

407408
/*static*/
408-
void LLFloaterAvatarPicker::findCoro(std::string url, LLUUID queryID, std::string name)
409+
void LLFloaterAvatarPicker::findByIdCoro(std::string url, LLUUID query_id, LLUUID agent_id, std::string floater_key)
409410
{
410411
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
411412
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
412-
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoro", httpPolicy));
413+
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("findByIdCoro", httpPolicy));
413414
LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
414415
LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
415416

416-
LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Generic POST for " << url << LL_ENDL;
417+
httpOpts->setTimeout(AVATAR_PICKER_SEARCH_TIMEOUT);
418+
419+
LLSD result = httpAdapter->getAndSuspend(httpRequest, url, httpOpts);
420+
421+
LL_DEBUGS("Agent") << result << LL_ENDL;
422+
423+
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
424+
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
425+
426+
if (status || (status == LLCore::HttpStatus(HTTP_BAD_REQUEST)))
427+
{
428+
result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
429+
}
430+
else
431+
{
432+
result["failure_reason"] = status.toString();
433+
}
434+
435+
LLFloaterAvatarPicker* floater =
436+
LLFloaterReg::findTypedInstance<LLFloaterAvatarPicker>("avatar_picker", floater_key);
437+
if (floater)
438+
{
439+
floater->processResponse(query_id, result);
440+
}
441+
}
442+
443+
/*static*/
444+
void LLFloaterAvatarPicker::findByNameCoro(std::string url, LLUUID queryID, std::string name)
445+
{
446+
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
447+
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
448+
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("findByNameCoro", httpPolicy));
449+
LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
450+
LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
451+
452+
LL_INFOS("HttpCoroutineAdapter", "genericPostCoro", "Agent") << "Generic POST for " << url << LL_ENDL;
417453

418454
httpOpts->setTimeout(AVATAR_PICKER_SEARCH_TIMEOUT);
419455

@@ -447,6 +483,7 @@ void LLFloaterAvatarPicker::find()
447483

448484
std::string text = getChild<LLUICtrl>("Edit")->getValue().asString();
449485

486+
LLUUID agent_id;
450487
size_t separator_index = text.find_first_of(" ._");
451488
if (separator_index != text.npos)
452489
{
@@ -458,51 +495,92 @@ void LLFloaterAvatarPicker::find()
458495
text = first;
459496
}
460497
}
498+
else if (!text.empty())
499+
{
500+
agent_id.set(text);
501+
}
461502

462503
mQueryID.generate();
504+
mNumResultsReturned = 0;
463505

464-
std::string url;
465-
url.reserve(128); // avoid a memory allocation or two
506+
getChild<LLScrollListCtrl>("SearchResults")->deleteAllItems();
507+
getChild<LLScrollListCtrl>("SearchResults")->setCommentText(getString("searching"));
508+
getChildView("ok_btn")->setEnabled(false);
466509

467-
LLViewerRegion* region = gAgent.getRegion();
468-
if(region)
510+
if (agent_id.notNull())
469511
{
470-
url = region->getCapability("AvatarPickerSearch");
471-
// Prefer use of capabilities to search on both SLID and display name
472-
if (!url.empty())
512+
// Search by uuid
513+
// While cache could have been nicer, it neither has a failure callback, nor
514+
// can cleanup in case of an invalid uuid. So we go directly to the capability.
515+
LLViewerRegion* region = gAgent.getRegion();
516+
if (region)
473517
{
474-
// capability urls don't end in '/', but we need one to parse
475-
// query parameters correctly
476-
if (url.size() > 0 && url[url.size()-1] != '/')
518+
std::string url;
519+
url.reserve(128);
520+
url = region->getCapability("GetDisplayNames");
521+
if (!url.empty())
477522
{
478-
url += "/";
479-
}
480-
url += "?page_size=100&names=";
481-
std::replace(text.begin(), text.end(), '.', ' ');
482-
url += LLURI::escape(text);
483-
LL_INFOS() << "avatar picker " << url << LL_ENDL;
523+
// capability urls don't end in '/', but we need one to parse
524+
// query parameters correctly
525+
if (url[url.size() - 1] != '/')
526+
{
527+
url += "/";
528+
}
529+
url += "?ids=";
530+
url += agent_id.asString();
531+
LL_DEBUGS("Agent") << "avatar picker " << url << LL_ENDL;
484532

485-
LLCoros::instance().launch("LLFloaterAvatarPicker::findCoro",
486-
boost::bind(&LLFloaterAvatarPicker::findCoro, url, mQueryID, getKey().asString()));
533+
LLCoros::instance().launch("LLFloaterAvatarPicker::findCoro",
534+
boost::bind(&LLFloaterAvatarPicker::findByIdCoro, url, mQueryID, agent_id, getKey().asString()));
535+
}
536+
else
537+
{
538+
LLSD content;
539+
content["failure_reason"] = LLTrans::getString("ServerUnavailable");
540+
processResponse(mQueryID, content);
541+
}
487542
}
488-
else
543+
}
544+
else
545+
{
546+
std::string url;
547+
url.reserve(128); // avoid a memory allocation or two
548+
549+
LLViewerRegion* region = gAgent.getRegion();
550+
if (region)
489551
{
490-
LLMessageSystem* msg = gMessageSystem;
491-
msg->newMessage("AvatarPickerRequest");
492-
msg->nextBlock("AgentData");
493-
msg->addUUID("AgentID", gAgent.getID());
494-
msg->addUUID("SessionID", gAgent.getSessionID());
495-
msg->addUUID("QueryID", mQueryID); // not used right now
496-
msg->nextBlock("Data");
497-
msg->addString("Name", text);
498-
gAgent.sendReliableMessage();
552+
url = region->getCapability("AvatarPickerSearch");
553+
// Prefer use of capabilities to search on both SLID and display name
554+
if (!url.empty())
555+
{
556+
// capability urls don't end in '/', but we need one to parse
557+
// query parameters correctly
558+
if (url.size() > 0 && url[url.size() - 1] != '/')
559+
{
560+
url += "/";
561+
}
562+
url += "?page_size=100&names=";
563+
std::replace(text.begin(), text.end(), '.', ' ');
564+
url += LLURI::escape(text);
565+
LL_DEBUGS("Agent") << "avatar picker " << url << LL_ENDL;
566+
567+
LLCoros::instance().launch("LLFloaterAvatarPicker::findCoro",
568+
boost::bind(&LLFloaterAvatarPicker::findByNameCoro, url, mQueryID, getKey().asString()));
569+
}
570+
else
571+
{
572+
LLMessageSystem* msg = gMessageSystem;
573+
msg->newMessage("AvatarPickerRequest");
574+
msg->nextBlock("AgentData");
575+
msg->addUUID("AgentID", gAgent.getID());
576+
msg->addUUID("SessionID", gAgent.getSessionID());
577+
msg->addUUID("QueryID", mQueryID); // not used right now
578+
msg->nextBlock("Data");
579+
msg->addString("Name", text);
580+
gAgent.sendReliableMessage();
581+
}
499582
}
500583
}
501-
getChild<LLScrollListCtrl>("SearchResults")->deleteAllItems();
502-
getChild<LLScrollListCtrl>("SearchResults")->setCommentText(getString("searching"));
503-
504-
getChildView("ok_btn")->setEnabled(false);
505-
mNumResultsReturned = 0;
506584
}
507585

508586
void LLFloaterAvatarPicker::setAllowMultiple(bool allow_multiple)

indra/newview/llfloateravatarpicker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ class LLFloaterAvatarPicker :public LLFloater
8686
void populateFriend();
8787
bool visibleItemsSelected() const; // Returns true if any items in the current tab are selected.
8888

89-
static void findCoro(std::string url, LLUUID mQueryID, std::string mName);
89+
static void findByIdCoro(std::string url, LLUUID query_id, LLUUID agent_id, std::string floater_key);
90+
static void findByNameCoro(std::string url, LLUUID mQueryID, std::string mName);
9091
void find();
9192
void setAllowMultiple(bool allow_multiple);
9293
LLScrollListCtrl* getActiveList();

indra/newview/skins/default/xui/en/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ are allowed.
327327
<!-- searching - generic -->
328328
<string name="Searching">Searching...</string>
329329
<string name="NoneFound">None found.</string>
330+
<string name="ServerUnavailable">Service not available.</string>
330331

331332
<!-- Indicates that an avatar name or other similar datum is being retrieved. General usage. -->
332333
<string name="RetrievingData">Retrieving...</string>

0 commit comments

Comments
 (0)