diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 18 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 101 |
2 files changed, 63 insertions, 56 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 122fd615b0..3e2da643fa 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -469,9 +469,11 @@ std::string facebook_client::choose_action(RequestType request_type, std::string if (!isPing) { action += "&qp=y"; // TODO: what's this item? action += "&pws=fresh"; // TODO: what's this item? - action += "&isq=449655"; // TODO: what's this item? + action += "&isq=487632"; // TODO: what's this item? action += "&msgs_recv=" + utils::conversion::to_string(&this->chat_msgs_recv_, UTILS_CONV_UNSIGNED_NUMBER); - // TODO: sometimes there is &tur=1697 and &qpmade=<some actual timestamp> + // TODO: sometimes there is &tur=1711 and &qpmade=<some actual timestamp> and &isq=487632 + // action += "&request_batch=1"; // it somehow batches up more responses to one - then response has special "t=batched" type and "batches" array with the data + // action += "&msgr_region=LLA"; // it was here only for first pull, same as request_batch } action += "&cap=8"; // TODO: what's this item? Sometimes it's 0, sometimes 8 @@ -1331,14 +1333,11 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin } else { data += "&message_batch[0][specific_to_list][0]=fbid:" + std::string(userId); data += "&message_batch[0][specific_to_list][1]=fbid:" + this->self_.user_id; - data += "&message_batch[0][client_thread_id]=user:" + std::string(userId); data += "&message_batch[0][other_user_fbid]=" + std::string(userId); } - data += "&message_batch[0][thread_fbid]"; data += "&message_batch[0][author]=fbid:" + this->self_.user_id; data += "&message_batch[0][author_email]"; - data += "&message_batch[0][coordinates]"; data += "&message_batch[0][timestamp]=" + utils::time::mili_timestamp(); data += "&message_batch[0][timestamp_absolute]"; data += "&message_batch[0][timestamp_relative]"; @@ -1346,6 +1345,10 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin data += "&message_batch[0][is_unread]=false"; data += "&message_batch[0][is_forward]=false"; data += "&message_batch[0][is_filtered_content]=false"; + data += "&message_batch[0][is_filtered_content_bh]=false"; + data += "&message_batch[0][is_filtered_content_account]=false"; + data += "&message_batch[0][is_filtered_content_quasar]=false"; + data += "&message_batch[0][is_filtered_content_invalid_app]=false"; data += "&message_batch[0][is_spoof_warning]=false"; data += "&message_batch[0][source]=source:chat:web"; data += "&message_batch[0][source_tags][0]=source:chat"; @@ -1366,10 +1369,9 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin data += "&message_batch[0][status]=0"; data += "&message_batch[0][offline_threading_id]"; data += "&message_batch[0][message_id]"; - data += "&message_batch[0][manual_retry_cnt]"; data += "&message_batch[0][ephemeral_ttl_mode]=0"; data += "&message_batch[0][manual_retry_cnt]=0"; - data += "&client=mercury&__a=1"; + data += "&client=mercury&__a=1&__pc=EXP1:DEFAULT"; data += "&fb_dtsg=" + this->dtsg_; data += "&__user=" + this->self_.user_id; data += "&ttstamp=" + ttstamp_; @@ -1388,7 +1390,7 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin // Remember this message id std::string mid = utils::text::source_get_value(&resp.data, 2, "\"message_id\":\"", "\""); if (mid.empty()) - mid = utils::text::source_get_value(&resp.data, 2, "\"mid\":\"", "\""); + mid = utils::text::source_get_value(&resp.data, 2, "\"mid\":\"", "\""); // TODO: This is probably not used anymore // For classic contacts remember last message id if (!parent->isChatRoom(hContact)) diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 275fedda77..1d7ab875d4 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -568,7 +568,8 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector< facebo std::string message_id = mid.as_string(); std::string message_text = body.as_string(); - std::string other_user_id = meta_["threadKey"]["otherUserFbId"].as_string(); // for whom the message is + std::string other_user_id = meta_["threadKey"]["otherUserFbId"].as_string(); // for whom the message is (probably only for single conversations) + std::string tid = meta_["threadKey"]["threadFbId"].as_string(); // this is probably only for chats // Process attachements and stickers parseAttachments2(proto, &message_text, delta_, other_user_id); // FIXME: Rework and fix parsing attachments @@ -583,23 +584,32 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector< facebo // continue; } - facebook_message* message = new facebook_message(); - message->isUnread = true; + facebook_message* message = new facebook_message(); message->isIncoming = (id != proto->facy.self_.user_id); + message->isUnread = message->isIncoming; message->message_text = message_text; message->time = utils::time::from_string(timestamp.as_string()); message->user_id = other_user_id; message->message_id = message_id; - // message->thread_id = tid.as_string(); // TODO: or if not incomming use my own id from facy.self_ ? - message->isChat = false; // FIXME: Determine whether this is chat or not - - /* if (!message->isChat && !message->isIncoming) { - message->sender_name.clear(); - message->user_id = !other_user_id.empty() ? other_user_id : proto->ThreadIDToContactID(message->thread_id); // TODO: Check if we have contact with this user_id in friendlist and otherwise do something different? - } */ + message->thread_id = tid; + message->isChat = other_user_id.empty(); // FIXME: Determine whether this is chat or not messages->push_back(message); } + else if (cls == "ReadReceipt") { + // user read message + const JSONNode &reader_ = delta_["threadKey"]["otherUserFbId"]; // who read the message + const JSONNode &time_ = delta_["actionTimestampMs"]; // when read + + if (!reader_ || !time_) + continue; + + time_t timestamp = utils::time::from_string(time_.as_string()); + MCONTACT hContact = proto->ContactIDToHContact(reader_.as_string()); + + if (hContact) + proto->facy.insert_reader(hContact, timestamp); + } else { proto->debugLogA("json::parse_messages - Unknown class '%s'", cls.c_str()); } @@ -612,53 +622,48 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector< facebo continue; std::string ev = ev_.as_string(); - if (ev == "read_receipt") { - // user read message - const JSONNode &reader_ = (*it)["reader"]; - const JSONNode &time_ = (*it)["time"]; - if (!reader_ || !time_) + if (ev == "read") { + // user read chat message + if (!proto->m_enableChat) continue; - time_t timestamp = utils::time::from_string(time_.as_string()); - MCONTACT hContact = NULL; - std::tstring reader; + const JSONNode &reader_ = (*it)["realtime_viewer_fbid"]; + const JSONNode &time_ = (*it)["timestamp"]; + if (!reader_ || !time_) + continue; std::string readerId = reader_.as_string(); - const JSONNode &threadid = (*it)["tid"]; - if (!threadid) { - // classic contact - hContact = proto->ContactIDToHContact(readerId); - } else { - // multi user chat - if (!proto->m_enableChat) - continue; - - std::string tid = threadid.as_string(); + time_t timestamp = utils::time::from_string(time_.as_string()); + std::string tid = ""; - auto itRoom = proto->facy.chat_rooms.find(tid); - if (itRoom != proto->facy.chat_rooms.end()) { - facebook_chatroom *chatroom = itRoom->second; - std::map<std::string, std::string> participants = chatroom->participants; + const JSONNode &tids = (*it)["tids"]; + for (auto it2 = tids.begin(); it2 != tids.end(); ++it2) { + tid = (*it2).as_string(); + break; + } - auto participant = participants.find(readerId); - if (participant == participants.end()) { - // TODO: load name of this participant - std::string name = readerId; - participants.insert(std::make_pair(readerId, name)); - proto->AddChatContact(tid.c_str(), readerId.c_str(), name.c_str()); - } + auto itRoom = proto->facy.chat_rooms.find(tid); + if (itRoom != proto->facy.chat_rooms.end()) { + facebook_chatroom *chatroom = itRoom->second; + std::map<std::string, std::string> participants = chatroom->participants; + + auto participant = participants.find(readerId); + if (participant == participants.end()) { + // TODO: load name of this participant + std::string name = readerId; + participants.insert(std::make_pair(readerId, name)); + proto->AddChatContact(tid.c_str(), readerId.c_str(), name.c_str()); + } - participant = participants.find(readerId); - if (participant != participants.end()) { - // TODO: remember just reader ids to avoid eventual duplication of names - reader = _A2T(participant->second.c_str(), CP_UTF8); - hContact = proto->ChatIDToHContact(tid); - } + participant = participants.find(readerId); + if (participant != participants.end()) { + // TODO: remember just reader ids to avoid eventual duplication of names + std::tstring reader = _A2T(participant->second.c_str(), CP_UTF8); + + MCONTACT hContact = proto->ChatIDToHContact(tid); + proto->facy.insert_reader(hContact, timestamp, reader); } } - - if (hContact) - proto->facy.insert_reader(hContact, timestamp, reader); } else if (ev == "deliver") { // inbox message (multiuser or direct) |