diff options
Diffstat (limited to 'protocols/FacebookRM/src/process.cpp')
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 119 |
1 files changed, 41 insertions, 78 deletions
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<facebook_message*>::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<char*>(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<facebook_message*> 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<facebook_message*>::size_type i=0; i<messages.size(); i++)
- {
+ for(std::vector<facebook_message*>::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<facebook_notification*>::size_type i=0; i<notifications.size(); i++)
{
|