diff options
author | Merov Linden <merov@lindenlab.com> | 2013-05-08 16:53:52 -0700 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2013-05-08 16:53:52 -0700 |
commit | 14be8efcc6a9797d2041e56addd0897f0b4234ea (patch) | |
tree | 9937caef33b388412ffe68f84fbe98db2da3f705 /indra/newview | |
parent | bd482ab55e30403438aed2fc19200eae36efc96a (diff) |
ACME-348 : WIP : LLFacebookConnect refactoring
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/CMakeLists.txt | 2 | ||||
-rw-r--r-- | indra/newview/llfacebookconnect.cpp | 215 | ||||
-rw-r--r-- | indra/newview/llfacebookconnect.h | 66 | ||||
-rw-r--r-- | indra/newview/llpanelpeople.cpp | 178 | ||||
-rw-r--r-- | indra/newview/llpanelpeople.h | 4 |
5 files changed, 283 insertions, 182 deletions
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 6b7fa7d842..44b1604b15 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -185,6 +185,7 @@ set(viewer_SOURCE_FILES llexpandabletextbox.cpp llexternaleditor.cpp llface.cpp + llfacebookconnect.cpp llfasttimerview.cpp llfavoritesbar.cpp llfeaturemanager.cpp @@ -769,6 +770,7 @@ set(viewer_HEADER_FILES llexpandabletextbox.h llexternaleditor.h llface.h + llfacebookconnect.h llfasttimerview.h llfavoritesbar.h llfeaturemanager.h diff --git a/indra/newview/llfacebookconnect.cpp b/indra/newview/llfacebookconnect.cpp new file mode 100644 index 0000000000..1962f6fd97 --- /dev/null +++ b/indra/newview/llfacebookconnect.cpp @@ -0,0 +1,215 @@ +/** + * @file llfacebookconnect.h + * @author Merov, Cho, Gil + * @brief Connection to Facebook Service + * + * $LicenseInfo:firstyear=2013&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2013, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llfacebookconnect.h" + +/////////////////////////////////////////////////////////////////////////////// +// +class LLFacebookConnectResponder : public LLHTTPClient::Responder +{ + LOG_CLASS(LLFacebookConnectResponder); +public: + + virtual void completed(U32 status, const std::string& reason, const LLSD& content) + { + if (isGoodStatus(status)) + { + LL_DEBUGS("FacebookConnect") << "Connect successful. content: " << content << LL_ENDL; + + // Grab some graph data now that we are connected + LLFacebookConnect::instance().setConnected(true); + LLFacebookConnect::instance().loadFacebookFriends(); + } + else + { + LL_WARNS("FacebookConnect") << "Failed to get a response. reason: " << reason << " status: " << status << LL_ENDL; + } + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +class LLFacebookDisconnectResponder : public LLHTTPClient::Responder +{ + LOG_CLASS(LLFacebookDisconnectResponder); +public: + + virtual void completed(U32 status, const std::string& reason, const LLSD& content) + { + if (isGoodStatus(status)) + { + LL_DEBUGS("FacebookConnect") << "Disconnect successful. content: " << content << LL_ENDL; + + // Hide all the facebook stuff + LLFacebookConnect::instance().setConnected(false); + LLFacebookConnect::instance().hideFacebookFriends(); + } + else + { + LL_WARNS("FacebookConnect") << "Failed to get a response. reason: " << reason << " status: " << status << LL_ENDL; + } + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +class LLFacebookConnectedResponder : public LLHTTPClient::Responder +{ + LOG_CLASS(LLFacebookDisconnectResponder); +public: + + LLFacebookConnectedResponder(bool show_login_if_not_connected) : mShowLoginIfNotConnected(show_login_if_not_connected) {} + + virtual void completed(U32 status, const std::string& reason, const LLSD& content) + { + if (isGoodStatus(status)) + { + LL_DEBUGS("FacebookConnect") << "Connect successful. content: " << content << LL_ENDL; + + // Grab some graph data if already connected + LLFacebookConnect::instance().setConnected(true); + LLFacebookConnect::instance().loadFacebookFriends(); + } + else + { + LL_WARNS("FacebookConnect") << "Failed to get a response. reason: " << reason << " status: " << status << LL_ENDL; + + // show the facebook login page if not connected yet + if ((status == 404) && mShowLoginIfNotConnected) + { + LLFacebookConnect::instance().connectToFacebook(); + } + } + } + +private: + bool mShowLoginIfNotConnected; +}; + +/////////////////////////////////////////////////////////////////////////////// +// +class LLFacebookFriendsResponder : public LLHTTPClient::Responder +{ + LOG_CLASS(LLFacebookFriendsResponder); +public: + + virtual void completed(U32 status, const std::string& reason, const LLSD& content) + { + if (isGoodStatus(status)) + { + LL_DEBUGS("FacebookConnect") << "Getting Facebook friends successful. content: " << content << LL_ENDL; + + // Display the list of friends + LLFacebookConnect::instance().showFacebookFriends(content); + } + else + { + LL_WARNS("FacebookConnect") << "Failed to get a response. reason: " << reason << " status: " << status << LL_ENDL; + } + } +}; + + +/////////////////////////////////////////////////////////////////////////////// +// +LLFacebookConnect::LLFacebookConnect() +: mConnectedToFbc(false) +{ +} + +void LLFacebookConnect::init() +{ +} + +void LLFacebookConnect::loadFacebookFriends() +{ + const bool follow_redirects=false; + const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; + LLHTTPClient::get(getFacebookConnectURL("/friend"), new FacebookFriendsResponder(this), + LLSD(), timeout, follow_redirects); +} + +void LLFacebookConnect::hideFacebookFriends() +{ + // That needs to be done in llpanelpeople... + //mFacebookFriends->clear(); +} + +void LLFacebookConnect::connectToFacebook(const std::string& auth_code) +{ + LLSD body; + if (!auth_code.empty()) + body["code"] = auth_code; + + LLHTTPClient::put(getFacebookConnectURL("/connection"), body, new FacebookConnectResponder(this)); +} + +void LLFacebookConnect::showFacebookFriends(const LLSD& friends) +{ + /* All that needs to be rewritten to + mFacebookFriends->clear(); + LLPersonTabModel::tab_type tab_type; + LLAvatarTracker& avatar_tracker = LLAvatarTracker::instance(); + + for (LLSD::map_const_iterator i = friends.beginMap(); i != friends.endMap(); ++i) + { + std::string name = i->second["name"].asString(); + LLUUID agent_id = i->second.has("agent_id") ? i->second["agent_id"].asUUID() : LLUUID(NULL); + + //add to avatar list + mFacebookFriends->addNewItem(agent_id, name, false); + + //FB+SL but not SL friend + if(agent_id.notNull() && !avatar_tracker.isBuddy(agent_id)) + { + tab_type = LLPersonTabModel::FB_SL_NON_SL_FRIEND; + } + //FB only friend + else + { + tab_type = LLPersonTabModel::FB_ONLY_FRIEND; + } + + //Add to person tab model + LLPersonTabModel * person_tab_model = dynamic_cast<LLPersonTabModel *>(mPersonFolderView->getPersonTabModelByIndex(tab_type)); + if(person_tab_model) + { + addParticipantToModel(person_tab_model, agent_id, name); + } + } + */ +} + + + + + + + + diff --git a/indra/newview/llfacebookconnect.h b/indra/newview/llfacebookconnect.h new file mode 100644 index 0000000000..d60fdacd90 --- /dev/null +++ b/indra/newview/llfacebookconnect.h @@ -0,0 +1,66 @@ +/** + * @file llfacebookconnect.h + * @author Merov, Cho, Gil + * @brief Connection to Facebook Service + * + * $LicenseInfo:firstyear=2013&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2013, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLFACEBOOKCONNECT_H +#define LL_LLFACEBOOKCONNECT_H + +#include "llsingleton.h" + +/** + * @class LLFacebookConnect + * + * Manages authentication to, and interaction with, a web service allowing the + * the viewer to get Facebook OpenGraph data. + */ +class LLFacebookConnect : public LLSingleton<LLFacebookConnect> +{ + LOG_CLASS(LLFacebookConnect); +public: + /* + * Performs initial setup, by requesting config data from the web service if + * it has not already been received. + */ + void init(); + + void loadFacebookFriends(); + void hideFacebookFriends(); + void connectToFacebook(const std::string& auth_code = ""); + void showFacebookFriends(const LLSD& friends); + + void setConnected(bool connected) { mConnectedToFbc = connected; } + +private: + + friend class LLSingleton<LLFacebookConnect>; + + LLFacebookConnect(); + ~LLFacebookConnect() {}; + + bool mConnectedToFbc; +}; + +#endif // LL_LLFACEBOOKCONNECT_H diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp index 9956888134..ce3ae48aca 100644 --- a/indra/newview/llpanelpeople.cpp +++ b/indra/newview/llpanelpeople.cpp @@ -1639,40 +1639,6 @@ void LLPanelPeople::openFacebookWeb(std::string url) LLUrlAction::openURLExternal(url); } -void LLPanelPeople::showFacebookFriends(const LLSD& friends) -{ - mFacebookFriends->clear(); - LLPersonTabModel::tab_type tab_type; - LLAvatarTracker& avatar_tracker = LLAvatarTracker::instance(); - - for (LLSD::map_const_iterator i = friends.beginMap(); i != friends.endMap(); ++i) - { - std::string name = i->second["name"].asString(); - LLUUID agent_id = i->second.has("agent_id") ? i->second["agent_id"].asUUID() : LLUUID(NULL); - - //add to avatar list - mFacebookFriends->addNewItem(agent_id, name, false); - - //FB+SL but not SL friend - if(agent_id.notNull() && !avatar_tracker.isBuddy(agent_id)) - { - tab_type = LLPersonTabModel::FB_SL_NON_SL_FRIEND; - } - //FB only friend - else - { - tab_type = LLPersonTabModel::FB_ONLY_FRIEND; - } - - //Add to person tab model - LLPersonTabModel * person_tab_model = dynamic_cast<LLPersonTabModel *>(mPersonFolderView->getPersonTabModelByIndex(tab_type)); - if(person_tab_model) - { - addParticipantToModel(person_tab_model, agent_id, name); - } - } -} - void LLPanelPeople::addTestParticipant() { std::string suffix("Aa"); @@ -1725,141 +1691,6 @@ void LLPanelPeople::addParticipantToModel(LLPersonTabModel * person_folder_model person_folder_model->addParticipant(person_model); } -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 - mPanelPeople->mConnectedToFbc = true; - mPanelPeople->loadFacebookFriends(); - } - else - { - llinfos << "failed to get response. reason: " << reason << " status: " << status << llendl; - } - } - - /*virtual*/ void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - mPanelPeople->openFacebookWeb(content["location"]); - } - } -}; - -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 - mPanelPeople->mConnectedToFbc = false; - mPanelPeople->hideFacebookFriends(); - } - else - { - llinfos << "failed to get response. reason: " << reason << " status: " << status << llendl; - } - } -}; - -class FacebookConnectedResponder : public LLHTTPClient::Responder -{ -public: - - LLPanelPeople * mPanelPeople; - bool mShowLoginIfNotConnected; - - FacebookConnectedResponder(LLPanelPeople * panel_people, bool show_login_if_not_connected) : mPanelPeople(panel_people), mShowLoginIfNotConnected(show_login_if_not_connected) {} - - /*virtual*/ void completed(U32 status, const std::string& reason, const LLSD& content) - { - if (isGoodStatus(status)) - { - llinfos << content << llendl; - - // grab some graph data if already connected - mPanelPeople->mConnectedToFbc = true; - mPanelPeople->loadFacebookFriends(); - } - else - { - llinfos << "failed to get response. reason: " << reason << " status: " << status << llendl; - - // show the facebook login page if not connected yet - if (status == 404 && mShowLoginIfNotConnected) - { - mPanelPeople->connectToFacebook(); - } - } - } -}; - -class FacebookFriendsResponder : public LLHTTPClient::Responder -{ -public: - - LLPanelPeople * mPanelPeople; - - FacebookFriendsResponder(LLPanelPeople * panel_people) : mPanelPeople(panel_people) {} - - /*virtual*/ void completed(U32 status, const std::string& reason, const LLSD& content) - { - if (isGoodStatus(status)) - { - llinfos << content << llendl; - - // display the list of friends - mPanelPeople->showFacebookFriends(content); - } - else - { - llinfos << "failed to get response. reason: " << reason << " status: " << status << llendl; - } - } - - /*virtual*/ void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - mPanelPeople->openFacebookWeb(content["location"]); - } - } -}; - -void LLPanelPeople::loadFacebookFriends() -{ - const bool follow_redirects=false; - const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; - LLHTTPClient::get(getFacebookConnectURL("/friend"), new FacebookFriendsResponder(this), - LLSD(), timeout, follow_redirects); -} - void LLPanelPeople::tryToReconnectToFacebook() { if (!mConnectedToFbc) @@ -1871,15 +1702,6 @@ void LLPanelPeople::tryToReconnectToFacebook() } } -void LLPanelPeople::connectToFacebook(const std::string& auth_code) -{ - LLSD body; - if (!auth_code.empty()) - body["code"] = auth_code; - - LLHTTPClient::put(getFacebookConnectURL("/connection"), body, new FacebookConnectResponder(this)); -} - void LLPanelPeople::disconnectFromFacebook() { LLHTTPClient::del(getFacebookConnectURL("/connection"), new FacebookDisconnectResponder(this)); diff --git a/indra/newview/llpanelpeople.h b/indra/newview/llpanelpeople.h index 943d84ac1d..fa354f7ecb 100644 --- a/indra/newview/llpanelpeople.h +++ b/indra/newview/llpanelpeople.h @@ -63,13 +63,9 @@ public: static void idle(void * user_data); void openFacebookWeb(std::string url); - void showFacebookFriends(const LLSD& friends); void addTestParticipant(); void addParticipantToModel(LLPersonTabModel * session_model, const LLUUID& agent_id, const std::string& name); - void hideFacebookFriends(); - void loadFacebookFriends(); void tryToReconnectToFacebook(); - void connectToFacebook(const std::string& auth_code = ""); void disconnectFromFacebook(); std::string getFacebookConnectURL(const std::string& route = ""); |