diff options
author | Robert Pösel <robyer@seznam.cz> | 2013-06-17 20:47:01 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2013-06-17 20:47:01 +0000 |
commit | c777014d3717e597a2abb5cf6391f80fd6bd3fad (patch) | |
tree | 128dedad136059b0cbfb3c8fa88d5b46e179c693 | |
parent | 5041283ecb1955228ce05338e99062dfbccceb71 (diff) |
Facebook: AddToContactList method cleanup.
git-svn-id: http://svn.miranda-ng.org/main/trunk@5003 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 98 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 31 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 2 |
4 files changed, 45 insertions, 88 deletions
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 020bc38390..5d448107df 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -25,31 +25,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. bool FacebookProto::IsMyContact(HANDLE hContact, bool include_chat)
{
const char *proto = GetContactProto(hContact);
- if(proto && strcmp(m_szModuleName, proto) == 0)
- {
- if(include_chat)
+ if (proto && !strcmp(m_szModuleName, proto)) {
+ if (include_chat)
return true;
else
- return db_get_b(hContact,m_szModuleName,"ChatRoom",0) == 0;
- } else {
- return false;
+ return !db_get_b(hContact, m_szModuleName, "ChatRoom", 0);
}
+ return false;
}
HANDLE FacebookProto::ChatIDToHContact(std::string chat_id)
{
for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- if(!IsMyContact(hContact, true))
+ if (!IsMyContact(hContact, true))
continue;
- DBVARIANT dbv;
- if(!db_get_s(hContact,m_szModuleName,"ChatRoomID",&dbv))
- {
- bool found = strcmp(chat_id.c_str(), dbv.pszVal) == 0;
- db_free(&dbv);
- if (found)
- return hContact;
- }
+ ptrA id = db_get_sa(hContact, m_szModuleName, "ChatRoomID");
+ if (id && !strcmp(id, chat_id.c_str()))
+ return hContact;
}
return 0;
@@ -61,23 +54,15 @@ HANDLE FacebookProto::ContactIDToHContact(std::string user_id) if (!IsMyContact(hContact))
continue;
- DBVARIANT dbv;
- if(!db_get_s(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv))
- {
- if(strcmp(user_id.c_str(),dbv.pszVal) == 0)
- {
- db_free(&dbv);
- return hContact;
- } else {
- db_free(&dbv);
- }
- }
+ ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ if (id && !strcmp(id, user_id.c_str()))
+ return hContact;
}
return 0;
}
-HANDLE FacebookProto::AddToContactList(facebook_user* fbu, BYTE type, bool dont_check, const char *new_name)
+HANDLE FacebookProto::AddToContactList(facebook_user* fbu, BYTE type, bool dont_check)
{
HANDLE hContact;
@@ -102,18 +87,20 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, BYTE type, bool dont_ db_unset(hContact, "CList", "MyHandle");
- DBVARIANT dbv;
- if(!db_get_ts(NULL,m_szModuleName,FACEBOOK_KEY_DEF_GROUP,&dbv))
- {
- db_set_ts(hContact,"CList","Group",dbv.ptszVal);
- db_free(&dbv);
- }
+ ptrT group = db_get_tsa(NULL, m_szModuleName, FACEBOOK_KEY_DEF_GROUP);
+ if (group)
+ db_set_ts(hContact, "CList", "Group", group);
- if (strlen(new_name) > 0)
- {
- db_set_utf(hContact, m_szModuleName, FACEBOOK_KEY_NAME, new_name);
- db_set_utf(hContact, m_szModuleName, FACEBOOK_KEY_NICK, new_name);
+ if (!fbu->real_name.empty()) {
+ db_set_utf(hContact, m_szModuleName, FACEBOOK_KEY_NAME, fbu->real_name.c_str());
+ db_set_utf(hContact, m_szModuleName, FACEBOOK_KEY_NICK, fbu->real_name.c_str());
}
+
+ if (fbu->gender)
+ db_set_b(hContact, m_szModuleName, "Gender", fbu->gender);
+
+ if (!fbu->image_url.empty())
+ db_set_s(hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, fbu->image_url.c_str());
db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, type);
@@ -136,13 +123,9 @@ void FacebookProto::SetAllContactStatuses(int status, bool reset_client) continue;
if (reset_client) {
- DBVARIANT dbv;
- if (!db_get_ts(hContact,m_szModuleName,"MirVer",&dbv)) {
- if (_tcscmp(dbv.ptszVal, _T(FACEBOOK_NAME)))
- db_set_ts(hContact,m_szModuleName,"MirVer", _T(FACEBOOK_NAME));
- db_free(&dbv);
- }
-
+ ptrT mirver = db_get_tsa(hContact, m_szModuleName, "MirVer");
+ if (!mirver || _tcscmp(mirver, _T(FACEBOOK_NAME)))
+ db_set_ts(hContact, m_szModuleName, "MirVer", _T(FACEBOOK_NAME));
/*std::tstring foldername = GetAvatarFolder() + L"\\smileys\\";
TCHAR *path = _tcsdup(foldername.c_str());
@@ -195,8 +178,7 @@ void FacebookProto::DeleteContactFromServer(void *data) HANDLE hContact = ContactIDToHContact(id);
// If contact wasn't deleted from database
- if (hContact != NULL)
- {
+ if (hContact != NULL) {
db_set_w(hContact, m_szModuleName, "Status", ID_STATUS_OFFLINE);
db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, FACEBOOK_CONTACT_NONE);
db_set_dw(hContact, m_szModuleName, FACEBOOK_KEY_DELETED, ::time(NULL));
@@ -232,15 +214,12 @@ void FacebookProto::AddContactToServer(void *data) // Process result data
facy.validate_response(&resp);
- if (resp.data.find("\"success\":true", 0) != std::string::npos)
- {
+ if (resp.data.find("\"success\":true", 0) != std::string::npos) {
HANDLE hContact = ContactIDToHContact(id);
// If contact wasn't deleted from database
if (hContact != NULL)
- {
db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, FACEBOOK_CONTACT_REQUEST);
- }
NotifyEvent(m_tszUserName, TranslateT("Request for friendship was sent."), NULL, FACEBOOK_EVENT_OTHER);
} else {
@@ -267,12 +246,8 @@ void FacebookProto::ApproveContactToServer(void *data) std::string get_data = "id=";
- DBVARIANT dbv;
- if (!db_get_s(hContact, m_szModuleName, FACEBOOK_KEY_ID, &dbv))
- {
- get_data += dbv.pszVal;
- db_free(&dbv);
- }
+ ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ get_data += id;
http::response resp = facy.flap(FACEBOOK_REQUEST_APPROVE_FRIEND, &post_data, &get_data);
@@ -296,12 +271,8 @@ void FacebookProto::CancelFriendsRequest(void *data) query += "&fb_dtsg=" + facy.dtsg_;
query += "&__user=" + facy.self_.user_id;
- DBVARIANT dbv;
- if (!db_get_s(hContact, m_szModuleName, FACEBOOK_KEY_ID, &dbv))
- {
- query += "&friend=" + std::string(dbv.pszVal);
- db_free(&dbv);
- }
+ ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ query += "&friend=" + std::string(id);
// Get unread inbox threads
http::response resp = facy.flap(FACEBOOK_REQUEST_CANCEL_REQUEST, &query);
@@ -349,9 +320,8 @@ void FacebookProto::SendPokeWorker(void *p) utils::text::slashu_to_utf8(
utils::text::source_get_value(&resp.data, 3, "\"body\":", "__html\":\"", "\"}"))));
- TCHAR* tmessage = mir_utf8decodeT(message.c_str());
+ ptrT tmessage = mir_utf8decodeT(message.c_str());
NotifyEvent(m_tszUserName, tmessage, NULL, FACEBOOK_EVENT_OTHER);
- mir_free(tmessage);
}
facy.handle_success("SendPokeWorker");
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 974feb3844..ce440d6019 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -93,18 +93,11 @@ void FacebookProto::ProcessBuddyList(void* data) } else {
i = i->next;
- if (!fbu->handle) { // just been added
+ if (!fbu->handle) // just been added
fbu->handle = AddToContactList(fbu, FACEBOOK_CONTACT_FRIEND);
-
- if (!fbu->real_name.empty()) {
- db_set_utf(fbu->handle, m_szModuleName, FACEBOOK_KEY_NAME, fbu->real_name.c_str());
- db_set_utf(fbu->handle, m_szModuleName, FACEBOOK_KEY_NICK, fbu->real_name.c_str());
- }
- }
- if (db_get_w(fbu->handle, m_szModuleName, "Status", 0) != fbu->status_id) {
+ if (db_get_w(fbu->handle, m_szModuleName, "Status", 0) != fbu->status_id)
db_set_w(fbu->handle, m_szModuleName, "Status", fbu->status_id);
- }
if (db_get_dw(fbu->handle, m_szModuleName, "LastActiveTS", 0) != fbu->last_active) {
if (fbu->last_active > 0)
@@ -251,16 +244,10 @@ void FacebookProto::ProcessFriendList(void* data) }
// Check remain contacts in map and add it to contact list
- for (std::map< std::string, facebook_user* >::iterator iter = friends.begin(); iter != friends.end(); ++iter)
- {
+ for (std::map< std::string, facebook_user* >::iterator iter = friends.begin(); iter != friends.end(); ++iter) {
facebook_user *fbu = iter->second;
- HANDLE hContact = AddToContactList(fbu, FACEBOOK_CONTACT_FRIEND, true); // This contact is surely new
-
- db_set_b(hContact, m_szModuleName, "Gender", fbu->gender);
- db_set_utf(hContact, m_szModuleName, FACEBOOK_KEY_NAME, fbu->real_name.c_str());
- db_set_utf(hContact, m_szModuleName, FACEBOOK_KEY_NICK, fbu->real_name.c_str());
- db_set_s(hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, fbu->image_url.c_str());
+ HANDLE hContact = AddToContactList(fbu, FACEBOOK_CONTACT_FRIEND, true); // This contact is surely new ...are you sure?
// db_set_w(hContact, m_szModuleName, "Status", ID_STATUS_OFFLINE);
}
@@ -350,12 +337,11 @@ void FacebookProto::ProcessUnreadMessage(void *tid_data) return;
}
- std::string name = utils::text::source_get_value(&messageslist, 2, "sender_name\":\"", "\"");
-
facebook_user fbu;
fbu.user_id = user_id;
+ fbu.real_name = utils::text::source_get_value(&messageslist, 2, "sender_name\":\"", "\"");
- HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE, false, name.c_str());
+ HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE);
// TODO: if contact is newly added, get his user info
// TODO: maybe create new "receiveMsg" function and use it for offline and channel messages?
@@ -469,8 +455,9 @@ void FacebookProto::ProcessMessages(void* data) LOG(" Got message: %s", messages[i]->message_text.c_str());
facebook_user fbu;
fbu.user_id = messages[i]->user_id;
+ fbu.real_name = messages[i]->sender_name;
- HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE, false, messages[i]->sender_name.c_str());
+ HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE);
db_set_s(hContact, m_szModuleName, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str());
// TODO: if contact is newly added, get his user info
@@ -609,7 +596,7 @@ void FacebookProto::ProcessFriendRequests(void*) if (fbu->user_id.length() && fbu->real_name.length())
{
- HANDLE hContact = AddToContactList(fbu, FACEBOOK_CONTACT_APPROVE, false, fbu->real_name.c_str());
+ HANDLE hContact = AddToContactList(fbu, FACEBOOK_CONTACT_APPROVE);
db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, FACEBOOK_CONTACT_APPROVE);
bool seen = false;
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 04d64f1605..10cf2591bf 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -252,7 +252,7 @@ HANDLE FacebookProto::AddToList(int flags, PROTOSEARCHRESULT* psr) fbu.real_name += " ";
fbu.real_name += surname;
- HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE, false, fbu.real_name.c_str());
+ HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE);
if (hContact) {
if (flags & PALF_TEMPORARY) {
db_set_b(hContact, "Clist", "Hidden", 1);
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 8fb316366f..640ccad168 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -168,7 +168,7 @@ public: bool IsMyContact(HANDLE, bool include_chat = false);
HANDLE ContactIDToHContact(std::string);
HANDLE ChatIDToHContact(std::string);
- HANDLE AddToContactList(facebook_user*, BYTE type, bool dont_check = false, const char *new_name = "");
+ HANDLE AddToContactList(facebook_user*, BYTE type, bool dont_check = false);
void SetAllContactStatuses(int status, bool reset_client = false);
HANDLE HContactFromAuthEvent(HANDLE hEvent);
|