From 30b77dbd46f6d951568ab17203713d5d267051d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sat, 29 Mar 2014 08:59:07 +0000 Subject: Facebook: Fix not to load offline multi chat messages to single contacts git-svn-id: http://svn.miranda-ng.org/main/trunk@8781 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/process.cpp | 95 +++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 33 deletions(-) (limited to 'protocols/FacebookRM/src/process.cpp') diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 43402fcfd7..831b4873f5 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -410,44 +410,73 @@ void FacebookProto::ProcessUnreadMessage(void *p) void FacebookProto::ReceiveMessages(std::vector messages, bool local_timestamp) { for(std::vector::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; + if (messages[i]->isChat) { + debugLogA(" Got chat message: %s", messages[i]->message_text.c_str()); + + std::tstring tthread_id = _A2T(messages[i]->thread_id.c_str()); + std::string user_id = messages[i]->user_id; + std::string user_name = messages[i]->sender_name; + std::string message_text = messages[i]->message_text; + std::string message_id = messages[i]->message_id; + DWORD timestamp = local_timestamp || !messages[i]->time ? ::time(NULL) : messages[i]->time; + + MCONTACT hChatContact = ChatIDToHContact(tthread_id); + + // RM TODO: better use check if chatroom exists/is in db/is online... no? + /// e.g. HANDLE hChatContact = proto->ChatIDToHContact(thread_id); ? + if (GetChatUsers(tthread_id.c_str()) == NULL) { + AddChat(tthread_id.c_str(), tthread_id.c_str()); // TODO: use correct name for chat, not thread_id + hChatContact = ChatIDToHContact(tthread_id); + // Set thread id (TID) for later + setTString(hChatContact, FACEBOOK_KEY_TID, tthread_id.c_str()); + } - MCONTACT hContact = ContactIDToHContact(fbu.user_id); - if (hContact == NULL) { - // We don't have this contact, lets load info about him - LoadContactInfo(&fbu); + if (!hChatContact) + hChatContact = ChatIDToHContact(tthread_id); - hContact = AddToContactList(&fbu, CONTACT_NONE); - } - - setString(hContact, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str()); + UpdateChat(tthread_id.c_str(), user_id.c_str(), user_name.c_str(), message_text.c_str(), timestamp); + setString(hChatContact, FACEBOOK_KEY_MESSAGE_ID, message_id.c_str()); + ForkThread(&FacebookProto::ReadMessageWorker, (void*)hChatContact); + } else { + 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; - // 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()); + MCONTACT hContact = ContactIDToHContact(fbu.user_id); + if (hContact == NULL) { + // We don't have this contact, lets load info about him + LoadContactInfo(&fbu); - ParseSmileys(messages[i]->message_text, hContact); + hContact = AddToContactList(&fbu, CONTACT_NONE); + } - 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); + 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()); + + 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]; } -- cgit v1.2.3