summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-06-19 10:39:56 +0000
committerRobert Pösel <robyer@seznam.cz>2014-06-19 10:39:56 +0000
commit99081c722ac293e30d993b504851bf096b3cd5d8 (patch)
treee11cdb2040cb2ac9bb4cca7f36527c1eb48fcd04 /protocols/FacebookRM/src
parent8cc704c0ac76ac635b2ca5e40ce5a21f2686156a (diff)
Facebook: Save contact's username into database (as key "Username")
git-svn-id: http://svn.miranda-ng.org/main/trunk@9541 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/contacts.cpp3
-rw-r--r--protocols/FacebookRM/src/db.h1
-rw-r--r--protocols/FacebookRM/src/entities.h480
-rw-r--r--protocols/FacebookRM/src/json.cpp4
-rw-r--r--protocols/FacebookRM/src/process.cpp10
5 files changed, 257 insertions, 241 deletions
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 808bdef735..76939ee44b 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -212,6 +212,9 @@ MCONTACT FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, b
if (!fbu->real_name.empty())
SaveName(hContact, fbu);
+ if (!fbu->username.empty())
+ setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str());
+
if (fbu->gender)
setByte(hContact, "Gender", fbu->gender);
diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h
index 9f28ee4211..834f7e7a74 100644
--- a/protocols/FacebookRM/src/db.h
+++ b/protocols/FacebookRM/src/db.h
@@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_KEY_SECOND_NAME "SecondName"
#define FACEBOOK_KEY_LAST_NAME "LastName"
#define FACEBOOK_KEY_NICK "Nick"
+#define FACEBOOK_KEY_USERNAME "Username"
#define FACEBOOK_KEY_PASS "Password"
#define FACEBOOK_KEY_DEVICE_ID "DeviceID"
#define FACEBOOK_KEY_AV_URL "AvatarURL"
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index a99479bdab..977b9b635d 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -1,239 +1,241 @@
-/*
-
-Facebook plugin for Miranda Instant Messenger
-_____________________________________________
-
-Copyright © 2009-11 Michal Zelinka, 2011-13 Robert Pösel
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#pragma once
-
-struct facebook_user
-{
- MCONTACT handle;
-
- std::string user_id;
- std::string real_name;
- std::string nick;
-
- unsigned int status_id;
- unsigned int gender;
- DWORD last_active;
-
- std::string image_url;
-
- bool deleted;
- bool idle;
-
- ClientType client;
-
- facebook_user()
- {
- this->handle = NULL;
- 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;
- this->client = CLIENT_WEB;
- }
-
- facebook_user(facebook_user* fu)
- {
- 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;
- this->image_url = fu->image_url;
- this->deleted = fu->deleted;
- this->idle = fu->idle;
- this->client = fu->client;
- }
-
- TCHAR *getMirVer()
- {
- switch (this->client) {
- case CLIENT_APP:
- return _T(FACEBOOK_CLIENT_APP);
- case CLIENT_MESSENGER:
- return _T(FACEBOOK_CLIENT_MESSENGER);
- case CLIENT_OTHER:
- return _T(FACEBOOK_CLIENT_OTHER);
- case CLIENT_MOBILE:
- return _T(FACEBOOK_CLIENT_MOBILE);
- case CLIENT_WEB:
- default:
- return _T(FACEBOOK_CLIENT_WEB);
- }
- }
-};
-
-struct facebook_chatroom
-{
- std::tstring chat_name;
- std::tstring thread_id;
- std::map<std::string, std::string> participants;
-
- std::string message_readers;
-
- DWORD last_active;
-};
-
-struct facebook_message
-{
- std::string user_id;
- std::string sender_name;
- std::string message_text;
- std::string message_id;
- std::string thread_id;
- DWORD time;
- bool isIncoming;
- bool isUnread;
- bool isChat;
-
- int flag_;
-
- facebook_message()
- {
- this->user_id = this->message_text = this->sender_name = this->message_id = this->thread_id = "";
- this->time = 0;
- this->isUnread = this->isIncoming = true;
- this->isChat = false;
- this->flag_ = 0;
- }
-
- facebook_message(const facebook_message& msg)
- {
- this->user_id = msg.user_id;
- this->sender_name = msg.sender_name;
- this->message_text = msg.message_text;
- this->message_id = msg.message_id;
- this->message_id = msg.thread_id;
- this->time = msg.time;
- this->isIncoming = msg.isIncoming;
- this->isUnread = msg.isUnread;
- this->isChat = msg.isChat;
- this->flag_ = msg.flag_;
- }
-};
-
-struct facebook_notification
-{
- std::string user_id;
- std::string text;
- std::string link;
- std::string id;
- bool seen;
- HWND hWndPopup;
-
- facebook_notification()
- {
- this->user_id = this->text = this->link = this->id = "";
- this->seen = false;
- this->hWndPopup = NULL;
- }
-};
-
-struct facebook_newsfeed
-{
- std::string user_id;
- std::string title;
- std::string text;
- std::string link;
-
- facebook_newsfeed()
- {
- this->user_id = this->title = this->text = this->link = "";
- }
-};
-
-struct send_chat
-{
- send_chat(const std::string &chat_id,const std::string &msg) : chat_id(chat_id), msg(msg) {}
- std::string chat_id;
- std::string msg;
-};
-
-struct send_direct
-{
- send_direct(MCONTACT hContact,const std::string &msg, HANDLE msgid) : hContact(hContact), msg(msg), msgid(msgid) {}
- MCONTACT hContact;
- std::string msg;
- HANDLE msgid;
-};
-
-struct send_typing
-{
- send_typing(MCONTACT hContact,const int status) : hContact(hContact), status(status) {}
- MCONTACT hContact;
- int status;
-};
-
-struct popup_data
-{
- popup_data(FacebookProto *proto) : proto(proto) {}
- popup_data(FacebookProto *proto, std::string url) : proto(proto), url(url) {}
- FacebookProto *proto;
- std::string url;
- std::string notification_id;
-};
-
-struct status_data
-{
- status_data() {
- this->user_id = this->text = this->url = this->place = this->privacy = "";
- this->isPage = false;
- }
- std::string user_id;
- std::string text;
- std::string url;
- std::string place;
- std::string privacy;
- bool isPage;
- std::vector<facebook_user*> users;
-};
-
-struct wall_data
-{
- wall_data() {
- this->user_id = "";
- this->title = NULL;
- this->isPage = false;
- }
- wall_data(std::string user_id, TCHAR *title, bool isPage = false) : user_id(user_id), title(title), isPage(isPage) {}
- std::string user_id;
- TCHAR *title;
- bool isPage;
-};
-
-struct post_status_data {
- post_status_data(FacebookProto *proto) : proto(proto) {}
- post_status_data(FacebookProto *proto, wall_data *wall) : proto(proto) {
- this->walls.push_back(wall);
- }
- FacebookProto *proto;
- std::vector<wall_data*> walls;
-};
-
-struct open_url
-{
- open_url(TCHAR *browser, TCHAR *url) : browser(browser), url(url) {}
- TCHAR *browser;
- TCHAR *url;
-};
+/*
+
+Facebook plugin for Miranda Instant Messenger
+_____________________________________________
+
+Copyright � 2009-11 Michal Zelinka, 2011-13 Robert P�sel
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#pragma once
+
+struct facebook_user
+{
+ MCONTACT handle;
+
+ std::string user_id;
+ std::string real_name;
+ std::string nick;
+ std::string username;
+
+ unsigned int status_id;
+ unsigned int gender;
+ DWORD last_active;
+
+ std::string image_url;
+
+ bool deleted;
+ bool idle;
+
+ ClientType client;
+
+ facebook_user()
+ {
+ this->handle = NULL;
+ this->user_id = this->real_name = this->nick = this->username = this->image_url = "";
+ this->status_id = ID_STATUS_OFFLINE;
+ this->gender = this->last_active = 0;
+ this->deleted = this->idle = false;
+ this->client = CLIENT_WEB;
+ }
+
+ facebook_user(facebook_user* fu)
+ {
+ this->handle = fu->handle;
+ this->user_id = fu->user_id;
+ this->real_name = fu->real_name;
+ this->nick = fu->nick;
+ this->username = fu->username;
+ this->status_id = fu->status_id;
+ this->gender = fu->gender;
+ this->last_active = fu->last_active;
+ this->image_url = fu->image_url;
+ this->deleted = fu->deleted;
+ this->idle = fu->idle;
+ this->client = fu->client;
+ }
+
+ TCHAR *getMirVer()
+ {
+ switch (this->client) {
+ case CLIENT_APP:
+ return _T(FACEBOOK_CLIENT_APP);
+ case CLIENT_MESSENGER:
+ return _T(FACEBOOK_CLIENT_MESSENGER);
+ case CLIENT_OTHER:
+ return _T(FACEBOOK_CLIENT_OTHER);
+ case CLIENT_MOBILE:
+ return _T(FACEBOOK_CLIENT_MOBILE);
+ case CLIENT_WEB:
+ default:
+ return _T(FACEBOOK_CLIENT_WEB);
+ }
+ }
+};
+
+struct facebook_chatroom
+{
+ std::tstring chat_name;
+ std::tstring thread_id;
+ std::map<std::string, std::string> participants;
+
+ std::string message_readers;
+
+ DWORD last_active;
+};
+
+struct facebook_message
+{
+ std::string user_id;
+ std::string sender_name;
+ std::string message_text;
+ std::string message_id;
+ std::string thread_id;
+ DWORD time;
+ bool isIncoming;
+ bool isUnread;
+ bool isChat;
+
+ int flag_;
+
+ facebook_message()
+ {
+ this->user_id = this->message_text = this->sender_name = this->message_id = this->thread_id = "";
+ this->time = 0;
+ this->isUnread = this->isIncoming = true;
+ this->isChat = false;
+ this->flag_ = 0;
+ }
+
+ facebook_message(const facebook_message& msg)
+ {
+ this->user_id = msg.user_id;
+ this->sender_name = msg.sender_name;
+ this->message_text = msg.message_text;
+ this->message_id = msg.message_id;
+ this->message_id = msg.thread_id;
+ this->time = msg.time;
+ this->isIncoming = msg.isIncoming;
+ this->isUnread = msg.isUnread;
+ this->isChat = msg.isChat;
+ this->flag_ = msg.flag_;
+ }
+};
+
+struct facebook_notification
+{
+ std::string user_id;
+ std::string text;
+ std::string link;
+ std::string id;
+ bool seen;
+ HWND hWndPopup;
+
+ facebook_notification()
+ {
+ this->user_id = this->text = this->link = this->id = "";
+ this->seen = false;
+ this->hWndPopup = NULL;
+ }
+};
+
+struct facebook_newsfeed
+{
+ std::string user_id;
+ std::string title;
+ std::string text;
+ std::string link;
+
+ facebook_newsfeed()
+ {
+ this->user_id = this->title = this->text = this->link = "";
+ }
+};
+
+struct send_chat
+{
+ send_chat(const std::string &chat_id,const std::string &msg) : chat_id(chat_id), msg(msg) {}
+ std::string chat_id;
+ std::string msg;
+};
+
+struct send_direct
+{
+ send_direct(MCONTACT hContact,const std::string &msg, HANDLE msgid) : hContact(hContact), msg(msg), msgid(msgid) {}
+ MCONTACT hContact;
+ std::string msg;
+ HANDLE msgid;
+};
+
+struct send_typing
+{
+ send_typing(MCONTACT hContact,const int status) : hContact(hContact), status(status) {}
+ MCONTACT hContact;
+ int status;
+};
+
+struct popup_data
+{
+ popup_data(FacebookProto *proto) : proto(proto) {}
+ popup_data(FacebookProto *proto, std::string url) : proto(proto), url(url) {}
+ FacebookProto *proto;
+ std::string url;
+ std::string notification_id;
+};
+
+struct status_data
+{
+ status_data() {
+ this->user_id = this->text = this->url = this->place = this->privacy = "";
+ this->isPage = false;
+ }
+ std::string user_id;
+ std::string text;
+ std::string url;
+ std::string place;
+ std::string privacy;
+ bool isPage;
+ std::vector<facebook_user*> users;
+};
+
+struct wall_data
+{
+ wall_data() {
+ this->user_id = "";
+ this->title = NULL;
+ this->isPage = false;
+ }
+ wall_data(std::string user_id, TCHAR *title, bool isPage = false) : user_id(user_id), title(title), isPage(isPage) {}
+ std::string user_id;
+ TCHAR *title;
+ bool isPage;
+};
+
+struct post_status_data {
+ post_status_data(FacebookProto *proto) : proto(proto) {}
+ post_status_data(FacebookProto *proto, wall_data *wall) : proto(proto) {
+ this->walls.push_back(wall);
+ }
+ FacebookProto *proto;
+ std::vector<wall_data*> walls;
+};
+
+struct open_url
+{
+ open_url(TCHAR *browser, TCHAR *url) : browser(browser), url(url) {}
+ TCHAR *browser;
+ TCHAR *url;
+};
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index f29913600c..331e473fd3 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 (this ISN'T nickname, but we will use it that way - but it's ugly and noone will use it)
+ JSONNODE *vanity = json_get(it, "vanity"); // username
//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)
@@ -185,7 +185,7 @@ void parseUser(JSONNODE *it, facebook_user *fbu)
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)));
+ fbu->username = 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 7c4584f5f0..2f13369f5a 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -210,6 +210,16 @@ void FacebookProto::ProcessFriendList(void*)
SaveName(hContact, fbu);
}
+ // Update username
+ ptrA username(getStringA(hContact, FACEBOOK_KEY_USERNAME));
+ if (!username || strcmp(username, fbu->username.c_str())) {
+ if (!fbu->username.empty())
+ setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str());
+ else
+ delSetting(hContact, FACEBOOK_KEY_USERNAME);
+ }
+
+ // Update contact type
if (getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) {
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND);
// TODO: remove that popup and use "Contact added you" event?