From 15bff8a1c1cdfad5c99d6cbb432e77062cd8162c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 15 Jul 2014 18:04:21 +0000 Subject: Facebook: Attempt to fix occasional sending/receiving duplicit messages git-svn-id: http://svn.miranda-ng.org/main/trunk@9815 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/client.h | 2 +- protocols/FacebookRM/src/communication.cpp | 2 +- protocols/FacebookRM/src/constants.h | 1 + protocols/FacebookRM/src/json.cpp | 14 ++++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 4b3d23f112..d62d5d27cb 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -157,7 +157,7 @@ public: // Messages handling - std::map messages_ignore; + std::map messages_ignore; bool channel(); bool send_message(MCONTACT, std::string message_recipient, std::string message_text, std::string *error_text, MessageMethod method); diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 8c72bd9be6..5f29f113b0 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -1201,7 +1201,7 @@ bool facebook_client::send_message(MCONTACT hContact, std::string message_recipi // Remember this message id std::string mid = utils::text::source_get_value(&resp.data, 2, "\"message_id\":\"", "\""); parent->setString(hContact, FACEBOOK_KEY_MESSAGE_ID, mid.c_str()); - messages_ignore.insert(std::make_pair(mid, false)); + messages_ignore.insert(std::make_pair(mid, 0)); } break; //case 1356002: // You are offline - wtf?? diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index d4f8f62ec2..fa1fa24dfe 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -57,6 +57,7 @@ along with this program. If not, see . #define FACEBOOK_GROUP_NAME_LIMIT 100 #define FACEBOOK_MESSAGES_ON_OPEN_LIMIT 99 #define FACEBOOK_TYPING_TIME 60 +#define FACEBOOK_IGNORE_COUNTER_LIMIT 5 // how many consequent requests it should keep info about duplicit message ids // Defaults #define FACEBOOK_MINIMAL_POLL_RATE 10 diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index b12fe32378..2470738b21 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -281,16 +281,16 @@ 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); + 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()); - it->second = true; // mark to delete it at the end + it->second++; // increase counter (for deleting it later) return true; } // remember this id to ignore duplicits - proto->facy.messages_ignore.insert(std::make_pair(mid, true)); + proto->facy.messages_ignore.insert(std::make_pair(mid, 1)); return false; } @@ -373,11 +373,13 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::map< std::string, 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) + for (std::map::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end();) { + if (it->second > FACEBOOK_IGNORE_COUNTER_LIMIT) { it = proto->facy.messages_ignore.erase(it); - else + } else { + it->second++; // increase counter on each request ++it; + } } std::string jsonData = static_cast< std::string* >(data)->substr(9); -- cgit v1.2.3