summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src/process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/FacebookRM/src/process.cpp')
-rw-r--r--protocols/FacebookRM/src/process.cpp73
1 files changed, 40 insertions, 33 deletions
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 584d1bebcb..866bc8cf00 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -359,9 +359,9 @@ void FacebookProto::ProcessUnreadMessage(void *p)
facebook_chatroom *room = it->second;
HANDLE hChatContact;
if (GetChatUsers(room->thread_id.c_str()) == NULL) {
- // Set thread id (TID) for later.
AddChat(room->thread_id.c_str(), room->chat_name.c_str());
hChatContact = ChatIDToHContact(room->thread_id);
+ // Set thread id (TID) for later
setTString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str());
for (std::map<std::string, std::string>::iterator jt = room->participants.begin(); jt != room->participants.end(); ) {
@@ -395,6 +395,11 @@ void FacebookProto::ProcessUnreadMessage(void *p)
// TODO: optimize this?
HANDLE 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?
@@ -469,38 +474,40 @@ void FacebookProto::ProcessMessages(void* data)
for(std::vector<facebook_message*>::size_type i=0; i<messages.size(); i++)
{
- 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;
-
- HANDLE hContact = AddToContactList(&fbu, CONTACT_NONE);
- setString(hContact, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_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);
- }
+ 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;
+
+ HANDLE 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];
}