From 80562f021ec5144326fb940422bfbd974bb74732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Wed, 23 Apr 2014 09:43:44 +0000 Subject: Facebook: Fixed loading own name and saving names improvements + hidden setting "NameAsNick" to not save real name as nickname (but it's pretty useless/ugly now) git-svn-id: http://svn.miranda-ng.org/main/trunk@9054 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/docs/facebook - readme.txt | 6 ++++ protocols/FacebookRM/src/communication.cpp | 21 ++++++++++---- protocols/FacebookRM/src/contacts.cpp | 37 +++++++++++++++---------- protocols/FacebookRM/src/db.h | 1 + protocols/FacebookRM/src/entities.h | 4 ++- protocols/FacebookRM/src/json.cpp | 4 ++- protocols/FacebookRM/src/process.cpp | 19 ++++--------- 7 files changed, 58 insertions(+), 34 deletions(-) (limited to 'protocols/FacebookRM') diff --git a/protocols/FacebookRM/docs/facebook - readme.txt b/protocols/FacebookRM/docs/facebook - readme.txt index 52dcd218de..49b79368ac 100644 --- a/protocols/FacebookRM/docs/facebook - readme.txt +++ b/protocols/FacebookRM/docs/facebook - readme.txt @@ -31,10 +31,16 @@ Info: "UseLocalTimestampUnread" (Byte) - 1 = Use local timestamp for offline (unread) messages "KeepUnread" (Byte) - 1 = Don't mark messages as read on server (works globally or per contact) "NaseemsSpamMode" (Byte) - 1 = Don't add contacts when we send message to them from other instances, add them only when they reply +"NameAsNick" (Byte) - 0 = don't use real name as nickname, use nickname if possible (default is 1) -------------------------------- Version history -------------------------------- +0.2.?.? - ?.?.2014 + + Hidden setting "NameAsNick" to not save real name as nickname (but it's pretty useless now) + ! Improved saving names (save only when changed) + ! Fixed loading own name + 0.2.4.0 - 21.4.2014 + Support true invisible status (they don't see you, but you see them) + Don't load "unread messages" which we received already (but didn't read them yet) 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, "", ""); - 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(""); + if (pos != std::string::npos) { + this->self_.nick = utils::text::source_get_value(&this->self_.real_name, 2, "(", ")"); + 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 . #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 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 . #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); } -- cgit v1.2.3