From 8a904bdef0e8237dee49c1b704d4ebbc2b28a958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Wed, 31 Aug 2016 10:11:32 +0000 Subject: Facebook: Basic support for handling more chat events; version bump Events like user join/leave, change emoji, etc. are now printed, but that's all. Still missing specific behavior for them, but that require more changes in events parsing and on other places. git-svn-id: http://svn.miranda-ng.org/main/trunk@17222 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/json.cpp | 102 +++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 29 deletions(-) (limited to 'protocols/FacebookRM/src/json.cpp') diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index f8cfb701d8..2c97a56b4a 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -665,7 +665,7 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vectorsecond.user_id = from_id; - proto->AddChatContact(tid.c_str(), participant->second); + proto->AddChatContact(tid.c_str(), participant->second, true); } participant = participants.find(from_id); @@ -934,47 +934,60 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vectorfacy.self_.user_id); + message.message_text = message_text; + message.time = utils::time::from_string(action_["timestamp"].as_string()); + message.user_id = message.isChat ? author_id : other_user_id; + message.message_id = message_id; + message.thread_id = thread_id; + if (logType == "log:video-call") { - std::string id = action_["other_user_fbid"].as_string(); - std::string message_id = action_["message_id"].as_string(); - - facebook_message message; - message.isChat = false; - message.isUnread = true; - message.isIncoming = (id != proto->facy.self_.user_id); - message.message_text = message_text; - message.time = utils::time::from_string(action_["timestamp"].as_string()); - message.user_id = id; - message.message_id = message_id; - message.thread_id = thread_id; message.type = CALL; - messages->push_back(message); + } + else if (logType == "log:generic-admin-text") { + message.type = ADMIN_TEXT; + } + else if (logType == "log:subscribe") { + message.type = SUBSCRIBE; + } + 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()); - - // TODO: check for other types, now we expect this is rename chat - if (!proto->m_enableChat) - continue; - - std::string name = log_data_["name"].as_string(); - - // proto->RenameChat(thread_id.c_str(), name.c_str()); // this don't work, why? - proto->setStringUtf(proto->ChatIDToHContact(thread_id), FACEBOOK_KEY_NICK, name.c_str()); - - proto->UpdateChat(thread_id.c_str(), NULL, NULL, message_text.c_str()); } + + messages->push_back(message); } } else if (t == "notifications_read" || t == "notifications_seen") { @@ -1112,8 +1125,7 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< // Either there is "body" (for classic messages), or "log_message_type" and "log_message_body" (for log messages) const JSONNode &log_type_ = (*it)["log_message_type"]; const JSONNode &log_body_ = (*it)["log_message_body"]; - // const JSONNode &log_data_ = (*it)["log_message_data"]; // additional data for this log message - // e.g., for missed video calls - {"answered":false,"caller":"fbid:1234567890","callee":"fbid:123456789012345"} + const JSONNode &log_data_ = (*it)["log_message_data"]; // additional data for this log message if (!author || (!body && !log_body_) || !mid || !tid || !timestamp) { proto->debugLogA("parse_thread_messages: ignoring message (%s) - missing attribute", mid.as_string().c_str()); @@ -1177,6 +1189,22 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< 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; + } + 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()); } @@ -1219,7 +1247,7 @@ int facebook_json_parser::parse_history(std::string *data, std::vector< facebook // Either there is "body" (for classic messages), or "log_message_type" and "log_message_body" (for log messages) const JSONNode &log_type_ = (*it)["log_message_type"]; const JSONNode &log_body_ = (*it)["log_message_body"]; - // const JSONNode &log_data_ = (*it)["log_message_data"]; + const JSONNode &log_data_ = (*it)["log_message_data"]; if (!author || (!body && !log_body_) || !mid || !tid || !timestamp) { proto->debugLogA("parse_history: ignoring message (%s) - missing attribute", mid.as_string().c_str()); @@ -1267,6 +1295,22 @@ int facebook_json_parser::parse_history(std::string *data, std::vector< facebook 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; + } + 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()); } -- cgit v1.2.3