summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src/contacts.cpp
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-04-23 09:43:44 +0000
committerRobert Pösel <robyer@seznam.cz>2014-04-23 09:43:44 +0000
commit80562f021ec5144326fb940422bfbd974bb74732 (patch)
tree350a55451884c1f3ebab276ffedebf0c8e1a1592 /protocols/FacebookRM/src/contacts.cpp
parent775eca92d90a473e087d4598a8539b7842c631b0 (diff)
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
Diffstat (limited to 'protocols/FacebookRM/src/contacts.cpp')
-rw-r--r--protocols/FacebookRM/src/contacts.cpp37
1 files changed, 23 insertions, 14 deletions
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)