From bed8dcfa17b2f9de35a145826c2a4201e6daff13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Wed, 2 Oct 2013 20:08:00 +0000 Subject: Facebook: Multi user chat improvements - Load unread messages at login - Mark received messages as read git-svn-id: http://svn.miranda-ng.org/main/trunk@6313 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/process.cpp | 72 +++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'protocols/FacebookRM/src/process.cpp') diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index af9726db2f..97ca204e9e 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -348,13 +348,45 @@ void FacebookProto::ProcessUnreadMessage(void *p) CODE_BLOCK_TRY std::vector messages; + std::map chatrooms; facebook_json_parser* p = new facebook_json_parser(this); - p->parse_thread_messages(&resp.data, &messages, true, limit); + p->parse_thread_messages(&resp.data, &messages, &chatrooms, true, limit); delete p; - for(std::vector::size_type i = 0; i < messages.size(); i++) { - if (messages[i]->user_id != facy.self_.user_id) { + for (std::map::iterator it = chatrooms.begin(); it != chatrooms.end(); ) { + + 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); + setString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str()); + + for (std::map::iterator jt = room->participants.begin(); jt != room->participants.end(); ) { + AddChatContact(room->thread_id.c_str(), jt->first.c_str(), jt->second.c_str()); + jt++; + } + } + + if (!hChatContact) + hChatContact = ChatIDToHContact(room->thread_id); + + setString(hChatContact, FACEBOOK_KEY_MESSAGE_ID, room->thread_id.c_str()); + ForkThread(&FacebookProto::ReadMessageWorker, hChatContact); + + delete it->second; + it = chatrooms.erase(it); + } + chatrooms.clear(); + + + for (std::vector::size_type i = 0; i < messages.size(); i++) { + if (messages[i]->isChat) { + LOG(" Got chat message: %s", messages[i]->message_text.c_str()); + UpdateChat(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) { LOG(" Got message: %s", messages[i]->message_text.c_str()); facebook_user fbu; fbu.user_id = messages[i]->user_id; @@ -369,26 +401,22 @@ void FacebookProto::ProcessUnreadMessage(void *p) ParseSmileys(messages[i]->message_text, hContact); - if (messages[i]->isChat) { - + 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 { - 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); - } + 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