From 4c6d7054a9d545c8d8978b6fe1d1f8a89119f2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 18 Mar 2014 23:42:49 +0000 Subject: Facebook: Load user info when receiving message from someone who isn't in clist yet git-svn-id: http://svn.miranda-ng.org/main/trunk@8655 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/process.cpp | 119 ++++++++++++----------------------- 1 file changed, 41 insertions(+), 78 deletions(-) (limited to 'protocols/FacebookRM/src/process.cpp') diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index b39168849a..43402fcfd7 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -385,52 +385,7 @@ void FacebookProto::ProcessUnreadMessage(void *p) } chatrooms.clear(); - - for (std::vector::size_type i = 0; i < messages.size(); i++) { - if (messages[i]->isChat) { - debugLogA(" Got chat message: %s", messages[i]->message_text.c_str()); - UpdateChat(_A2T(messages[i]->thread_id.c_str()), messages[i]->user_id.c_str(), messages[i]->sender_name.c_str(), messages[i]->message_text.c_str(), local_timestamp || !messages[i]->time ? ::time(NULL) : messages[i]->time); - } else if (messages[i]->user_id != facy.self_.user_id) { - debugLogA(" 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; - - // TODO: optimize this? - MCONTACT hContact = AddToContactList(&fbu, CONTACT_NONE); - setString(hContact, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str()); - - // Save TID if not exists already - ptrA tid( getStringA(hContact, FACEBOOK_KEY_TID)); - if (!tid || strcmp(tid, messages[i]->thread_id.c_str())) - setString(hContact, FACEBOOK_KEY_TID, messages[i]->thread_id.c_str()); - - // TODO: if contact is newly added, get his user info - // TODO: maybe create new "receiveMsg" function and use it for offline and channel messages? - - ParseSmileys(messages[i]->message_text, hContact); - - if (messages[i]->isIncoming) { - PROTORECVEVENT recv = {0}; - recv.flags = PREF_UTF; - recv.szMessage = const_cast(messages[i]->message_text.c_str()); - recv.timestamp = local_timestamp || !messages[i]->time ? ::time(NULL) : messages[i]->time; - ProtoChainRecvMsg(hContact, &recv); - } else { - DBEVENTINFO dbei = {0}; - dbei.cbSize = sizeof(dbei); - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.flags = DBEF_SENT | DBEF_UTF; - dbei.szModule = m_szModuleName; - dbei.timestamp = local_timestamp || !messages[i]->time ? ::time(NULL) : messages[i]->time; - dbei.cbBlob = (DWORD)messages[i]->message_text.length() + 1; - dbei.pBlob = (PBYTE)messages[i]->message_text.c_str(); - db_event_add(hContact, &dbei); - } - } - delete messages[i]; - } - messages.clear(); + ReceiveMessages(messages, local_timestamp); debugLogA("***** Unread messages processed"); @@ -452,41 +407,22 @@ void FacebookProto::ProcessUnreadMessage(void *p) } } -// TODO: combine processmessages and processunreadmessages? (behavior of showing messages to user should be the same) -void FacebookProto::ProcessMessages(void* data) +void FacebookProto::ReceiveMessages(std::vector messages, bool local_timestamp) { - if (data == NULL) - return; - - std::string* resp = (std::string*)data; - - // receive messages from all folders by default, use hidden setting to receive only inbox messages - bool inboxOnly = getBool(FACEBOOK_KEY_INBOX_ONLY, 0); - - if (isOffline()) - goto exit; - - debugLogA("***** Starting processing messages"); - - CODE_BLOCK_TRY - - std::vector< facebook_message* > messages; - std::vector< facebook_notification* > notifications; - - facebook_json_parser* p = new facebook_json_parser(this); - p->parse_messages(data, &messages, ¬ifications, inboxOnly); - delete p; - - bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0); - - for(std::vector::size_type i=0; i::size_type i = 0; i < messages.size(); i++) { debugLogA(" 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; - MCONTACT hContact = AddToContactList(&fbu, CONTACT_NONE); + MCONTACT hContact = ContactIDToHContact(fbu.user_id); + if (hContact == NULL) { + // We don't have this contact, lets load info about him + LoadContactInfo(&fbu); + + hContact = AddToContactList(&fbu, CONTACT_NONE); + } + setString(hContact, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str()); // Save TID if not exists already @@ -494,9 +430,6 @@ void FacebookProto::ProcessMessages(void* data) if (!tid || strcmp(tid, messages[i]->thread_id.c_str())) setString(hContact, FACEBOOK_KEY_TID, messages[i]->thread_id.c_str()); - // TODO: if contact is newly added, get his user info - // TODO: maybe create new "receiveMsg" function and use it for offline and channel messages? - ParseSmileys(messages[i]->message_text, hContact); if (messages[i]->isIncoming) { @@ -519,6 +452,36 @@ void FacebookProto::ProcessMessages(void* data) delete messages[i]; } messages.clear(); +} + +// TODO: combine processmessages and processunreadmessages? (behavior of showing messages to user should be the same) +void FacebookProto::ProcessMessages(void* data) +{ + if (data == NULL) + return; + + std::string* resp = (std::string*)data; + + // receive messages from all folders by default, use hidden setting to receive only inbox messages + bool inboxOnly = getBool(FACEBOOK_KEY_INBOX_ONLY, 0); + + if (isOffline()) + goto exit; + + debugLogA("***** Starting processing messages"); + + CODE_BLOCK_TRY + + std::vector< facebook_message* > messages; + std::vector< facebook_notification* > notifications; + + facebook_json_parser* p = new facebook_json_parser(this); + p->parse_messages(data, &messages, ¬ifications, inboxOnly); + delete p; + + bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0); + + ReceiveMessages(messages, local_timestamp); for(std::vector::size_type i=0; i