Moved 'removeFriendRequest' into UserInfoDialog.

This commit is contained in:
hiker 2014-04-03 16:58:38 +11:00
parent afa2e2e98d
commit d9267a937a
3 changed files with 36 additions and 52 deletions

View File

@ -374,46 +374,6 @@ namespace Online
GUIEngine::DialogQueue::get()->pushDialog(dia, true);
} // CancelFriendRequest::callback
// ------------------------------------------------------------------------
/** A request to the server, to remove a friend relation.
* \param friend_id The id of the friend to be removed.
*/
void CurrentUser::requestRemoveFriend(const uint32_t friend_id) const
{
assert(m_state == US_SIGNED_IN);
CurrentUser::RemoveFriendRequest * request =
new CurrentUser::RemoveFriendRequest(friend_id);
request->setServerURL("client-user.php");
request->addParameter("action", "remove-friend");
request->addParameter("token", getToken());
request->addParameter("userid", getID());
request->addParameter("friendid", friend_id);
request->queue();
} // requestRemoveFriend
// ------------------------------------------------------------------------
/** Callback for the request to remove a friend. Shows a confirmation
* message and takes care of updating all the cached information.
*/
void CurrentUser::RemoveFriendRequest::callback()
{
core::stringw info_text("");
if(isSuccess())
{
CurrentUser::get()->getProfile()->removeFriend(m_id);
ProfileManager::get()->moveToCache(m_id);
ProfileManager::get()->getProfileByID(m_id)->deleteRelationalInfo();
OnlineProfileFriends::getInstance()->refreshFriendsList();
info_text = _("Friend removed!");
}
else
info_text = getInfo();
UserInfoDialog *info = new UserInfoDialog(m_id, info_text,!isSuccess(),
true);
GUIEngine::DialogQueue::get()->pushDialog(info, true);
} // RemoveFriendRequest::callback
// ------------------------------------------------------------------------
/** A request to the server, to change the password of the signed in user.
* \param current_password The active password of the currently signed in

View File

@ -87,15 +87,6 @@ namespace Online
SetAddonVoteRequest() : XMLRequest() {}
}; // SetAddonVoteRequest
// ----------------------------------------------------------------
class RemoveFriendRequest : public XMLRequest {
unsigned int m_id;
virtual void callback ();
public:
RemoveFriendRequest(unsigned int id)
: XMLRequest(true), m_id(id) {}
}; // RemoveFriendRequest
// ----------------------------------------------------------------
class CancelFriendRequest : public XMLRequest {
virtual void callback ();
@ -149,8 +140,6 @@ namespace Online
const XMLRequest * requestGetAddonVote(const std::string & addon_id) const;
const SetAddonVoteRequest * requestSetAddonVote(const std::string & addon_id, float rating) const;
void requestFriendRequest(const uint32_t friend_id) const;
void requestAcceptFriend(const uint32_t friend_id) const;
void requestRemoveFriend(const uint32_t friend_id) const;
void requestCancelFriend(const uint32_t friend_id) const;
void requestPasswordChange( const irr::core::stringw &current_password,
const irr::core::stringw &new_password,

View File

@ -283,8 +283,43 @@ void UserInfoDialog::declineFriendRequest()
*/
void UserInfoDialog::removeExistingFriend()
{
CurrentUser::get()->requestRemoveFriend(m_profile->getID());
/** An inline class for the remove friend request. */
class RemoveFriendRequest : public XMLRequest
{
unsigned int m_id;
virtual void callback()
{
core::stringw info_text("");
if (isSuccess())
{
CurrentUser::get()->getProfile()->removeFriend(m_id);
ProfileManager *pm = ProfileManager::get();
pm->moveToCache(m_id);
pm->getProfileByID(m_id)->deleteRelationalInfo();
OnlineProfileFriends::getInstance()->refreshFriendsList();
info_text = _("Friend removed!");
}
else
info_text = getInfo();
UserInfoDialog *info = new UserInfoDialog(m_id, info_text,
!isSuccess(), true);
GUIEngine::DialogQueue::get()->pushDialog(info, true);
} // callback
// --------------------------------------------------------------------
public:
RemoveFriendRequest(unsigned int id)
: XMLRequest(true), m_id(id) {}
}; // RemoveFriendRequest
// ------------------------------------------------------------------------
int friend_id = m_profile->getID();
RemoveFriendRequest * request = new RemoveFriendRequest(friend_id);
CurrentUser::get()->setUserDetails(request);
request->addParameter("action", "remove-friend");
request->addParameter("friendid", friend_id);
request->queue();
} // removeExistingFriend
// -----------------------------------------------------------------------------