diff options
Diffstat (limited to 'protocols/FacebookRM/src')
| -rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 21 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 37 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/db.h | 1 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/entities.h | 4 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/json.cpp | 4 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/process.cpp | 19 | 
6 files changed, 52 insertions, 34 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 4f538f62a5..5b44a7e9f1 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -916,12 +916,23 @@ bool facebook_client::home()  	{
  	case HTTP_CODE_OK:
  	{		
 -		// Get real_name
 +		// Get real name
  		this->self_.real_name = utils::text::source_get_value(&resp.data, 2, "<strong class=\"profileName\">", "</strong>");
 -		if (!this->self_.real_name.empty()) {
 -			parent->SaveName(NULL, &this->self_);
 -			parent->debugLogA("      Got self real name: %s", this->self_.real_name.c_str());
 -		} else {
 +
 +		// Get and strip optional nickname
 +		std::string::size_type pos = this->self_.real_name.find("<span class=\"alternate_name\">");
 +		if (pos != std::string::npos) {
 +			this->self_.nick = utils::text::source_get_value(&this->self_.real_name, 2, "<span class=\"alternate_name\">(", ")</span>");
 +			parent->debugLogA("      Got self nick name: %s", this->self_.nick.c_str());
 +
 +			this->self_.real_name = this->self_.real_name.substr(0, pos - 1);
 +		}
 +		parent->debugLogA("      Got self real name: %s", this->self_.real_name.c_str());
 +
 +		// Save name and nickname
 +		parent->SaveName(NULL, &this->self_);
 +
 +		if (this->self_.real_name.empty()) {
  			client_notify(TranslateT("Something happened to Facebook. Maybe there was some major update so you should wait for an update."));
  			return handle_error("home", FORCE_QUIT);
  		}
 diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index ea45210d80..4b7b0c4bdb 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -22,37 +22,46 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #include "common.h"
 +void updateStringUtf(FacebookProto *proto, MCONTACT hContact, const char *key, std::string value) {
 +	bool update_required = true;
 +	
 +	DBVARIANT dbv;
 +	if (!proto->getStringUtf(hContact, key, &dbv)) {
 +		update_required = strcmp(dbv.pszVal, value.c_str()) != 0;
 +		db_free(&dbv);
 +	}
 +
 +	if (update_required) {
 +		proto->setStringUtf(hContact, key, value.c_str());
 +	}
 +}
 +
  void FacebookProto::SaveName(MCONTACT hContact, const facebook_user *fbu)
  {
 -	if (fbu->real_name.empty()) {
 -		delSetting(hContact, FACEBOOK_KEY_NICK);
 -		delSetting(hContact, FACEBOOK_KEY_FIRST_NAME);
 -		delSetting(hContact, FACEBOOK_KEY_SECOND_NAME);
 -		delSetting(hContact, FACEBOOK_KEY_LAST_NAME);
 -		return;
 -	}
 +	// Save nick
 +	std::string nick = fbu->real_name;
 +	if (!getBool(FACEBOOK_KEY_NAME_AS_NICK, 1) && !fbu->nick.empty())
 +		nick = fbu->nick;
 -	setStringUtf(hContact, FACEBOOK_KEY_NICK, fbu->real_name.c_str());
 +	updateStringUtf(this, hContact, FACEBOOK_KEY_NICK, nick);
  	// Explode whole name into first, second and last name
  	std::vector<std::string> names;
  	utils::text::explode(fbu->real_name, " ", &names);
 -	setStringUtf(hContact, FACEBOOK_KEY_FIRST_NAME, names.front().c_str());
 -	setStringUtf(hContact, FACEBOOK_KEY_LAST_NAME, names.back().c_str());
 +	updateStringUtf(this, hContact, FACEBOOK_KEY_FIRST_NAME, names.front().c_str());
 +	updateStringUtf(this, hContact, FACEBOOK_KEY_LAST_NAME, names.back().c_str());
 +	std::string middle = "";
  	if (names.size() > 2) {
 -		std::string middle = "";
  		for (std::string::size_type i = 1; i < names.size() - 1; i++) {
  			if (!middle.empty())
  				middle += " ";
  			middle += names.at(i);
  		}
 -		setStringUtf(hContact, FACEBOOK_KEY_SECOND_NAME, middle.c_str());
 -	} else {
 -		delSetting(hContact, FACEBOOK_KEY_SECOND_NAME);
  	}
 +	updateStringUtf(this, hContact, FACEBOOK_KEY_SECOND_NAME, middle);
  }
  bool FacebookProto::IsMyContact(MCONTACT hContact, bool include_chat)
 diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h index e7f659b7b1..536462d9e7 100644 --- a/protocols/FacebookRM/src/db.h +++ b/protocols/FacebookRM/src/db.h @@ -61,6 +61,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #define	FACEBOOK_KEY_LOCALE					"Locale"		// [HIDDEN] - en_US, cs_CZ, etc.
  #define FACEBOOK_KEY_LOCAL_TIMESTAMP_UNREAD	"UseLocalTimestampUnread" // [HIDDEN] - 1 = use local timestamp for offline messages
  #define FACEBOOK_KEY_NASEEMS_SPAM_MODE		"NaseemsSpamMode" // [HIDDEN] - 1 = don't load messages sent from other instances (e.g., browser) - known as "Naseem's spam mode"
 +#define FACEBOOK_KEY_NAME_AS_NICK			"NameAsNick"	// [HIDDEN] - 0 = don't use real name as nickname, use nickname if possible
  #define FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE     "EventNotificationsEnable"
  #define FACEBOOK_KEY_EVENT_FEEDS_ENABLE             "EventFeedsEnable"
 diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index 188bd19df8..0e8fb29522 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -28,6 +28,7 @@ struct facebook_user  	std::string user_id;
  	std::string real_name;
 +	std::string nick;
  	unsigned int status_id;
  	unsigned int gender;
 @@ -43,7 +44,7 @@ struct facebook_user  	facebook_user()
  	{
  		this->handle = NULL;
 -		this->user_id = this->real_name = this->image_url = "";
 +		this->user_id = this->real_name = this->nick = this->image_url = "";
  		this->status_id = ID_STATUS_OFFLINE;
  		this->gender = this->last_active = 0;
  		this->deleted = this->idle = false;
 @@ -55,6 +56,7 @@ struct facebook_user  		this->handle = fu->handle;
  		this->user_id = fu->user_id;
  		this->real_name = fu->real_name;
 +		this->nick = fu->nick;
  		this->status_id = fu->status_id;
  		this->gender = fu->gender;
  		this->last_active = fu->last_active;
 diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index f5a60b1466..e5c8150ebe 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -174,7 +174,7 @@ void parseUser(JSONNODE *it, facebook_user *fbu)  	JSONNODE *name = json_get(it, "name");
  	JSONNODE *thumbSrc = json_get(it, "thumbSrc");
  	JSONNODE *gender = json_get(it, "gender");
 -	//JSONNODE *vanity = json_get(it, "vanity"); // username
 +	JSONNODE *vanity = json_get(it, "vanity"); // username (this ISN'T nickname, but we will use it that way - but it's ugly and noone will use it)
  	//JSONNODE *uri = json_get(it, "uri"); // profile url
  	//JSONNODE *is_friend = json_get(it, "is_friend"); // e.g. "True"
  	//JSONNODE *type = json_get(it, "type"); // e.g. "friend" (classic contact) or "user" (disabled/deleted account)
 @@ -184,6 +184,8 @@ void parseUser(JSONNODE *it, facebook_user *fbu)  		fbu->real_name = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_pstring(name)));
  	if (thumbSrc)
  		fbu->image_url = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_pstring(thumbSrc)));
 +	if (vanity)
 +		fbu->nick = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_pstring(vanity)));
  	if (gender)
  		switch (json_as_int(gender)) {
 diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 171341701c..fbbbb0c657 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -175,23 +175,16 @@ void FacebookProto::ProcessFriendList(void* data)  				// Update gender
  				if (getByte(hContact, "Gender", 0) != fbu->gender)
  					setByte(hContact, "Gender", fbu->gender);
 -
 -				// Update name
 -				DBVARIANT dbv;
 -				bool update_required = true;
 -
 -				// TODO: remove in some future version?
 +				
 +				// TODO: remove this in some future version?
 +				// Remove old useless "RealName" field
  				ptrA realname(getStringA(hContact, "RealName"));
  				if (realname != NULL) {
  					delSetting(hContact, "RealName");
  				}
 -				else if (!getStringUtf(hContact, FACEBOOK_KEY_NICK, &dbv))
 -				{
 -					update_required = strcmp(dbv.pszVal, fbu->real_name.c_str()) != 0;
 -					db_free(&dbv);
 -				}
 -				if (update_required)
 -				{
 +
 +				// Update real name and nick
 +				if (!fbu->real_name.empty()) {
  					SaveName(hContact, fbu);
  				}
  | 
