summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2013-06-12 12:36:39 +0000
committerRobert Pösel <robyer@seznam.cz>2013-06-12 12:36:39 +0000
commit39c0180794b837d1c1525791cb193b8b0a49e703 (patch)
treeba80651a280fe7b7e8855af9d43ae133d2fe1110 /protocols/FacebookRM
parentcc4c50d725df57a51a69fcefa94f5812ab56b6f3 (diff)
Facebook: Fixed and improved duplicit messages checking. Version bump.
git-svn-id: http://svn.miranda-ng.org/main/trunk@4924 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/src/client.h2
-rw-r--r--protocols/FacebookRM/src/communication.cpp2
-rw-r--r--protocols/FacebookRM/src/json.cpp98
-rw-r--r--protocols/FacebookRM/src/version.h2
4 files changed, 54 insertions, 50 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index ce49743ea8..621326ac3c 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -149,7 +149,7 @@ public:
// Messages handling
- std::set<std::string> messages_sent;
+ std::map<std::string, bool> messages_ignore;
bool channel();
bool send_message(std::string message_recipient, std::string message_text, std::string *error_text, int method);
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index cb2e0a3f4a..39cc38d5b2 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -1167,7 +1167,7 @@ bool facebook_client::send_message(std::string message_recipient, std::string me
{
// Remember this message id
std::string mid = utils::text::source_get_value(&resp.data, 2, "\"message_id\":\"", "\"");
- messages_sent.insert(mid);
+ messages_ignore.insert(std::make_pair(mid, false));
} break;
//case 1356002: // You are offline - wtf??
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 49feef15e7..695c75520c 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -273,6 +273,21 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_
return EXIT_SUCCESS;
}
+bool ignore_duplicits(FacebookProto *proto, std::string mid, std::string text) {
+ std::map<std::string, bool>::iterator it = proto->facy.messages_ignore.find(mid);
+ if (it != proto->facy.messages_ignore.end()) {
+ std::string msg = "????? Ignoring duplicit/sent message\n" + text;
+ proto->Log(msg.c_str());
+
+ it->second = true; // mark to delete it at the end
+ return true;
+ }
+
+ // remember this id to ignore duplicits
+ proto->facy.messages_ignore.insert(std::make_pair(mid, true));
+ return false;
+}
+
int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::vector< facebook_notification* >* notifications)
{
using namespace json;
@@ -287,9 +302,6 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
const Object& objRoot = objDocument;
const Array& messagesArray = objRoot["ms"];
- std::string last_msg = "";
- std::string thread_mid = "";
-
for (Array::const_iterator itMessage(messagesArray.Begin()); itMessage != messagesArray.End(); ++itMessage)
{
const Object& objMember = *itMessage;
@@ -309,18 +321,15 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
const Number& time_sent = messageContent["time"];
+ // ignore duplicits or messages sent from miranda
+ if (ignore_duplicits(proto, message_id.Value(), text.Value()))
+ continue;
+
std::string message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value())), true);
if (message_text.empty())
continue;
if (was_id == proto->facy.self_.user_id) {
- // ignore messages sent from Miranda
- std::set<std::string>::iterator it = proto->facy.messages_sent.find(message_id.Value());
- if (it != proto->facy.messages_sent.end()) {
- proto->facy.messages_sent.erase(it);
- continue;
- }
-
const Number& to = objMember["to"];
char to_id[32];
lltoa(to.Value(), to_id, 10);
@@ -351,9 +360,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
std::string msg = "????? We got truncated message so we ignore it\n";
msg += utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
proto->Log(msg.c_str());
- } else if (last_msg != text.Value()) {
- last_msg = text.Value();
-
+ } else {
facebook_message* message = new facebook_message();
message->message_text = message_text;
message->time = utils::time::fix_timestamp(time_sent.Value());
@@ -361,9 +368,6 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
message->message_id = message_id;
messages->push_back(message);
- } else {
- std::string msg = "????? Got duplicit message?\n" + message_text;
- proto->Log(msg.c_str());
}
}
else if (type.Value() == "messaging")
@@ -402,33 +406,26 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
char was_id[32];
lltoa(sender_fbid.Value(), was_id, 10);
- // Ignore messages from myself
- if (was_id == proto->facy.self_.user_id)
+ // ignore duplicits or messages sent from miranda
+ if (ignore_duplicits(proto, mid.Value(), text.Value()))
continue;
- // Ignore group chat messages
- if (thread_mid == mid.Value())
+ // Ignore messages from myself
+ if (was_id == proto->facy.self_.user_id)
continue;
std::string message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value())), true);
if (message_text.empty())
continue;
- if (last_msg != text.Value()) {
- last_msg = text.Value();
-
- facebook_message* message = new facebook_message();
- message->message_text = message_text;
- message->sender_name = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(sender_name.Value()));
- message->time = utils::time::fix_timestamp(time_sent.Value());
- message->user_id = was_id; // TODO: Check if we have contact with this ID in friendlist and otherwise do something different?
- message->message_id = mid.Value();
+ facebook_message* message = new facebook_message();
+ message->message_text = message_text;
+ message->sender_name = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(sender_name.Value()));
+ message->time = utils::time::fix_timestamp(time_sent.Value());
+ message->user_id = was_id; // TODO: Check if we have contact with this ID in friendlist and otherwise do something different?
+ message->message_id = mid.Value();
- messages->push_back(message);
- } else {
- std::string msg = "????? Got duplicit inbox message?\n" + message_text;
- proto->Log(msg.c_str());
- }
+ messages->push_back(message);
}
}
else if (type.Value() == "thread_msg") // multiuser message
@@ -441,31 +438,32 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
char was_id[32];
lltoa(from.Value(), was_id, 10);
- // Ignore messages from myself
- if (was_id == proto->facy.self_.user_id)
- continue;
-
const Object& messageContent = objMember["msg"];
const String& text = messageContent["text"];
- last_msg = text.Value();
-
- // remember this thread mid so we can ignore it in "messaging" section
const String& mid = messageContent["messageId"];
- thread_mid = mid.Value();
- std::string popup_text = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(from_name.Value()));
- popup_text += ": ";
- popup_text += utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
+ // ignore duplicits or messages sent from miranda
+ if (ignore_duplicits(proto, mid.Value(), text.Value()))
+ continue;
- std::string title = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(to_name.Value()));
+ // Ignore messages from myself
+ if (was_id == proto->facy.self_.user_id)
+ continue;
+
+ std::string message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value())), true);
+ if (message_text.empty())
+ continue;
+ std::string title = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(to_name.Value()));
std::string url = "/?action=read&sk=inbox&page&query&tid=" + to_id.Value();
+ std::string popup_text = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(from_name.Value()));
+ popup_text += ": " + message_text;
proto->Log(" Got multichat message");
TCHAR* szTitle = mir_utf8decodeT(title.c_str());
TCHAR* szText = mir_utf8decodeT(popup_text.c_str());
- proto->NotifyEvent(szTitle,szText,NULL,FACEBOOK_EVENT_OTHER, &url);
+ proto->NotifyEvent(szTitle, szText, NULL, FACEBOOK_EVENT_OTHER, &url);
mir_free(szTitle);
mir_free(szText);
}
@@ -536,6 +534,12 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
else
continue;
}
+
+ // remove received messages from map
+ for (std::map<std::string, bool>::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end(); ++it) {
+ if (it->second)
+ proto->facy.messages_ignore.erase(it);
+ }
}
catch (Reader::ParseException& e)
{
diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h
index 223710daa2..f77c2bc19c 100644
--- a/protocols/FacebookRM/src/version.h
+++ b/protocols/FacebookRM/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 1
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
#define __TOSTRING(x) #x