Fixed crash in UserInfoDialog if an invalid response is received (friend id

is not contained in the response --> profile not found --> crash. Now
the friend id is stored in the request itself, and not needed in the response
from the server). Moved RejectFriendRequest into UserInfoDialog.
This commit is contained in:
hiker
2014-03-15 11:54:04 +11:00
parent aa169d0191
commit 3f738b60d5
4 changed files with 68 additions and 66 deletions

View File

@@ -336,52 +336,6 @@ namespace Online
} // requestUserSearch
// ------------------------------------------------------------------------
/** 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
* declined.
*/
void CurrentUser::requestDeclineFriend(const uint32_t friend_id) const
{
assert(m_state == US_SIGNED_IN);
CurrentUser::DeclineFriendRequest * request =
new CurrentUser::DeclineFriendRequest();
request->setServerURL("client-user.php");
request->addParameter("action", "decline-friend-request");
request->addParameter("token", getToken());
request->addParameter("userid", getID());
request->addParameter("friendid", friend_id);
request->queue();
} // requestDeclineFriend
// ------------------------------------------------------------------------
/** Callback for the request to decline a friend invitation. Shows a
* confirmation message and takes care of updating all the cached
* information.
*/
void CurrentUser::DeclineFriendRequest::callback()
{
uint32_t id(0);
getXMLData()->get("friendid", &id);
core::stringw info_text("");
if(isSuccess())
{
CurrentUser::get()->getProfile()->removeFriend(id);
ProfileManager::get()->moveToCache(id);
ProfileManager::get()->getProfileByID(id)->deleteRelationalInfo();
OnlineProfileFriends::getInstance()->refreshFriendsList();
info_text = _("Friend request declined!");
}
else
info_text = getInfo();
GUIEngine::DialogQueue::get()->pushDialog(
new UserInfoDialog(id, info_text,!isSuccess(), true), true);
} // DeclineFriendRequest::callback
// ------------------------------------------------------------------------
/** A request to the server, to cancel a pending friend request.
* \param friend_id The id of the user of which the request has to be
* canceled.
*/
void CurrentUser::requestCancelFriend(const uint32_t friend_id) const
{
assert(m_state == US_SIGNED_IN);
@@ -428,7 +382,7 @@ namespace Online
{
assert(m_state == US_SIGNED_IN);
CurrentUser::RemoveFriendRequest * request =
new CurrentUser::RemoveFriendRequest();
new CurrentUser::RemoveFriendRequest(friend_id);
request->setServerURL("client-user.php");
request->addParameter("action", "remove-friend");
request->addParameter("token", getToken());
@@ -443,20 +397,18 @@ namespace Online
*/
void CurrentUser::RemoveFriendRequest::callback()
{
uint32_t id(0);
getXMLData()->get("friendid", &id);
core::stringw info_text("");
if(isSuccess())
{
CurrentUser::get()->getProfile()->removeFriend(id);
ProfileManager::get()->moveToCache(id);
ProfileManager::get()->getProfileByID(id)->deleteRelationalInfo();
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(id, info_text,!isSuccess(),
UserInfoDialog *info = new UserInfoDialog(m_id, info_text,!isSuccess(),
true);
GUIEngine::DialogQueue::get()->pushDialog(info, true);

View File

@@ -87,18 +87,13 @@ namespace Online
SetAddonVoteRequest() : XMLRequest() {}
}; // SetAddonVoteRequest
// ----------------------------------------------------------------
class DeclineFriendRequest : public XMLRequest {
virtual void callback ();
public:
DeclineFriendRequest() : XMLRequest(true) {}
}; // DeclineFriendRequest
// ----------------------------------------------------------------
class RemoveFriendRequest : public XMLRequest {
unsigned int m_id;
virtual void callback ();
public:
RemoveFriendRequest() : XMLRequest(true) {}
RemoveFriendRequest(unsigned int id)
: XMLRequest(true), m_id(id) {}
}; // RemoveFriendRequest
// ----------------------------------------------------------------
@@ -155,7 +150,6 @@ namespace Online
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 requestDeclineFriend(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,

View File

@@ -58,6 +58,11 @@ void UserInfoDialog::load()
void UserInfoDialog::beforeAddingWidgets()
{
m_profile = ProfileManager::get()->getProfileByID(m_showing_id);
// Avoid a crash in case that an invalid m_showing_id is given
// (which can only happen if there's a problem on the server).
if (!m_profile)
m_profile = CurrentUser::get()->getProfile();
m_self_destroy = false;
m_enter_profile = false;
m_processing = false;
@@ -174,7 +179,10 @@ void UserInfoDialog::sendFriendRequest()
} // sendFriendRequest
// -----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/** Sends an AcceptFriend request to the server. It will show a popup
* menu with the result once the request has been processed.
*/
void UserInfoDialog::acceptFriendRequest()
{
// ----------------------------------------------------------------
@@ -221,6 +229,55 @@ void UserInfoDialog::acceptFriendRequest()
m_options_widget->setDeactivated();
} // acceptFriendRequest
// -----------------------------------------------------------------------------
/** 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
* declined.
*/
void UserInfoDialog::declineFriendRequest()
{
// ----------------------------------------------------------------
class DeclineFriendRequest : public XMLRequest
{
/** A request to the server, to cancel a pending friend request.
* \param friend_id The id of the user of which the request has to be
* canceled.
*/
virtual void callback()
{
uint32_t id(0);
getXMLData()->get("friendid", &id);
core::stringw info_text("");
if (isSuccess())
{
CurrentUser::get()->getProfile()->removeFriend(id);
ProfileManager::get()->moveToCache(id);
ProfileManager::get()->getProfileByID(id)
->deleteRelationalInfo();
OnlineProfileFriends::getInstance()->refreshFriendsList();
info_text = _("Friend request declined!");
}
else
info_text = getInfo();
GUIEngine::DialogQueue::get()->pushDialog(
new UserInfoDialog(id, info_text, !isSuccess(),
true), true);
} // callback
public:
DeclineFriendRequest() : XMLRequest(true) {}
}; // DeclineFriendRequest
// ----------------------------------------------------------------
DeclineFriendRequest *request = new DeclineFriendRequest();
CurrentUser::setUserDetails(request);
request->addParameter("action", "decline-friend-request");
request->addParameter("friendid", m_profile->getID());
request->queue();
m_processing = true;
m_options_widget->setDeactivated();
} // declineFriendRequest
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& eventSource)
{
@@ -262,9 +319,7 @@ GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& even
}
else if(selection == m_decline_widget->m_properties[PROP_ID])
{
CurrentUser::get()->requestDeclineFriend(m_profile->getID());
m_processing = true;
m_options_widget->setDeactivated();
declineFriendRequest();
return GUIEngine::EVENT_BLOCK;
}
}

View File

@@ -62,6 +62,7 @@ private:
void deactivate();
void sendFriendRequest();
void acceptFriendRequest();
void declineFriendRequest();
public:
UserInfoDialog(uint32_t showing_id, const core::stringw info = "", bool error = false, bool from_queue = false);