summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llpanelpeople.cpp132
-rw-r--r--indra/newview/llpanelpeople.h7
2 files changed, 112 insertions, 27 deletions
diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp
index d2e764df13..ebf7002fc1 100644
--- a/indra/newview/llpanelpeople.cpp
+++ b/indra/newview/llpanelpeople.cpp
@@ -536,6 +536,7 @@ private:
LLPanelPeople::LLPanelPeople()
: LLPanel(),
+ mConnectedToFbc(false),
mFilterSubString(LLStringUtil::null),
mFilterSubStringOrig(LLStringUtil::null),
mFilterEditor(NULL),
@@ -885,23 +886,17 @@ void LLPanelPeople::updateFbcTestList()
{
if (mFbcTestBrowserHandle.get())
{
- // get the browser data (from the title bar, of course!)
- std::string title = mFbcTestBrowserHandle.get()->getTitle();
+ // get the current browser url (from the title bar, of course!)
+ std::string url = mFbcTestBrowserHandle.get()->getTitle();
- // if the data is ready (if it says the magic word)
- if (title.length() >= 2 && title[0] == ':')
+ // if the browser has redirected from facebook
+ if (url.substr(0, FBC_SERVICES_URL.length()) == FBC_SERVICES_URL)
{
- // success! :)
- if (title[1] == ')')
- {
- // get the friends
- getFacebookFriends();
- }
- // failure :(
- else if (title[1] == '(')
- {
- llinfos << "authentication failed" << llendl;
- }
+ // get the auth code
+ std::string auth_code = url.substr(FBC_SERVICES_URL.length() + 6);
+
+ // finish authenticating on the server
+ connectToFacebook(auth_code);
// close the browser window
mFbcTestBrowserHandle.get()->die();
@@ -1669,15 +1664,82 @@ void LLPanelPeople::showFacebookFriends(const LLSD& friends)
for (LLSD::array_const_iterator i = friends.beginArray(); i != friends.endArray(); ++i)
{
- const LLSD& fb_friend = *i;
-
- std::string name = fb_friend["name"].asString();
- LLUUID agent_id = fb_friend.has("agent_id") ? fb_friend["agent_id"].asUUID() : LLUUID(NULL);
+ std::string name = (*i)["name"].asString();
+ LLUUID agent_id = (*i).has("agent_id") ? (*i)["agent_id"].asUUID() : LLUUID(NULL);
mFacebookFriends->addSocialItem(agent_id, name, false);
}
}
+void LLPanelPeople::hideFacebookFriends()
+{
+ mFacebookFriends->clear();
+}
+
+class FacebookConnectResponder : public LLHTTPClient::Responder
+{
+public:
+
+ LLPanelPeople * mPanelPeople;
+
+ FacebookConnectResponder(LLPanelPeople * panel_people) : mPanelPeople(panel_people) {}
+
+ /*virtual*/ void completed(U32 status, const std::string& reason, const LLSD& content)
+ {
+ if (isGoodStatus(status))
+ {
+ llinfos << content << llendl;
+
+ // grab some graph data now that we are connected
+ if (content["success"])
+ {
+ mPanelPeople->mConnectedToFbc = true;
+ mPanelPeople->loadFacebookFriends();
+ }
+ else if (content.has("error"))
+ {
+ llinfos << "failed to connect. reason: " << content["error"]["message"] << llendl;
+ }
+ }
+ else
+ {
+ llinfos << "failed to get response. reason: " << reason << " status: " << status << llendl;
+ }
+ }
+};
+
+class FacebookDisconnectResponder : public LLHTTPClient::Responder
+{
+public:
+
+ LLPanelPeople * mPanelPeople;
+
+ FacebookDisconnectResponder(LLPanelPeople * panel_people) : mPanelPeople(panel_people) {}
+
+ /*virtual*/ void completed(U32 status, const std::string& reason, const LLSD& content)
+ {
+ if (isGoodStatus(status))
+ {
+ llinfos << content << llendl;
+
+ // hide all the facebook stuff
+ if (content["success"])
+ {
+ mPanelPeople->mConnectedToFbc = false;
+ mPanelPeople->hideFacebookFriends();
+ }
+ else if (content.has("error"))
+ {
+ llinfos << "failed to disconnect. reason: " << content["error"]["message"] << llendl;
+ }
+ }
+ else
+ {
+ llinfos << "failed to get response. reason: " << reason << " status: " << status << llendl;
+ }
+ }
+};
+
class FacebookConnectedResponder : public LLHTTPClient::Responder
{
public:
@@ -1693,16 +1755,17 @@ public:
{
llinfos << content << llendl;
- // pull down graph data if already contected
+ // grab some graph data if already connected
if (content["connected"])
{
- mPanelPeople->getFacebookFriends();
+ mPanelPeople->mConnectedToFbc = true;
+ mPanelPeople->loadFacebookFriends();
}
- // show the facebook login page
+ // show the facebook login page if not connected yet
else if (mShowLoginIfNotConnected)
{
LLFloaterWebContent::Params p;
- p.url("https://www.facebook.com/dialog/oauth?client_id=565771023434202&redirect_uri=" + FBC_SERVICES_URL + "/agent/" + gAgentID.asString() + "/fbc/connect");
+ p.url("https://www.facebook.com/dialog/oauth?client_id=565771023434202&redirect_uri=" + FBC_SERVICES_URL);
mPanelPeople->openFacebookWeb(p);
}
}
@@ -1727,7 +1790,7 @@ public:
{
llinfos << content << llendl;
- // display the friend data
+ // display the list of friends
if (content.has("friends"))
{
mPanelPeople->showFacebookFriends(content["friends"]);
@@ -1744,14 +1807,31 @@ public:
}
};
-void LLPanelPeople::getFacebookFriends()
+void LLPanelPeople::loadFacebookFriends()
{
LLHTTPClient::get(FBC_SERVICES_URL + "/agent/" + gAgentID.asString() + "/fbc/friends", new FacebookFriendsResponder(this));
}
+void LLPanelPeople::connectToFacebook(const std::string& auth_code)
+{
+ LLHTTPClient::post(FBC_SERVICES_URL + "/agent/" + gAgentID.asString() + "/fbc/connect/" + auth_code, LLSD(), new FacebookConnectResponder(this));
+}
+
+void LLPanelPeople::disconnectFromFacebook()
+{
+ LLHTTPClient::post(FBC_SERVICES_URL + "/agent/" + gAgentID.asString() + "/fbc/disconnect", LLSD(), new FacebookDisconnectResponder(this));
+}
+
void LLPanelPeople::onLoginFbcButtonClicked()
{
- LLHTTPClient::get(FBC_SERVICES_URL + "/agent/" + gAgentID.asString() + "/fbc/connected", new FacebookConnectedResponder(this, true));
+ if (mConnectedToFbc)
+ {
+ disconnectFromFacebook();
+ }
+ else
+ {
+ LLHTTPClient::get(FBC_SERVICES_URL + "/agent/" + gAgentID.asString() + "/fbc/connected", new FacebookConnectedResponder(this, true));
+ }
}
void LLPanelPeople::onFacebookAppRequestClicked()
diff --git a/indra/newview/llpanelpeople.h b/indra/newview/llpanelpeople.h
index 45ed7e1039..914899ca6d 100644
--- a/indra/newview/llpanelpeople.h
+++ b/indra/newview/llpanelpeople.h
@@ -59,7 +59,12 @@ public:
void openFacebookWeb(LLFloaterWebContent::Params& p);
void showFacebookFriends(const LLSD& friends);
- void getFacebookFriends();
+ void hideFacebookFriends();
+ void loadFacebookFriends();
+ void connectToFacebook(const std::string& auth_code);
+ void disconnectFromFacebook();
+
+ bool mConnectedToFbc;
// internals
class Updater;