diff options
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 41 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 14 | ||||
-rw-r--r-- | protocols/FacebookRM/src/utils.cpp | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/utils.h | 2 |
4 files changed, 28 insertions, 35 deletions
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index ee1a2ed62a..49feef15e7 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -308,8 +308,10 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa //"tab_type":"friend", objMember["tab_type"]
const Number& time_sent = messageContent["time"];
-// proto->Log("????? Checking time %15.2f > %15.2f", time_sent.Value(), proto->facy.last_message_time_);
+ 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
@@ -319,8 +321,6 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa continue;
}
- std::string message_text = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
-
const Number& to = objMember["to"];
char to_id[32];
lltoa(to.Value(), to_id, 10);
@@ -353,16 +353,16 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa proto->Log(msg.c_str());
} else if (last_msg != text.Value()) {
last_msg = text.Value();
+
facebook_message* message = new facebook_message();
- message->message_text = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
+ message->message_text = message_text;
message->time = utils::time::fix_timestamp(time_sent.Value());
message->user_id = was_id;
message->message_id = message_id;
messages->push_back(message);
} else {
- std::string msg = "????? Got duplicit message?\n";
- msg += utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
+ std::string msg = "????? Got duplicit message?\n" + message_text;
proto->Log(msg.c_str());
}
}
@@ -410,24 +410,23 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa if (thread_mid == mid.Value())
continue;
- //proto->Log("????? Checking time %15.2f > %15.2f", time_sent.Value(), proto->facy.last_message_time_);
+ 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 = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
-
+ 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";
- msg += utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
+ std::string msg = "????? Got duplicit inbox message?\n" + message_text;
proto->Log(msg.c_str());
}
}
@@ -454,17 +453,13 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa 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()));
+ 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()));
+ popup_text += utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
- 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=";
- url += to_id.Value();
+ 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();
proto->Log(" Got multichat message");
@@ -517,8 +512,8 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa HANDLE hContact = proto->AddToContactList(&fbu, FACEBOOK_CONTACT_FRIEND);
- if (db_get_w(hContact,proto->m_szModuleName,"Status", 0) == ID_STATUS_OFFLINE)
- db_set_w(hContact,proto->m_szModuleName,"Status",ID_STATUS_ONLINE);
+ if (db_get_w(hContact, proto->m_szModuleName, "Status", 0) == ID_STATUS_OFFLINE)
+ db_set_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_ONLINE);
const Number& state = objMember["st"];
if (state.Value() == 1)
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 0a140724fe..502deaa627 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -369,13 +369,11 @@ void FacebookProto::ProcessUnreadMessage(void *tid_data) std::string::size_type pos3 = messageslist.find("class=\\\"MessagingMessage ", pos2);
std::string messagesgroup = messageslist.substr(pos2, pos3 - pos2);
- DWORD timestamp = utils::conversion::to_timestamp(
- utils::text::source_get_value(&messagesgroup, 2, "data-utime=\\\"", "\\\""));
+ DWORD timestamp = utils::conversion::to_timestamp(utils::text::source_get_value(&messagesgroup, 2, "data-utime=\\\"", "\\\""));
pos3 = 0;
while ((pos3 = messagesgroup.find("class=\\\"content noh", pos3)) != std::string::npos)
{
-
std::string message_attachments = "";
std::string::size_type pos4 = 0;
if ((pos4 = messagesgroup.find("class=\\\"attachments\\\"", pos4)) != std::string::npos) {
@@ -409,9 +407,11 @@ void FacebookProto::ProcessUnreadMessage(void *tid_data) std::string message_text = messagesgroup.substr(pos3, messagesgroup.find("<\\/div", pos3) + 6 - pos3);
message_text = utils::text::source_get_value(&message_text, 2, "\\\">", "<\\/div");
- message_text = utils::text::trim(
- utils::text::special_expressions_decode(
- utils::text::remove_html(message_text)));
+ message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::remove_html(message_text)), true);
+ pos3++;
+
+ if (message_text.empty())
+ continue;
LOG("Got unread message: \"%s\"", message_text.c_str());
@@ -430,8 +430,6 @@ void FacebookProto::ProcessUnreadMessage(void *tid_data) recv.szMessage = const_cast<char*>(message_text.c_str());
recv.timestamp = timestamp;
ProtoChainRecvMsg(hContact, &recv);
-
- pos3++;
}
}
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp index 10214d970c..44de994a73 100644 --- a/protocols/FacebookRM/src/utils.cpp +++ b/protocols/FacebookRM/src/utils.cpp @@ -351,13 +351,13 @@ std::string utils::text::slashu_to_utf8(std::string data) return new_string;
}
-std::string utils::text::trim(std::string data)
+std::string utils::text::trim(std::string data, bool rtrim)
{
std::string spaces = " \t\r\n"; // TODO: include "nbsp"?
- std::string::size_type begin = data.find_first_not_of(spaces);
+ std::string::size_type begin = rtrim ? 0 : data.find_first_not_of(spaces);
std::string::size_type end = data.find_last_not_of(spaces) + 1;
- return (begin != std::string::npos) ? data.substr(begin, end - begin) : "";
+ return (end != std::string::npos) ? data.substr(begin, end - begin) : "";
}
void utils::text::explode(std::string str, std::string separator, std::vector<std::string>* results)
diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h index f0b3b68d96..eef3907004 100644 --- a/protocols/FacebookRM/src/utils.h +++ b/protocols/FacebookRM/src/utils.h @@ -89,7 +89,7 @@ namespace utils std::string edit_html(std::string data);
std::string remove_html(std::string data);
std::string slashu_to_utf8(std::string data);
- std::string trim(std::string data);
+ std::string trim(std::string data, bool rtrim = false);
std::string source_get_value(std::string* data, unsigned int argument_count, ...);
std::string source_get_value2(std::string* data, const char *term, const char *endings);
void explode(std::string str, std::string separator, std::vector<std::string>* results);
|