From 853ad9d70ddcf0cdd354672a5c7baa858de1bb22 Mon Sep 17 00:00:00 2001 From: Cho Date: Wed, 3 Jul 2013 00:35:10 +0100 Subject: Implemented events for LLFacebookConnect state changes for ACME-662 --- indra/newview/llfacebookconnect.cpp | 53 +++++++++++++++---------------------- indra/newview/llfacebookconnect.h | 15 ++++++----- indra/newview/llfloatersocial.cpp | 4 +-- indra/newview/llpanelpeople.cpp | 26 +++++++++++++++--- indra/newview/llpanelpeople.h | 2 ++ 5 files changed, 58 insertions(+), 42 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llfacebookconnect.cpp b/indra/newview/llfacebookconnect.cpp index 5d6c496275..8a86ff6377 100644 --- a/indra/newview/llfacebookconnect.cpp +++ b/indra/newview/llfacebookconnect.cpp @@ -38,7 +38,9 @@ #include "llimagepng.h" #include "llimagejpeg.h" #include "lltrans.h" +#include "llevents.h" +boost::scoped_ptr LLFacebookConnect::sStateWatcher(new LLEventStream("FacebookConnectState")); // Local functions void log_facebook_connect_error(const std::string& request, U32 status, const std::string& reason, const std::string& code, const std::string& description) @@ -90,11 +92,6 @@ class LLFacebookConnectResponder : public LLHTTPClient::Responder public: LLFacebookConnectResponder() - { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); - } - - LLFacebookConnectResponder(LLFacebookConnect::connect_callback_t cb) : mConnectCallback(cb) { LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); } @@ -107,11 +104,6 @@ public: // Grab some graph data now that we are connected LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); - - if (mConnectCallback) - { - mConnectCallback(); - } } else { @@ -127,9 +119,6 @@ public: LLFacebookConnect::instance().openFacebookWeb(content["location"]); } } - -private: - LLFacebookConnect::connect_callback_t mConnectCallback; }; /////////////////////////////////////////////////////////////////////////////// @@ -208,11 +197,6 @@ public: LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); } - LLFacebookConnectedResponder(bool auto_connect, LLFacebookConnect::connect_callback_t cb) : mAutoConnect(auto_connect), mConnectCallback(cb) - { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); - } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) { if (isGoodStatus(status)) @@ -220,11 +204,6 @@ public: LL_DEBUGS("FacebookConnect") << "Connect successful. content: " << content << LL_ENDL; LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); - - if (mConnectCallback) - { - mConnectCallback(); - } } else { @@ -250,7 +229,6 @@ public: private: bool mAutoConnect; - LLFacebookConnect::connect_callback_t mConnectCallback; }; /////////////////////////////////////////////////////////////////////////////// @@ -306,13 +284,13 @@ std::string LLFacebookConnect::getFacebookConnectURL(const std::string& route) return url; } -void LLFacebookConnect::connectToFacebook(const std::string& auth_code, connect_callback_t cb) +void LLFacebookConnect::connectToFacebook(const std::string& auth_code) { LLSD body; if (!auth_code.empty()) body["code"] = auth_code; - LLHTTPClient::put(getFacebookConnectURL("/connection"), body, new LLFacebookConnectResponder(cb)); + LLHTTPClient::put(getFacebookConnectURL("/connection"), body, new LLFacebookConnectResponder()); } void LLFacebookConnect::disconnectFromFacebook() @@ -320,21 +298,21 @@ void LLFacebookConnect::disconnectFromFacebook() LLHTTPClient::del(getFacebookConnectURL("/connection"), new LLFacebookDisconnectResponder()); } -void LLFacebookConnect::getConnectionToFacebook(bool auto_connect, connect_callback_t cb) +void LLFacebookConnect::checkConnectionToFacebook(bool auto_connect) { if ((mConnectionState == FB_NOT_CONNECTED) || (mConnectionState == FB_CONNECTION_FAILED)) { const bool follow_redirects = false; - const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; - LLHTTPClient::get(getFacebookConnectURL("/connection"), new LLFacebookConnectedResponder(auto_connect, cb), + const F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + LLHTTPClient::get(getFacebookConnectURL("/connection"), new LLFacebookConnectedResponder(auto_connect), LLSD(), timeout, follow_redirects); } } void LLFacebookConnect::loadFacebookFriends() { - const bool follow_redirects=false; - const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; + const bool follow_redirects = false; + const F32 timeout = HTTP_REQUEST_EXPIRY_SECS; LLHTTPClient::get(getFacebookConnectURL("/friends"), new LLFacebookFriendsResponder(), LLSD(), timeout, follow_redirects); } @@ -451,6 +429,19 @@ void LLFacebookConnect::clearContent() mContent = LLSD(); } +void LLFacebookConnect::setConnectionState(LLFacebookConnect::EConnectionState connection_state) +{ + if (mConnectionState != connection_state) + { + LLSD state_info; + state_info["enum"] = connection_state; + sStateWatcher->post(state_info); + } + + mConnectionState = connection_state; +} + + diff --git a/indra/newview/llfacebookconnect.h b/indra/newview/llfacebookconnect.h index abd6fb385d..4e95fc3545 100644 --- a/indra/newview/llfacebookconnect.h +++ b/indra/newview/llfacebookconnect.h @@ -31,6 +31,8 @@ #include "llsingleton.h" #include "llimage.h" +class LLEventPump; + /** * @class LLFacebookConnect * @@ -49,13 +51,12 @@ public: FB_CONNECTION_FAILED = 3 }; - typedef boost::function connect_callback_t; typedef boost::function share_callback_t; typedef boost::function content_updated_callback_t; - void connectToFacebook(const std::string& auth_code = "", connect_callback_t cb = connect_callback_t()); // Initiate the complete FB connection. Please use getConnectionToFacebook() in normal use. - void disconnectFromFacebook(); // Disconnect from the FBC service. - void getConnectionToFacebook(bool auto_connect = false, connect_callback_t cb = connect_callback_t()); // Check if an access token is available on the FBC service. If not, call connectToFacebook(). + void connectToFacebook(const std::string& auth_code = ""); // Initiate the complete FB connection. Please use checkConnectionToFacebook() in normal use. + void disconnectFromFacebook(); // Disconnect from the FBC service. + void checkConnectionToFacebook(bool auto_connect = false); // Check if an access token is available on the FBC service. If not, call connectToFacebook(). void loadFacebookFriends(); void postCheckin(const std::string& location, const std::string& name, const std::string& description, const std::string& picture, const std::string& message); @@ -72,8 +73,8 @@ public: void storeContent(const LLSD& content); const LLSD& getContent() const; - void setConnectionState(EConnectionState connection_state) { mConnectionState = connection_state; } - bool isConnected() { return (mConnectionState == FB_CONNECTED); } + void setConnectionState(EConnectionState connection_state); + bool isConnected() { return (mConnectionState == FB_CONNECTED); } S32 generation() { return mGeneration; } void openFacebookWeb(std::string url); @@ -93,6 +94,8 @@ private: share_callback_t mSharePhotoCallback; share_callback_t mUpdateStatusCallback; content_updated_callback_t mContentUpdatedCallback; + + static boost::scoped_ptr sStateWatcher; }; #endif // LL_LLFACEBOOKCONNECT_H diff --git a/indra/newview/llfloatersocial.cpp b/indra/newview/llfloatersocial.cpp index 4660644969..50d641865b 100644 --- a/indra/newview/llfloatersocial.cpp +++ b/indra/newview/llfloatersocial.cpp @@ -536,8 +536,8 @@ void LLFloaterSocial::onCancel() BOOL LLFloaterSocial::postBuild() { - // Initiate a connection to Facebook (getConnectionToFacebook() handles the already connected state) - LLFacebookConnect::instance().getConnectionToFacebook(true); + // Initiate a connection to Facebook + LLFacebookConnect::instance().checkConnectionToFacebook(true); // Keep tab of the Photo Panel mSocialPhotoPanel = static_cast(getChild("panel_social_photo")); return LLFloater::postBuild(); diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp index bd4813f945..8c8cad0743 100755 --- a/indra/newview/llpanelpeople.cpp +++ b/indra/newview/llpanelpeople.cpp @@ -839,16 +839,36 @@ void LLPanelPeople::updateRecentList() mRecentList->setDirty(); } +bool LLPanelPeople::onConnectedToFacebook(const LLSD& data) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLPanelPeople"); + + LLFacebookConnect::instance().loadFacebookFriends(); + } + + return false; +} + void LLPanelPeople::updateFacebookList(bool visible) { - if(visible) + if (visible) { LLFacebookConnect::instance().setContentUpdatedCallback(boost::bind(&LLPanelPeople::updateSuggestedFriendList, this)); if (mTryToConnectToFbc) - { + { // try to reconnect to facebook! - LLFacebookConnect::instance().getConnectionToFacebook(false, boost::bind(&LLFacebookConnect::loadFacebookFriends, &LLFacebookConnect::instance())); + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().loadFacebookFriends(); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLPanelPeople", boost::bind(&LLPanelPeople::onConnectedToFacebook, this, _1)); + LLFacebookConnect::instance().checkConnectionToFacebook(); + } // don't try again mTryToConnectToFbc = false; diff --git a/indra/newview/llpanelpeople.h b/indra/newview/llpanelpeople.h index 666702a08c..c6ee7b8165 100755 --- a/indra/newview/llpanelpeople.h +++ b/indra/newview/llpanelpeople.h @@ -126,6 +126,8 @@ private: void onFriendListRefreshComplete(LLUICtrl*ctrl, const LLSD& param); + bool onConnectedToFacebook(const LLSD& data); + void setAccordionCollapsedByUser(LLUICtrl* acc_tab, bool collapsed); void setAccordionCollapsedByUser(const std::string& name, bool collapsed); bool isAccordionCollapsedByUser(LLUICtrl* acc_tab); -- cgit v1.2.3 From eef8579dd7f9af558041d4d3a4b4aeb39bf280a1 Mon Sep 17 00:00:00 2001 From: Cho Date: Wed, 3 Jul 2013 01:16:41 +0100 Subject: Moved auto-connect to happen when Post button is clicked for ACME-654 and ACME-652 --- indra/newview/llfloatersocial.cpp | 84 +++++++++++++++++++++++++++++++++------ indra/newview/llfloatersocial.h | 60 ++++++++++++++-------------- 2 files changed, 103 insertions(+), 41 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llfloatersocial.cpp b/indra/newview/llfloatersocial.cpp index 50d641865b..061bcf246d 100644 --- a/indra/newview/llfloatersocial.cpp +++ b/indra/newview/llfloatersocial.cpp @@ -88,7 +88,7 @@ void LLSocialStatusPanel::draw() if (mMessageTextEditor && mPostStatusButton) { std::string message = mMessageTextEditor->getValue().asString(); - mPostStatusButton->setEnabled(!message.empty() && LLFacebookConnect::instance().isConnected()); + mPostStatusButton->setEnabled(!message.empty()); } LLPanel::draw(); @@ -101,8 +101,18 @@ void LLSocialStatusPanel::onSend() std::string message = mMessageTextEditor->getValue().asString(); if (!message.empty()) { - LLFacebookConnect::instance().updateStatus(message); - + // Connect to Facebook if necessary and then post + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().updateStatus(message); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLSocialStatusPanel", boost::bind(&LLSocialStatusPanel::onConnectedToFacebook, this, _1, message)); + LLFacebookConnect::instance().checkConnectionToFacebook(true); + } + + // Close the floater once "Post" has been pushed LLFloater* floater = getParentByType(); if (floater) { @@ -112,6 +122,18 @@ void LLSocialStatusPanel::onSend() } } +bool LLSocialStatusPanel::onConnectedToFacebook(const LLSD& data, const std::string& message) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLSocialStatusPanel"); + + LLFacebookConnect::instance().updateStatus(message); + } + + return false; +} + /////////////////////////// //LLSocialPhotoPanel/////// /////////////////////////// @@ -233,8 +255,6 @@ void LLSocialPhotoPanel::draw() mThumbnailPlaceholder->draw(); gGL.popUIMatrix(); } - - mPostButton->setEnabled(LLFacebookConnect::instance().isConnected()); } LLSnapshotLivePreview* LLSocialPhotoPanel::getPreviewView() @@ -302,7 +322,18 @@ void LLSocialPhotoPanel::onSend() } LLSnapshotLivePreview* previewp = getPreviewView(); - LLFacebookConnect::instance().sharePhoto(previewp->getFormattedImage(), caption); + + // Connect to Facebook if necessary and then post + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().sharePhoto(previewp->getFormattedImage(), caption); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLSocialPhotoPanel", boost::bind(&LLSocialPhotoPanel::onConnectedToFacebook, this, _1, previewp->getFormattedImage(), caption)); + LLFacebookConnect::instance().checkConnectionToFacebook(true); + } + updateControls(); // Close the floater once "Post" has been pushed @@ -313,6 +344,18 @@ void LLSocialPhotoPanel::onSend() } } +bool LLSocialPhotoPanel::onConnectedToFacebook(const LLSD& data, LLPointer image, const std::string& caption) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLSocialPhotoPanel"); + + LLFacebookConnect::instance().sharePhoto(image, caption); + } + + return false; +} + void LLSocialPhotoPanel::updateControls() { LLSnapshotLivePreview* previewp = getPreviewView(); @@ -482,8 +525,7 @@ void LLSocialCheckinPanel::draw() mMapCheckBox->setEnabled(true); mMapCheckBox->set(mMapCheckBoxValue); } - mPostButton->setEnabled(LLFacebookConnect::instance().isConnected()); - + LLPanel::draw(); } @@ -508,8 +550,16 @@ void LLSocialCheckinPanel::onSend() // Get the caption std::string caption = getChild("place_caption")->getValue().asString(); - // Post all that to Facebook - LLFacebookConnect::instance().postCheckin(slurl_string, region_name, description, map_url, caption); + // Connect to Facebook if necessary and then post + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().postCheckin(slurl_string, region_name, description, map_url, caption); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLSocialCheckinPanel", boost::bind(&LLSocialCheckinPanel::onConnectedToFacebook, this, _1, slurl_string, region_name, description, map_url, caption)); + LLFacebookConnect::instance().checkConnectionToFacebook(true); + } // Close the floater once "Post" has been pushed LLFloater* floater = getParentByType(); @@ -519,6 +569,18 @@ void LLSocialCheckinPanel::onSend() } } +bool LLSocialCheckinPanel::onConnectedToFacebook(const LLSD& data, const std::string& location, const std::string& name, const std::string& description, const std::string& picture, const std::string& message) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLSocialCheckinPanel"); + + LLFacebookConnect::instance().postCheckin(location, name, description, picture, message); + } + + return false; +} + //////////////////////// //LLFloaterSocial/////// //////////////////////// @@ -536,8 +598,6 @@ void LLFloaterSocial::onCancel() BOOL LLFloaterSocial::postBuild() { - // Initiate a connection to Facebook - LLFacebookConnect::instance().checkConnectionToFacebook(true); // Keep tab of the Photo Panel mSocialPhotoPanel = static_cast(getChild("panel_social_photo")); return LLFloater::postBuild(); diff --git a/indra/newview/llfloatersocial.h b/indra/newview/llfloatersocial.h index 89b9e2016a..4970f95e89 100644 --- a/indra/newview/llfloatersocial.h +++ b/indra/newview/llfloatersocial.h @@ -41,6 +41,7 @@ public: BOOL postBuild(); void draw(); void onSend(); + bool onConnectedToFacebook(const LLSD& data, const std::string& message); private: LLUICtrl* mMessageTextEditor; @@ -49,41 +50,40 @@ private: class LLSocialPhotoPanel : public LLPanel { - public: - LLSocialPhotoPanel(); - ~LLSocialPhotoPanel(); + LLSocialPhotoPanel(); + ~LLSocialPhotoPanel(); - BOOL postBuild(); - void draw(); + BOOL postBuild(); + void draw(); - LLSnapshotLivePreview* getPreviewView(); - void onVisibilityChange(const LLSD& new_visibility); - void onClickNewSnapshot(); - void onSend(); + LLSnapshotLivePreview* getPreviewView(); + void onVisibilityChange(const LLSD& new_visibility); + void onClickNewSnapshot(); + void onSend(); + bool onConnectedToFacebook(const LLSD& data, LLPointer image, const std::string& caption); - void updateControls(); - void updateResolution(BOOL do_update); - void checkAspectRatio(S32 index); - void setNeedRefresh(bool need); - LLUICtrl* getRefreshBtn(); + void updateControls(); + void updateResolution(BOOL do_update); + void checkAspectRatio(S32 index); + void setNeedRefresh(bool need); + LLUICtrl* getRefreshBtn(); private: - - LLHandle mPreviewHandle; - - LLUICtrl * mSnapshotPanel; - LLUICtrl * mResolutionComboBox; - LLUICtrl * mRefreshBtn; - LLUICtrl * mRefreshLabel; - LLUICtrl * mSucceessLblPanel; - LLUICtrl * mFailureLblPanel; - LLUICtrl * mThumbnailPlaceholder; - LLUICtrl * mCaptionTextBox; - LLUICtrl * mLocationCheckbox; - LLUICtrl * mPostButton; - - bool mNeedRefresh; + LLHandle mPreviewHandle; + + LLUICtrl * mSnapshotPanel; + LLUICtrl * mResolutionComboBox; + LLUICtrl * mRefreshBtn; + LLUICtrl * mRefreshLabel; + LLUICtrl * mSucceessLblPanel; + LLUICtrl * mFailureLblPanel; + LLUICtrl * mThumbnailPlaceholder; + LLUICtrl * mCaptionTextBox; + LLUICtrl * mLocationCheckbox; + LLUICtrl * mPostButton; + + bool mNeedRefresh; }; class LLSocialCheckinPanel : public LLPanel @@ -93,6 +93,8 @@ public: BOOL postBuild(); void draw(); void onSend(); + bool onConnectedToFacebook(const LLSD& data, const std::string& location, const std::string& name, const std::string& description, const std::string& picture, const std::string& message); + private: std::string mMapUrl; LLPointer mMapTexture; -- cgit v1.2.3 From b070533bdaa78fb2d94ec49a2ea3d9a9ada3d437 Mon Sep 17 00:00:00 2001 From: Cho Date: Wed, 3 Jul 2013 01:38:30 +0100 Subject: added FB_POSTING and PB_POST_FAILED states to LLFacebookConnect for ACME-663 --- indra/newview/llfacebookconnect.cpp | 16 +++++++++++++--- indra/newview/llfacebookconnect.h | 6 ++++-- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llfacebookconnect.cpp b/indra/newview/llfacebookconnect.cpp index 8a86ff6377..30fb63084b 100644 --- a/indra/newview/llfacebookconnect.cpp +++ b/indra/newview/llfacebookconnect.cpp @@ -128,8 +128,15 @@ class LLFacebookShareResponder : public LLHTTPClient::Responder LOG_CLASS(LLFacebookShareResponder); public: - LLFacebookShareResponder() {} - LLFacebookShareResponder(LLFacebookConnect::share_callback_t cb) : mShareCallback(cb) {} + LLFacebookShareResponder() + { + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POSTING); + } + + LLFacebookShareResponder(LLFacebookConnect::share_callback_t cb) : mShareCallback(cb) + { + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POSTING); + } virtual void completed(U32 status, const std::string& reason, const LLSD& content) { @@ -137,9 +144,12 @@ public: { toast_user_for_success(); LL_DEBUGS("FacebookConnect") << "Post successful. content: " << content << LL_ENDL; + + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); } else { + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POST_FAILED); log_facebook_connect_error("Share", status, reason, content.get("error_code"), content.get("error_description")); } @@ -300,7 +310,7 @@ void LLFacebookConnect::disconnectFromFacebook() void LLFacebookConnect::checkConnectionToFacebook(bool auto_connect) { - if ((mConnectionState == FB_NOT_CONNECTED) || (mConnectionState == FB_CONNECTION_FAILED)) + if ((mConnectionState == FB_NOT_CONNECTED) || (mConnectionState == FB_CONNECTION_FAILED) || (mConnectionState == FB_POST_FAILED)) { const bool follow_redirects = false; const F32 timeout = HTTP_REQUEST_EXPIRY_SECS; diff --git a/indra/newview/llfacebookconnect.h b/indra/newview/llfacebookconnect.h index 4e95fc3545..7d6bca5a25 100644 --- a/indra/newview/llfacebookconnect.h +++ b/indra/newview/llfacebookconnect.h @@ -48,7 +48,9 @@ public: FB_NOT_CONNECTED = 0, FB_CONNECTION_IN_PROGRESS = 1, FB_CONNECTED = 2, - FB_CONNECTION_FAILED = 3 + FB_CONNECTION_FAILED = 3, + FB_POSTING = 4, + FB_POST_FAILED = 5 }; typedef boost::function share_callback_t; @@ -74,7 +76,7 @@ public: const LLSD& getContent() const; void setConnectionState(EConnectionState connection_state); - bool isConnected() { return (mConnectionState == FB_CONNECTED); } + bool isConnected() { return ((mConnectionState == FB_CONNECTED) || (mConnectionState == FB_POSTING)); } S32 generation() { return mGeneration; } void openFacebookWeb(std::string url); -- cgit v1.2.3