diff options
author | Robert Pösel <robyer@seznam.cz> | 2015-02-07 08:43:52 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2015-02-07 08:43:52 +0000 |
commit | 9fe7b9187d30041071ceebb4daf69cca38900b09 (patch) | |
tree | 7fe2efab376aed3ae7375e1017a2a0f05d52e515 /protocols/FacebookRM/src | |
parent | bca544e48bda364d28bf3d732e0b578683870ebf (diff) |
Facebook: Implement and use activity_ping request
Maybe it's not needed at all, but maybe it will help something :)
git-svn-id: http://svn.miranda-ng.org/main/trunk@12037 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r-- | protocols/FacebookRM/src/client.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 42 | ||||
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 7 | ||||
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 1 |
6 files changed, 51 insertions, 8 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index f26ab107ee..6022cd5dca 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -186,6 +186,7 @@ public: std::map<int, time_t> messages_timestamp;
bool channel();
+ bool activity_ping();
int send_message(int seqid, MCONTACT, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captchaPersistData = "", const std::string &captcha = "");
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 2399dbfad7..27e8009f18 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -3,7 +3,7 @@ Facebook plugin for Miranda Instant Messenger _____________________________________________ -Copyright � 2009-11 Michal Zelinka, 2011-15 Robert P�sel +Copyright © 2009-11 Michal Zelinka, 2011-15 Robert Pösel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -206,7 +206,7 @@ bool facebook_client::handle_error(const std::string &method, int action) DWORD facebook_client::choose_security_level(RequestType request_type) { if (this->https_) - if (request_type != REQUEST_MESSAGES_RECEIVE || parent->getByte(FACEBOOK_KEY_FORCE_HTTPS_CHANNEL, DEFAULT_FORCE_HTTPS_CHANNEL)) + if ((request_type != REQUEST_MESSAGES_RECEIVE && request_type != REQUEST_ACTIVE_PING) || parent->getByte(FACEBOOK_KEY_FORCE_HTTPS_CHANNEL, DEFAULT_FORCE_HTTPS_CHANNEL)) return NLHRF_SSL; switch (request_type) { @@ -241,6 +241,7 @@ DWORD facebook_client::choose_security_level(RequestType request_type) // case REQUEST_THREAD_INFO: // case REQUEST_THREAD_SYNC: // case REQUEST_MESSAGES_RECEIVE: + // case REQUEST_ACTIVE_PING: // case REQUEST_VISIBILITY: // case REQUEST_POKE: // case REQUEST_ASYNC: @@ -284,6 +285,7 @@ int facebook_client::choose_method(RequestType request_type) // case REQUEST_HOME: // case REQUEST_DTSG: // case REQUEST_MESSAGES_RECEIVE: + // case REQUEST_ACTIVE_PING: // case REQUEST_FEEDS: // case REQUEST_PAGES: // case REQUEST_NOTIFICATIONS: @@ -315,6 +317,7 @@ std::string facebook_client::choose_server(RequestType request_type) return FACEBOOK_SERVER_LOGIN; case REQUEST_MESSAGES_RECEIVE: + case REQUEST_ACTIVE_PING: { std::string server = FACEBOOK_SERVER_CHAT; utils::text::replace_first(&server, "%s", this->chat_conn_num_.empty() ? "0" : this->chat_conn_num_); @@ -528,16 +531,21 @@ std::string facebook_client::choose_action(RequestType request_type, std::string return "/ajax/mercury/thread_sync.php"; case REQUEST_MESSAGES_RECEIVE: + case REQUEST_ACTIVE_PING: { - std::string action = "/pull?channel=" + (this->chat_channel_.empty() ? "p_" + self_.user_id : this->chat_channel_); - action += "&seq=" + (this->chat_sequence_num_.empty() ? "0" : this->chat_sequence_num_); + bool isPing = (request_type == REQUEST_ACTIVE_PING); + + std::string action = (isPing ? "/active_ping" : "/pull"); + action += "?channel=" + (this->chat_channel_.empty() ? "p_" + self_.user_id : this->chat_channel_); + if (!isPing) + action += "&seq=" + (this->chat_sequence_num_.empty() ? "0" : this->chat_sequence_num_); action += "&partition=" + (this->chat_channel_partition_.empty() ? "0" : this->chat_channel_partition_); action += "&clientid=" + this->chat_clientid_; action += "&cb=" + utils::text::rand_string(4, "0123456789abcdefghijklmnopqrstuvwxyz"); int idleSeconds = parent->IdleSeconds(); action += "&idle=" + utils::conversion::to_string(&idleSeconds, UTILS_CONV_UNSIGNED_NUMBER); - action += "&cap=0"; + action += "&cap=0"; // TODO: what's this item? // action += "&wtc=0,0,0.000,0,0"; // TODO: what's this item? It's numbers grows with every new request... action += "&uid=" + self_.user_id; @@ -549,12 +557,12 @@ std::string facebook_client::choose_action(RequestType request_type, std::string if (!this->chat_sticky_pool_.empty()) action += "&sticky_pool=" + this->chat_sticky_pool_; - if (!this->chat_traceid_.empty()) + if (!isPing && !this->chat_traceid_.empty()) action += "&traceid=" + this->chat_traceid_; if (parent->isInvisible()) action += "&state=offline"; - else if (idleSeconds < 60) + else if (isPing || idleSeconds < 60) action += "&state=active"; return action; @@ -1145,6 +1153,9 @@ bool facebook_client::reconnect() //std::string visibility = utils::text::source_get_value2(&resp.data, "\"visibility\":", ",}"); //parent->debugLogA(" Got self visibility: %s", visibility.c_str()); + // Send activity_ping after each reconnect + activity_ping(); + return handle_success("reconnect"); } @@ -1229,6 +1240,23 @@ bool facebook_client::channel() } } +bool facebook_client::activity_ping() +{ + handle_entry("activity_ping"); + + http::response resp = flap(REQUEST_ACTIVE_PING); + + // Remember this last ping time + parent->m_pingTS = ::time(NULL); + + if (resp.data.empty() || resp.data.find("\"t\":\"pong\"") == resp.data.npos) { + // Something went wrong + return handle_error("activity_ping"); + } + + return handle_success("activity_ping"); +} + int facebook_client::send_message(int seqid, MCONTACT hContact, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captcha_persist_data, const std::string &captcha) { ScopedLock s(send_message_lock_); diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index b256e9ae9f..2ccc754c76 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -231,6 +231,13 @@ void FacebookProto::MessageLoop(void *) { if (isOffline() || m_signingOut) break; + + // If we're not idle, send activity_ping every few minutes... + if (!m_idleTS && (::time(NULL) - m_pingTS) > FACEBOOK_PING_TIME) { + debugLogA("***** FacebookProto::MessageLoop[%d] pinging...", tim); + facy.activity_ping(); + } + debugLogA("***** FacebookProto::MessageLoop[%d] refreshing...", tim); } diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index f046b785a6..c2b892e954 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -62,6 +62,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define FACEBOOK_MESSAGES_ON_OPEN_LIMIT 99
#define FACEBOOK_TYPING_TIME 60
#define FACEBOOK_IGNORE_COUNTER_LIMIT 5 // how many consequent requests it should keep info about duplicit message ids
+#define FACEBOOK_PING_TIME 600 // every 10 minutes send activity_ping (it is just random/guessed value)
// Defaults
#define FACEBOOK_MINIMAL_POLL_RATE 10
@@ -144,7 +145,8 @@ enum RequestType { REQUEST_MESSAGE_SEND_CHAT, // sending message through chat
REQUEST_MESSAGE_SEND_INBOX, // sending message through inbox
- REQUEST_MESSAGES_RECEIVE, // receiving messages
+ REQUEST_MESSAGES_RECEIVE, // receiving messages and other realtime actions
+ REQUEST_ACTIVE_PING, // sending activity ping
REQUEST_TYPING_SEND, // sending typing notification
REQUEST_THREAD_INFO, // getting thread info
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 561313a2f6..0626e0d677 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -44,6 +44,7 @@ FacebookProto::FacebookProto(const char* proto_name, const TCHAR* username) : m_signingOut = false; m_enableChat = DEFAULT_ENABLE_CHATS; m_idleTS = 0; + m_pingTS = 0; // Load custom locale, if set ptrA locale(getStringA(FACEBOOK_KEY_LOCALE)); @@ -413,6 +414,9 @@ int FacebookProto::OnIdleChanged(WPARAM wParam, LPARAM lParam) // User stopped being idle m_idleTS = 0; delSetting("IdleTS"); + + // Set sending activity_ping at next channel request (because I don't want to create new thread here for such small thing) + m_pingTS = 0; } return 0; diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index fec92279d2..51a9bba0ee 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -60,6 +60,7 @@ public: bool m_enableChat; bool m_signingOut; time_t m_idleTS; + time_t m_pingTS; std::string m_locale; // DB utils missing in proto_interface |