From f76536ca3174e4d50b28c00202980288436663ee Mon Sep 17 00:00:00 2001 From: hiker Date: Sat, 15 Mar 2014 10:13:44 +1100 Subject: [PATCH] Moved FriendRequest into corresponding GUI object. --- src/online/current_user.cpp | 44 +-------------- src/online/current_user.hpp | 7 --- .../dialogs/user_info_dialog.cpp | 55 ++++++++++++++++++- .../dialogs/user_info_dialog.hpp | 1 + 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp index 043fb8ff8..a7b698926 100644 --- a/src/online/current_user.cpp +++ b/src/online/current_user.cpp @@ -30,10 +30,10 @@ #include "online/profile_manager.hpp" #include "online/servers_manager.hpp" #include "states_screens/login_screen.hpp" +#include "states_screens/online_profile_friends.hpp" #include "states_screens/dialogs/change_password_dialog.hpp" #include "states_screens/dialogs/user_info_dialog.hpp" #include "states_screens/dialogs/notification_dialog.hpp" -#include "states_screens/online_profile_friends.hpp" #include "utils/log.hpp" #include "utils/translation.hpp" @@ -335,48 +335,6 @@ namespace Online return request; } // requestUserSearch - // ------------------------------------------------------------------------ - /** A request to the server, to invite a user to be friends. - * \param friend_id The id of the user which has to be friended. - */ - void CurrentUser::requestFriendRequest(const uint32_t friend_id) const - { - assert(m_state == US_SIGNED_IN); - CurrentUser::FriendRequest * request = new CurrentUser::FriendRequest(); - request->setServerURL("client-user.php"); - request->addParameter("action", "friend-request"); - request->addParameter("token", getToken()); - request->addParameter("userid", getID()); - request->addParameter("friendid", friend_id); - request->queue(); - } // requestFriendRequest - - // ------------------------------------------------------------------------ - /** Callback for the request to send a friend invitation. Shows a - * confirmation message and takes care of updating all the cached - * information. - */ - void CurrentUser::FriendRequest::callback() - { - uint32_t id(0); - getXMLData()->get("friendid", &id); - core::stringw info_text(""); - if(isSuccess()) - { - CurrentUser::get()->getProfile()->addFriend(id); - OnlineProfile::RelationInfo *info = - new OnlineProfile::RelationInfo(_("Today"), false, true, false); - ProfileManager::get()->getProfileByID(id)->setRelationInfo(info); - OnlineProfileFriends::getInstance()->refreshFriendsList(); - info_text = _("Friend request send!"); - } - else - info_text = getInfo(); - UserInfoDialog *dialog = new UserInfoDialog(id, info_text, - !isSuccess(), true); - GUIEngine::DialogQueue::get()->pushDialog(dialog, true); - } // FriendRequest::callback - // ------------------------------------------------------------------------ /** 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 diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp index 292d6a30d..1fdf524af 100644 --- a/src/online/current_user.hpp +++ b/src/online/current_user.hpp @@ -87,13 +87,6 @@ namespace Online SetAddonVoteRequest() : XMLRequest() {} }; // SetAddonVoteRequest - // ---------------------------------------------------------------- - class FriendRequest : public XMLRequest { - virtual void callback (); - public: - FriendRequest() : XMLRequest(true) {} - }; // FriendRequest - // ---------------------------------------------------------------- class AcceptFriendRequest : 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 696738509..f10422cf8 100644 --- a/src/states_screens/dialogs/user_info_dialog.cpp +++ b/src/states_screens/dialogs/user_info_dialog.cpp @@ -18,9 +18,11 @@ #include "states_screens/dialogs/user_info_dialog.hpp" #include "audio/sfx_manager.hpp" +#include "guiengine/dialog_queue.hpp" #include "guiengine/engine.hpp" #include "online/online_profile.hpp" #include "online/messages.hpp" +#include "states_screens/online_profile_friends.hpp" #include "states_screens/online_profile_overview.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" @@ -120,6 +122,55 @@ UserInfoDialog::~UserInfoDialog() { } +// ----------------------------------------------------------------------------- +void UserInfoDialog::sendFriendRequest() +{ + class FriendRequest : public XMLRequest + { + // ------------------------------------------------------------------------ + /** Callback for the request to send 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()) + { + CurrentUser::get()->getProfile()->addFriend(id); + OnlineProfile::RelationInfo *info = + new OnlineProfile::RelationInfo(_("Today"), false, + true, false); + ProfileManager::get()->getProfileByID(id)->setRelationInfo(info); + OnlineProfileFriends::getInstance()->refreshFriendsList(); + info_text = _("Friend request send!"); + } + else + info_text = getInfo(); + UserInfoDialog *dialog = new UserInfoDialog(id, info_text, + !isSuccess(), true); + GUIEngine::DialogQueue::get()->pushDialog(dialog, true); + + } // callback + public: + FriendRequest() : XMLRequest(true) {} + }; // FriendRequest + + // ------------------------------------------------------------------------ + + FriendRequest *request = new FriendRequest(); + CurrentUser::setUserDetails(request); + request->addParameter("action", "friend-request"); + request->addParameter("friendid", m_profile->getID()); + request->queue(); + + m_processing = true; + m_options_widget->setDeactivated(); + +} // sendFriendRequest + // ----------------------------------------------------------------------------- GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& eventSource) { @@ -141,9 +192,7 @@ GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& even } else if(selection == m_friend_widget->m_properties[PROP_ID]) { - CurrentUser::get()->requestFriendRequest(m_profile->getID()); - m_processing = true; - m_options_widget->setDeactivated(); + sendFriendRequest(); return GUIEngine::EVENT_BLOCK; } else if(selection == m_remove_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 d231b2157..ac519b21a 100644 --- a/src/states_screens/dialogs/user_info_dialog.hpp +++ b/src/states_screens/dialogs/user_info_dialog.hpp @@ -60,6 +60,7 @@ private: void requestJoin(); void activate(); void deactivate(); + void sendFriendRequest(); public: UserInfoDialog(uint32_t showing_id, const core::stringw info = "", bool error = false, bool from_queue = false);