Moved FriendRequest into corresponding GUI object.

This commit is contained in:
hiker 2014-03-15 10:13:44 +11:00
parent e63ad2754d
commit f76536ca31
4 changed files with 54 additions and 53 deletions

View File

@ -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

View File

@ -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 ();

View File

@ -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])

View File

@ -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);