diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-09-01 01:09:56 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-09-01 01:09:56 +0000 |
commit | 669c32164d32129e6226f9f586f9ebfebd6fa9c7 (patch) | |
tree | 0f8b8ff348cd0f544d17c00211b81449ed1ebbbb /protocols | |
parent | 2d091ed700332dd73d94353be44b9e1d8c22aeca (diff) |
Facebook: Add support for forgotten PHONE_CALL and cleanup code
git-svn-id: http://svn.miranda-ng.org/main/trunk@17233 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 15 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 142 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 8 |
3 files changed, 58 insertions, 107 deletions
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 7d07a010d6..dd389df257 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -187,13 +187,14 @@ enum ClientType { // Each type then could have also separate class representing it. And when giving it in some list, make it map of arrays with key=thread_id to group it by contact/chat, to have it more effective
// Use also for Poke and such events...
enum MessageType {
- MESSAGE = 1, // Classic message
- CALL = 2, // Video call
- ADMIN_TEXT = 3,
- SUBSCRIBE = 4,
- UNSUBSCRIBE = 5,
- THREAD_NAME = 6,
- THREAD_IMAGE = 7,
+ MESSAGE = 1,
+ PHONE_CALL = 2,
+ VIDEO_CALL = 3,
+ ADMIN_TEXT = 4,
+ SUBSCRIBE = 5,
+ UNSUBSCRIBE = 6,
+ THREAD_NAME = 7,
+ THREAD_IMAGE = 8,
};
enum ParticipantRole {
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index a46fd08fb2..c79ad14716 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -72,6 +72,47 @@ void parseUser(const JSONNode &it, facebook_user *fbu) } } +void parseMessageType(FacebookProto *proto, facebook_message &message, const JSONNode &log_type_, const JSONNode &log_body_, const JSONNode &log_data_) { + if (!log_type_ || !log_body_ || !log_data_) + return; + + std::string logType = log_type_.as_string(); + + if (logType == "log:phone-call") { + message.type = PHONE_CALL; + } + else if (logType == "log:video-call") { + message.type = VIDEO_CALL; + } + else if (logType == "log:generic-admin-text") { + message.type = ADMIN_TEXT; + } + else if (logType == "log:subscribe") { + message.type = SUBSCRIBE; + + const JSONNode &fbids_ = log_data_["added_participants"]; + for (auto it2 = fbids_.begin(); it2 != fbids_.end(); ++it2) { + std::string id = (*it2).as_string().substr(5); // strip "fbid:" prefix + if (!message.data.empty()) + message.data += ";"; + message.data += id; + } + } + else if (logType == "log:unsubscribe") { + message.type = UNSUBSCRIBE; + } + else if (logType == "log:thread-name") { + message.type = THREAD_NAME; + message.data = log_data_["name"].as_string(); + } + else if (logType == "log:thread-image") { + message.type = THREAD_IMAGE; + } + else { + proto->debugLogA("!!! Unknown log type - %s", logType.c_str()); + } +} + int facebook_json_parser::parse_chat_participant_names(std::string *data, std::map<std::string, chatroom_participant>* participants) { std::string jsonData = data->substr(9); @@ -964,36 +1005,7 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector<faceboo message.message_id = message_id; message.thread_id = thread_id; - if (logType == "log:video-call") { - message.type = CALL; - } - else if (logType == "log:generic-admin-text") { - message.type = ADMIN_TEXT; - } - else if (logType == "log:subscribe") { - message.type = SUBSCRIBE; - - const JSONNode &fbids_ = log_data_["added_participants"]; - for (auto it2 = fbids_.begin(); it2 != fbids_.end(); ++it2) { - std::string id = (*it2).as_string().substr(5); // strip "fbid:" prefix - if (!message.data.empty()) - message.data += ";"; - message.data += id; - } - } - else if (logType == "log:unsubscribe") { - message.type = UNSUBSCRIBE; - } - else if (logType == "log:thread-name") { - message.type = THREAD_NAME; - message.data = log_data_["name"].as_string(); - } - else if (logType == "log:thread-image") { - message.type = THREAD_IMAGE; - } - else { - proto->debugLogA("!!! Unknown log type - %s", logType.c_str()); - } + parseMessageType(proto, message, log_type_, log_body_, log_data_); messages->push_back(message); } @@ -1191,40 +1203,8 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< else continue; } - - if (log_type_) { - std::string log_type = log_type_.as_string(); - if (log_type == "log:video-call") { - message.type = CALL; - } - else if (log_type == "log:generic-admin-text") { - message.type = ADMIN_TEXT; - } - else if (log_type == "log:subscribe") { - message.type = SUBSCRIBE; - - const JSONNode &fbids_ = log_data_["added_participants"]; - for (auto it2 = fbids_.begin(); it2 != fbids_.end(); ++it2) { - std::string id = (*it2).as_string().substr(5); // strip "fbid:" prefix - if (!message.data.empty()) - message.data += ";"; - message.data += id; - } - } - else if (log_type == "log:unsubscribe") { - message.type = UNSUBSCRIBE; - } - else if (log_type == "log:thread-name") { - message.type = THREAD_NAME; - message.data = log_data_["name"].as_string(); - } - else if (log_type == "log:thread-image") { - message.type = THREAD_IMAGE; - } - else { - proto->debugLogA("parse_thread_messages: unknown message log type (%s) - %s", mid.as_string().c_str(), log_type.c_str()); - } - } + + parseMessageType(proto, message, log_type_, log_body_, log_data_); messages->push_back(message); } @@ -1306,39 +1286,7 @@ int facebook_json_parser::parse_history(std::string *data, std::vector< facebook message.isChat = false; message.user_id = other_user_id; - if (log_type_) { - std::string log_type = log_type_.as_string(); - if (log_type == "log:video-call") { - message.type = CALL; - } - else if (log_type == "log:generic-admin-text") { - message.type = ADMIN_TEXT; - } - else if (log_type == "log:subscribe") { - message.type = SUBSCRIBE; - - const JSONNode &fbids_ = log_data_["added_participants"]; - for (auto it2 = fbids_.begin(); it2 != fbids_.end(); ++it2) { - std::string id = (*it2).as_string().substr(5); // strip "fbid:" prefix - if (!message.data.empty()) - message.data += ";"; - message.data += id; - } - } - else if (log_type == "log:unsubscribe") { - message.type = UNSUBSCRIBE; - } - else if (log_type == "log:thread-name") { - message.type = THREAD_NAME; - message.data = log_data_["name"].as_string(); - } - else if (log_type == "log:thread-image") { - message.type = THREAD_IMAGE; - } - else { - proto->debugLogA("parse_history: unknown message log type (%s) - %s", mid.as_string().c_str(), log_type.c_str()); - } - } + parseMessageType(proto, message, log_type_, log_body_, log_data_); messages->push_back(message); } diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 9e47f091ee..4a64b638db 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -595,10 +595,12 @@ void FacebookProto::LoadHistory(void *pParam) DBEVENTINFO dbei = { 0 }; dbei.cbSize = sizeof(dbei); - if (msg.type == CALL) + if (msg.type == MESSAGE) + dbei.eventType = EVENTTYPE_MESSAGE; + else if (msg.type == VIDEO_CALL || msg.type == PHONE_CALL) dbei.eventType = FACEBOOK_EVENTTYPE_CALL; else - dbei.eventType = EVENTTYPE_MESSAGE; + dbei.eventType = EVENTTYPE_URL; // FIXME: Use better and specific type for our other event types. dbei.flags = DBEF_UTF; @@ -1074,7 +1076,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo if (msg.type == MESSAGE) dbei.eventType = EVENTTYPE_MESSAGE; - else if (msg.type == CALL) + else if (msg.type == VIDEO_CALL || msg.type == PHONE_CALL) dbei.eventType = FACEBOOK_EVENTTYPE_CALL; else dbei.eventType = EVENTTYPE_URL; // FIXME: Use better and specific type for our other event types. |