Client core for relationship info.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13493 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-08-17 20:22:55 +00:00
parent 05a495810e
commit f0cf45b9b4
6 changed files with 86 additions and 21 deletions

View File

@ -22,6 +22,7 @@
#include "addons/addons_manager.hpp"
#include "config/user_config.hpp"
#include "online/servers_manager.hpp"
#include "online/profile_manager.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "addons/addon.hpp"
@ -148,6 +149,7 @@ namespace Online{
UserConfigParams::m_saved_token = getToken();
UserConfigParams::m_saved_session = true;
}
ProfileManager::get()->addToCache(new Profile(CurrentUser::get()->getUserID(), CurrentUser::get()->getUserName()));
}
else
setUserState (US_SIGNED_OUT);

View File

@ -35,9 +35,20 @@ using namespace Online;
namespace Online{
Profile::RelationInfo::RelationInfo(const irr::core::stringw & date, bool is_online, bool is_pending, bool is_asker)
{
m_date = date;
Log::info("date","%s",m_date.c_str());
m_is_online = is_online;
m_is_pending = is_pending;
m_is_asker = is_asker;
}
// ============================================================================
Profile::Profile( const uint32_t & userid,
const irr::core::stringw & username)
Profile::Profile( const uint32_t & userid,
const irr::core::stringw & username)
{
setState (S_READY);
m_cache_bit = true;
@ -45,6 +56,43 @@ namespace Online{
m_is_current_user = (m_id == CurrentUser::get()->getUserID());
m_username = username;
m_has_fetched_friends = false;
m_relation_info = NULL;
}
Profile::Profile(const XMLNode * xml, ConstructorType type)
{
m_relation_info = NULL;
if(type == C_RELATION_INFO){
std::string is_online_string("");
xml->get("online", &is_online_string);
bool is_online = is_online_string == "yes";
irr::core::stringw date("");
xml->get("date", &date);
std::string is_pending_string("");
xml->get("is_pending", &is_pending_string);
bool is_pending = is_pending_string == "yes";
bool is_asker(false);
if(is_pending)
{
std::string is_asker_string("");
xml->get("is_asker", &is_asker_string);
is_asker = is_asker_string == "yes";
}
m_relation_info = new RelationInfo(date, is_online, is_pending, is_asker);
xml = xml->getNode("user");
}
xml->get("id", &m_id);
xml->get("user_name", &m_username);
m_cache_bit = true;
m_has_fetched_friends = false;
m_is_current_user = (m_id == CurrentUser::get()->getUserID());
setState (S_READY);
}
// ============================================================================
Profile::~Profile()
{
delete m_relation_info;
}
// ============================================================================
@ -63,17 +111,11 @@ namespace Online{
{
const XMLNode * friends_xml = input->getNode("friends");
m_friends.clear();
uint32_t friend_id(0);
irr::core::stringw friend_username("");
for (unsigned int i = 0; i < friends_xml->getNumNodes(); i++)
{
friends_xml->getNode(i)->get("friend_id", &friend_id);
friends_xml->getNode(i)->get("friend_name", &friend_username);
ProfileManager::get()->addToCache(
new Profile(friend_id, friend_username)
);
m_friends.push_back(friend_id);
Profile * profile = new Profile(friends_xml->getNode(i), (m_is_current_user ? C_RELATION_INFO : C_DEFAULT));
m_friends.push_back(profile->getID());
ProfileManager::get()->addToCache(profile);
}
m_has_fetched_friends = true;
Profile::setState (Profile::S_READY);

View File

@ -41,6 +41,26 @@ namespace Online{
class Profile
{
public :
enum ConstructorType
{
C_DEFAULT = 1,
C_RELATION_INFO
};
class RelationInfo
{
private:
bool m_is_online;
bool m_is_pending;
bool m_is_asker;
irr::core::stringw m_date;
public:
RelationInfo(const irr::core::stringw & date, bool is_online, bool is_pending, bool is_asker = false);
bool isPending(){return m_is_pending;}
bool isAsker(){return m_is_asker;}
const irr::core::stringw & getDate() { return m_date; }
bool isOnline() const { return m_is_online; }
void setOnline(bool online) { m_is_online = online; }
};
class FriendsListRequest : public XMLRequest
{
virtual void callback ();
@ -61,6 +81,7 @@ namespace Online{
bool m_is_current_user;
uint32_t m_id;
irr::core::stringw m_username;
RelationInfo * m_relation_info;
bool m_has_fetched_friends;
std::vector<uint32_t> m_friends;
@ -76,6 +97,9 @@ namespace Online{
public:
Profile( const uint32_t & userid,
const irr::core::stringw & username);
Profile( const XMLNode * xml,
ConstructorType type = C_DEFAULT);
~Profile();
void fetchFriends();
const std::vector<uint32_t> & getFriends();
@ -83,13 +107,14 @@ namespace Online{
bool isReady() const { return getState() == S_READY; }
bool isCurrentUser() const { return m_is_current_user; }
const RelationInfo * getRelationInfo() { return m_relation_info; }
void setCacheBit() { m_cache_bit = true; }
void unsetCacheBit() { m_cache_bit = false; }
bool getCacheBit() const { return m_cache_bit; }
uint32_t getID() const { return m_id; }
irr::core::stringw getUserName() const { return m_username; }
const irr::core::stringw & getUserName() const { return m_username; }
}; // class CurrentUser

View File

@ -106,6 +106,7 @@ void OnlineProfileFriends::onUpdate(float delta, irr::video::IVideoDriver* driv
if(m_visiting_profile->isReady())
{
m_friends_list_widget->clear();
Log::info("","%d",m_visiting_profile->getFriends().size());
for(unsigned int i = 0; i < m_visiting_profile->getFriends().size(); i++)
{
PtrVector<GUIEngine::ListWidget::ListCell> * row = new PtrVector<GUIEngine::ListWidget::ListCell>;

View File

@ -217,7 +217,6 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
}
else if (selection == m_profile_widget->m_properties[PROP_ID])
{
ProfileManager::get()->addToCache(new Profile(CurrentUser::get()->getUserID(), CurrentUser::get()->getUserName()));
ProfileManager::get()->setVisiting(CurrentUser::get()->getUserID());
StateManager::get()->pushScreen(OnlineProfileOverview::getInstance());
}

View File

@ -65,16 +65,11 @@ void OnlineUserSearch::parseResult(const XMLNode * input)
{
m_users.clear();
const XMLNode * users_xml = input->getNode("users");
uint32_t id(0);
irr::core::stringw username("");
for (unsigned int i = 0; i < users_xml->getNumNodes(); i++)
{
users_xml->getNode(i)->get("id", &id);
users_xml->getNode(i)->get("user_name", &username);
ProfileManager::get()->addToCache(
new Profile(id, username)
);
m_users.push_back(id);
Profile * profile = new Profile(users_xml->getNode(i));
ProfileManager::get()->addToCache(profile);
m_users.push_back(profile->getID());
}
}
@ -85,6 +80,7 @@ void OnlineUserSearch::showList()
{
PtrVector<GUIEngine::ListWidget::ListCell> * row = new PtrVector<GUIEngine::ListWidget::ListCell>;
Profile * profile = ProfileManager::get()->getProfileByID(m_users[i]);
assert(profile != NULL);
row->push_back(new GUIEngine::ListWidget::ListCell(profile->getUserName(),-1,3));
m_user_list_widget->addItem("user", row);
}