diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp index a7b698926..1ff349baa 100644 --- a/src/online/current_user.cpp +++ b/src/online/current_user.cpp @@ -335,50 +335,6 @@ namespace Online return request; } // requestUserSearch - // ------------------------------------------------------------------------ - /** A request to the server, to accept a friend request. - * \param friend_id The id of the user of which the request has to be - * accepted. - */ - void CurrentUser::requestAcceptFriend(const uint32_t friend_id) const - { - assert(m_state == US_SIGNED_IN); - CurrentUser::AcceptFriendRequest * request = - new CurrentUser::AcceptFriendRequest(); - request->setServerURL("client-user.php"); - request->addParameter("action", "accept-friend-request"); - request->addParameter("token", getToken()); - request->addParameter("userid", getID()); - request->addParameter("friendid", friend_id); - request->queue(); - } // requestAcceptFriend - - // ------------------------------------------------------------------------ - /** Callback for the request to accept a friend invitation. Shows a - * confirmation message and takes care of updating all the cached - * information. - */ - void CurrentUser::AcceptFriendRequest::callback() - { - uint32_t id(0); - getXMLData()->get("friendid", &id); - core::stringw info_text(""); - if(isSuccess()) - { - OnlineProfile * profile = ProfileManager::get()->getProfileByID(id); - profile->setFriend(); - OnlineProfile::RelationInfo *info = - new OnlineProfile::RelationInfo(_("Today"), false, false, true); - profile->setRelationInfo(info); - OnlineProfileFriends::getInstance()->refreshFriendsList(); - info_text = _("Friend request accepted!"); - } - else - info_text = getInfo(); - GUIEngine::DialogQueue::get()->pushDialog( - new UserInfoDialog(id, info_text,!isSuccess(), true), true); - } // AcceptFriendRequest::callback - // ------------------------------------------------------------------------ /** A request to the server, to decline a friend request. * \param friend_id The id of the user of which the request has to be diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp index 1fdf524af..b23df18cf 100644 --- a/src/online/current_user.hpp +++ b/src/online/current_user.hpp @@ -87,13 +87,6 @@ namespace Online SetAddonVoteRequest() : XMLRequest() {} }; // SetAddonVoteRequest - // ---------------------------------------------------------------- - class AcceptFriendRequest : public XMLRequest { - virtual void callback (); - public: - AcceptFriendRequest() : XMLRequest(true) {} - }; // AcceptFriendRequest - // ---------------------------------------------------------------- class DeclineFriendRequest : public XMLRequest { virtual void callback (); diff --git a/src/states_screens/dialogs/user_info_dialog.cpp b/src/states_screens/dialogs/user_info_dialog.cpp index f10422cf8..e8545a5e1 100644 --- a/src/states_screens/dialogs/user_info_dialog.cpp +++ b/src/states_screens/dialogs/user_info_dialog.cpp @@ -123,6 +123,9 @@ UserInfoDialog::~UserInfoDialog() } // ----------------------------------------------------------------------------- +/** Sends a friend request to the server. When the request is finished, it + * show a dialog with the result of this request. + */ void UserInfoDialog::sendFriendRequest() { class FriendRequest : public XMLRequest @@ -171,6 +174,53 @@ void UserInfoDialog::sendFriendRequest() } // sendFriendRequest +// ----------------------------------------------------------------------------- +void UserInfoDialog::acceptFriendRequest() +{ + // ---------------------------------------------------------------- + class AcceptFriendRequest : public XMLRequest + { + /** Callback for the request to accept a friend invitation. Shows a + * confirmation message and takes care of updating all the cached + * information. + */ + virtual void callback() + { + uint32_t id(0); + getXMLData()->get("friendid", &id); + core::stringw info_text(""); + if (isSuccess()) + { + OnlineProfile * profile = + ProfileManager::get()->getProfileByID(id); + profile->setFriend(); + OnlineProfile::RelationInfo *info = + new OnlineProfile::RelationInfo(_("Today"), false, + false, true); + profile->setRelationInfo(info); + OnlineProfileFriends::getInstance()->refreshFriendsList(); + info_text = _("Friend request accepted!"); + } + else + info_text = getInfo(); + GUIEngine::DialogQueue::get()->pushDialog( + new UserInfoDialog(id, info_text, !isSuccess(), true), true); + + } // callback + public: + AcceptFriendRequest() : XMLRequest(true) {} + }; // AcceptFriendRequest + // ------------------------------------------------------------------------ + + AcceptFriendRequest *request = new AcceptFriendRequest(); + CurrentUser::setUserDetails(request); + request->addParameter("action", "accept-friend-request"); + request->addParameter("friendid", m_profile->getID()); + request->queue(); + m_processing = true; + m_options_widget->setDeactivated(); +} // acceptFriendRequest + // ----------------------------------------------------------------------------- GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& eventSource) { @@ -207,9 +257,7 @@ GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& even } else if(selection == m_accept_widget->m_properties[PROP_ID]) { - CurrentUser::get()->requestAcceptFriend(m_profile->getID()); - m_processing = true; - m_options_widget->setDeactivated(); + acceptFriendRequest(); return GUIEngine::EVENT_BLOCK; } else if(selection == m_decline_widget->m_properties[PROP_ID]) diff --git a/src/states_screens/dialogs/user_info_dialog.hpp b/src/states_screens/dialogs/user_info_dialog.hpp index ac519b21a..253806b26 100644 --- a/src/states_screens/dialogs/user_info_dialog.hpp +++ b/src/states_screens/dialogs/user_info_dialog.hpp @@ -61,6 +61,7 @@ private: void activate(); void deactivate(); void sendFriendRequest(); + void acceptFriendRequest(); public: UserInfoDialog(uint32_t showing_id, const core::stringw info = "", bool error = false, bool from_queue = false);