From 2f23f177d8ffcb7e65c52fc7c28b9cb269be8abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sat, 15 Mar 2014 11:12:14 +0000 Subject: Facebook: fix showing duplicates of sent messages (at the cost of slowing down whole processing and sending only one message at a time :() git-svn-id: http://svn.miranda-ng.org/main/trunk@8618 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/communication.cpp | 2 ++ protocols/FacebookRM/src/json.cpp | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'protocols/FacebookRM') diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 53e2bd08a8..9308be3ed8 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -1147,6 +1147,8 @@ bool facebook_client::channel() bool facebook_client::send_message(std::string message_recipient, std::string message_text, std::string *error_text, MessageMethod method) { + ScopedLock s(send_message_lock_); + handle_entry("send_message"); http::response resp; diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index f7f3bc7100..ac53334fe5 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -262,6 +262,8 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_ bool ignore_duplicits(FacebookProto *proto, std::string mid, std::string text) { + ScopedLock s(proto->facy.send_message_lock_); + std::map::iterator it = proto->facy.messages_ignore.find(mid); if (it != proto->facy.messages_ignore.end()) { proto->debugLogA("????? Ignoring duplicit/sent message\n%s", text.c_str()); @@ -353,6 +355,14 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::vector< facebook_notification* >* notifications, bool inboxOnly) { + // remove old received messages from map + for (std::map::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end();) { + if (it->second) + it = proto->facy.messages_ignore.erase(it); + else + ++it; + } + std::string jsonData = static_cast< std::string* >(data)->substr(9); JSONNODE *root = json_parse(jsonData.c_str()); @@ -723,14 +733,6 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa continue; } - // remove received messages from map - for (std::map::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end(); ) { - if (it->second) - it = proto->facy.messages_ignore.erase(it); - else - ++it; - } - json_delete(root); return EXIT_SUCCESS; } -- cgit v1.2.3