diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-02-12 01:58:23 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-02-12 01:58:23 +0000 |
commit | f49eebc1d4c1278286afff0996a28ff8b6a3ebdf (patch) | |
tree | 88c557f1282e99f76e8d85654472070de3d42ed9 /protocols | |
parent | 33060f2573e523ed0895c17eb649acb9ee0f9f2f (diff) |
Facebook: Update some requests format, changes for stickers and new support for sending stickers (send message "[[sticker:STICKER_ID]]")
git-svn-id: http://svn.miranda-ng.org/main/trunk@16272 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/src/client.h | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 57 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 9 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 29 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 12 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 12 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 8 |
7 files changed, 86 insertions, 43 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index dbd735716d..f393aa0a67 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -158,7 +158,7 @@ public: }
std::string __inline __rev() {
- return "1911928"; // FIXME: Some version of communication protocol? On 1.9.2015 was used "1911928"
+ return "2177663"; // FIXME: Some version of communication protocol? This version is from 12.2.2015
}
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 0efc1657e8..0996625777 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -392,6 +392,11 @@ std::string facebook_client::choose_action(RequestType request_type, std::string utils::text::replace_first(&action, "%s", this->chat_reconnect_reason_); utils::text::replace_first(&action, "%s", this->dtsg_); utils::text::replace_first(&action, "%s", this->self_.user_id); + + action += "&__dyn=" + __dyn(); + action += "&__req=" + __req(); + action += "&__rev=" + __rev(); + return action; } @@ -454,11 +459,16 @@ std::string facebook_client::choose_action(RequestType request_type, std::string int idleSeconds = parent->IdleSeconds(); if (idleSeconds > 0 && !parent->isInvisible()) action += "&idle=" + utils::conversion::to_string(&idleSeconds, UTILS_CONV_UNSIGNED_NUMBER); - action += "&cap=0"; // TODO: what's this item? Sometimes it's 0, sometimes 8 - // action += "&wtc=0,0,0.000,0,0"; // TODO: what's this item? It's numbers grows with every new request... - action += "&msgs_recv=" + utils::conversion::to_string(&this->chat_msgs_recv_, UTILS_CONV_UNSIGNED_NUMBER); + 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 += "&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> + } + action += "&cap=8"; // TODO: what's this item? Sometimes it's 0, sometimes 8 action += "&uid=" + self_.user_id; action += "&viewer_uid=" + self_.user_id; @@ -488,13 +498,7 @@ std::string facebook_client::choose_action(RequestType request_type, std::string return "/ajax/mercury/change_read_status.php?__a=1"; case REQUEST_NOTIFICATIONS_READ: - { - std::string action = "/ajax/notifications/mark_read.php?__a=1"; - if (get_data != NULL) { - action += "&" + (*get_data); - } - return action; - } + return "/ajax/notifications/mark_read.php?__a=1"; case REQUEST_TYPING_SEND: return "/ajax/messaging/typ.php?__a=1"; @@ -1075,7 +1079,11 @@ bool facebook_client::chat_state(bool online) data += "&window_id=0"; data += "&fb_dtsg=" + dtsg_; data += "&__user=" + self_.user_id; - http::response resp = flap(REQUEST_VISIBILITY, &data); + data += "&__dyn=" + __dyn(); + data += "&__req=" + __req(); + data += "&ttstamp=" + ttstamp_; + data += "&__rev=" + __rev(); + http::response resp = flap(REQUEST_VISIBILITY, &data); // NOTE: Request revised 11.2.2016 if (!resp.error_title.empty()) return handle_error("chat_state"); @@ -1287,6 +1295,7 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin 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]"; @@ -1303,22 +1312,37 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin 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"; - data += "&message_batch[0][body]=" + utils::url::encode(message_text); + + // Experimental sticker sending support + if (message_text.substr(0, 10) == "[[sticker:" && message_text.substr(message_text.length() - 2) == "]]") { + data += "&message_batch[0][body]="; + data += "&message_batch[0][sticker_id]=" + utils::url::encode(message_text.substr(10, message_text.length()-10-2)); + } + else { + data += "&message_batch[0][body]=" + utils::url::encode(message_text); + } + data += "&message_batch[0][has_attachment]=false"; data += "&message_batch[0][html_body]=false"; data += "&message_batch[0][signatureID]"; data += "&message_batch[0][ui_push_phase]"; 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 += "&client=mercury&__a=1&__dyn&__req&__rev"; + data += "&message_batch[0][ephemeral_ttl_mode]=0"; + data += "&message_batch[0][manual_retry_cnt]=0"; + data += "&client=mercury&__a=1"; data += "&fb_dtsg=" + this->dtsg_; data += "&__user=" + this->self_.user_id; data += "&ttstamp=" + ttstamp_; + data += "&__dyn=" + __dyn(); + data += "&__req=" + __req(); + data += "&__rev=" + __rev(); { ScopedLock s(send_message_lock_); - resp = flap(REQUEST_MESSAGE_SEND_CHAT, &data); + resp = flap(REQUEST_MESSAGE_SEND_CHAT, &data); // NOTE: Request revised 11.2.2016 *error_text = resp.error_text; @@ -1373,7 +1397,10 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin parent->debugLogA(" Got captchaPersistData (first): %s", captchaPersistData.c_str()); std::string capStr = "new_captcha_type=TFBCaptcha&skipped_captcha_data=" + captchaPersistData; - capStr += "&__dyn=&__req=&__rev=&__user=" + this->self_.user_id; + capStr += "&__dyn=" + __dyn(); + capStr += "&__req=" + __req(); + capStr += "&__rev=" + __rev(); + capStr += "&__user=" + this->self_.user_id; http::response capResp = flap(REQUEST_CAPTCHA_REFRESH, NULL, &capStr); if (capResp.code == HTTP_CODE_OK) { diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 1105e28b58..0aec3fcaa0 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -223,7 +223,7 @@ void FacebookProto::LoadContactInfo(facebook_user* fbu) data += "&ttstamp=" + facy.ttstamp_; data += "&__rev=" + facy.__rev(); - http::response resp = facy.flap(REQUEST_USER_INFO, &data); // NOTE: Request revised 1.9.2015 + http::response resp = facy.flap(REQUEST_USER_INFO, &data); // NOTE: Request revised 11.2.2016 if (resp.code == HTTP_CODE_OK) { CODE_BLOCK_TRY @@ -288,7 +288,12 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc) // request info about thread data += "&threads[thread_ids][0]=" + thread_id; - http::response resp = facy.flap(REQUEST_THREAD_INFO, &data); // NOTE: Request revised 1.9.2015 + // TODO: ABILITY TO DEFINE TIMESTAMP! (way to load history since specific moment? ... offset seems to does nothing at all) + /* messages[user_ids][<<userid>>][offset]=11 + messages[user_ids][<<userid>>][timestamp]=1446369866009 // most recent message has this timestamp (included) + messages[user_ids][<<userid>>][limit]=20 */ + + http::response resp = facy.flap(REQUEST_THREAD_INFO, &data); // NOTE: Request revised 12.2.2016 if (resp.code != HTTP_CODE_OK) { facy.handle_error("LoadChatInfo"); diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 1978499c55..76eb2e0f49 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -106,13 +106,14 @@ int facebook_json_parser::parse_buddy_list(std::string *data, List::List< facebo } // Facebook is not sending this info anymore, it should be removed + // TODO: It is now supported to get via /ajax/mercury/tabs_presence.php request, and it is also getting through classic pull as special type of event const JSONNode &p = (*it)["p"]; if (p) { - std::string status = p["status"].as_string(); // this seems to be "active" everytime + std::string status = p["status"].as_string(); // this seems to be "active" or "invisible" or null std::string webStatus = p["webStatus"].as_string(); // "active", "idle" or "offline" - std::string fbAppStatus = p["fbAppStatus"].as_string(); // "offline" or "active" - std::string messengerStatus = p["messengerStatus"].as_string(); // "offline" or "active" - std::string otherStatus = p["otherStatus"].as_string(); // "offline" or "active" - this seems to be "active" when webStatus is "idle" or "active" only + std::string fbAppStatus = p["fbAppStatus"].as_string(); // "offline" or "active" or "invisible" or null + std::string messengerStatus = p["messengerStatus"].as_string(); // "offline" or "active" or "invisible" or null + std::string otherStatus = p["otherStatus"].as_string(); // "offline" or "active" or "invisible" or null - this seems to be "active" when webStatus is "idle" or "active" only // this may never happen if (status != "active") @@ -369,18 +370,18 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, const JSO attachments_text += "\n" + absolutizeUrl(link) + "\n"; } - // Stickers as smileys - if (proto->getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { - const JSONNode &metadata = (*itAttachment)["metadata"]; - if (metadata) { - const JSONNode &stickerId_ = metadata["stickerID"]; - if (stickerId_) { - std::string sticker = "[[sticker:" + stickerId_.as_string() + "]]\n"; - attachments_text += sticker; + const JSONNode &metadata = (*itAttachment)["metadata"]; + if (metadata) { + const JSONNode &stickerId_ = metadata["stickerID"]; + if (stickerId_) { + std::string sticker = "[[sticker:" + stickerId_.as_string() + "]]\n"; + attachments_text += sticker; - if (other_user_fbid.empty() && !thread_id.empty()) - other_user_fbid = proto->ThreadIDToContactID(thread_id); + if (other_user_fbid.empty() && !thread_id.empty()) + other_user_fbid = proto->ThreadIDToContactID(thread_id); + // Stickers as smileys + if (proto->getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { // FIXME: rewrite smileyadd to use custom smileys per protocol and not per contact and then remove this ugliness if (!other_user_fbid.empty()) { MCONTACT hContact = proto->ContactIDToHContact(other_user_fbid); diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 05659f3153..487040e331 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -165,7 +165,7 @@ void FacebookProto::SendTypingWorker(void *p) data += "&ttsamp=" + facy.ttstamp_; data += "&__rev=" + facy.__rev(); - http::response resp = facy.flap(REQUEST_TYPING_SEND, &data); // NOTE: Request revised 1.9.2015 + http::response resp = facy.flap(REQUEST_TYPING_SEND, &data); // NOTE: Request revised 11.2.2016 } delete typing; @@ -215,7 +215,11 @@ void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url, std::string b64 = ptrA(mir_base64_encode((PBYTE)sticker.c_str(), (unsigned)sticker.length())); b64 = utils::url::encode(b64); - std::tstring filename = GetAvatarFolder() + _T("\\stickers\\") + (TCHAR*)_A2T(b64.c_str()) + _T(".png"); + std::tstring filename = GetAvatarFolder() + _T("\\stickers\\"); + ptrT dir(mir_tstrdup(filename.c_str())); + + filename += (TCHAR*)_A2T(b64.c_str()); + filename += _T(".png"); // Check if we have this sticker already and download it it not if (GetFileAttributes(filename.c_str()) == INVALID_FILE_ATTRIBUTES) { @@ -227,8 +231,8 @@ void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url, SMADD_CONT cont; cont.cbSize = sizeof(SMADD_CONT); cont.hContact = hContact; - cont.type = 1; - cont.path = ptrT(mir_tstrdup(filename.c_str())); + cont.type = 0; + cont.path = dir; CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); } diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 2699aec358..eb64a99f8f 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -176,7 +176,7 @@ void FacebookProto::ProcessFriendList(void*) data += "&ttstamp=" + facy.ttstamp_; data += "&__rev=" + facy.__rev(); - http::response resp = facy.flap(REQUEST_USER_INFO_ALL, &data); // NOTE: Request revised 1.9.2015 + http::response resp = facy.flap(REQUEST_USER_INFO_ALL, &data); // NOTE: Request revised 11.2.2016 if (resp.code != HTTP_CODE_OK) { facy.handle_error("load_friends"); @@ -616,7 +616,7 @@ void FacebookProto::SyncThreads(void*) debugLogA(" Facebook's milli timestamp for sync: %s", time.c_str()); - http::response resp = facy.flap(REQUEST_THREAD_SYNC, &data); // NOTE: Request revised 1.9.2015 + http::response resp = facy.flap(REQUEST_THREAD_SYNC, &data); // NOTE: Request revised 11.2.2016 if (resp.code != HTTP_CODE_OK || resp.data.empty()) { facy.handle_error("LoadLastMessages"); @@ -1092,16 +1092,18 @@ void FacebookProto::ProcessNotifications(void*) int count = FACEBOOK_NOTIFICATIONS_LOAD_COUNT; - std::string data = "__dyn=&__req=&__rev="; - data += "&__user=" + facy.self_.user_id; + std::string data = "__user=" + facy.self_.user_id; data += "&fb_dtsg=" + facy.dtsg_; data += "&cursor="; // when loading more data += "&length=" + utils::conversion::to_string(&count, UTILS_CONV_UNSIGNED_NUMBER); // number of items to load data += "&businessID="; // probably for pages? data += "&ttstamp=" + facy.ttstamp_; + data += "&__dyn=" + facy.__dyn(); + data += "&__req=" + facy.__req(); + data += "&__rev=" + facy.__rev(); // Get notifications - http::response resp = facy.flap(REQUEST_NOTIFICATIONS, &data); + http::response resp = facy.flap(REQUEST_NOTIFICATIONS, &data); // NOTE: Request revised 11.2.2016 if (resp.code != HTTP_CODE_OK) { facy.handle_error("notifications"); diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 73b534eded..9fed01e483 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -924,12 +924,16 @@ void FacebookProto::ReadNotificationWorker(void *p) return; } - std::string data = "seen=0&asyncSignal=&__dyn=&__rev=&__req=&alert_ids%5B0%5D=" + utils::url::encode(*id); + std::string data = "alert_ids%5B0%5D=" + utils::url::encode(*id); + data += "&seen=true"; data += "&fb_dtsg=" + facy.dtsg_; data += "&__user=" + facy.self_.user_id; data += "&ttstamp=" + facy.ttstamp_; + data += "&__dyn=" + facy.__dyn(); + data += "&__req=" + facy.__req(); + data += "&__rev=" + facy.__rev(); - facy.flap(REQUEST_NOTIFICATIONS_READ, NULL, &data); + facy.flap(REQUEST_NOTIFICATIONS_READ, &data); // NOTE: Request revised 11.2.2016 delete id; } |