diff options
-rw-r--r-- | protocols/FacebookRM/src/client.h | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 1 | ||||
-rw-r--r-- | 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<std::string, bool> messages_ignore;
+ std::map<std::string, int> 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 <http://www.gnu.org/licenses/>. #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<std::string, bool>::iterator it = proto->facy.messages_ignore.find(mid); + std::map<std::string, int>::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<std::string, bool>::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end();) { - if (it->second) + for (std::map<std::string, int>::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); |