diff options
Diffstat (limited to 'protocols/FacebookRM/src/channel.cpp')
-rw-r--r-- | protocols/FacebookRM/src/channel.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/protocols/FacebookRM/src/channel.cpp b/protocols/FacebookRM/src/channel.cpp new file mode 100644 index 0000000000..9498209ff2 --- /dev/null +++ b/protocols/FacebookRM/src/channel.cpp @@ -0,0 +1,77 @@ +/* + +Facebook plugin for Miranda Instant Messenger +_____________________________________________ + +Copyright © 2011-17 Robert Pösel, 2017-18 Miranda NG team + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "stdafx.h" + +///////////////////////////////////////////////////////////////////////////////////////// +// receiving updates, sending activity ping + +ChannelRequest::ChannelRequest(facebook_client *fc, Type type) : + HttpRequest(REQUEST_POST, FORMAT, + type == PULL ? FACEBOOK_SERVER_CHAT "/pull" : FACEBOOK_SERVER_CHAT "/active_ping", + fc->chat_conn_num_.empty() ? "0" : fc->chat_conn_num_.c_str(), + fc->chat_channel_host_.c_str()) +{ + if (type == PULL) { + timeout = 65 * 1000; + Persistent = CHANNEL; + } + + bool isPing = (type == PING); + + Url << CHAR_PARAM("channel", fc->chat_channel_.empty() ? ("p_" + fc->self_.user_id).c_str() : fc->chat_channel_.c_str()); + if (!isPing) + Url << CHAR_PARAM("seq", fc->chat_sequence_num_.empty() ? "0" : fc->chat_sequence_num_.c_str()); + + Url + << CHAR_PARAM("partition", fc->chat_channel_partition_.empty() ? "0" : fc->chat_channel_partition_.c_str()) + << CHAR_PARAM("clientid", fc->chat_clientid_.c_str()) + << CHAR_PARAM("cb", utils::text::rand_string(4, "0123456789abcdefghijklmnopqrstuvwxyz", &fc->random_).c_str()); + + int idleSeconds = fc->parent->IdleSeconds(); + Url << INT_PARAM("idle", idleSeconds); // Browser is sending "idle" always, even if it's "0" + + if (!isPing) { + Url << CHAR_PARAM("qp", "y") << CHAR_PARAM("pws", "fresh") << INT_PARAM("isq", 487632); + Url << INT_PARAM("msgs_recv", fc->chat_msgs_recv_); + // TODO: sometimes there is &tur=1711 and &qpmade=<some actual timestamp> and &isq=487632 + // Url << "request_batch=1"; // it somehow batches up more responses to one - then response has special "t=batched" type and "batches" array with the data + // Url << "msgr_region=LLA"; // it was here only for first pull, same as request_batch + } + + Url << INT_PARAM("cap", 8) // TODO: what's this item? Sometimes it's 0, sometimes 8 + << CHAR_PARAM("uid", fc->self_.user_id.c_str()) + << CHAR_PARAM("viewer_uid", fc->self_.user_id.c_str()); + + if (!fc->chat_sticky_num_.empty() && !fc->chat_sticky_pool_.empty()) { + Url << CHAR_PARAM("sticky_token", fc->chat_sticky_num_.c_str()); + Url << CHAR_PARAM("sticky_pool", fc->chat_sticky_pool_.c_str()); + } + + if (!isPing && !fc->chat_traceid_.empty()) + Url << CHAR_PARAM("traceid", fc->chat_traceid_.c_str()); + + if (fc->parent->isInvisible()) + Url << CHAR_PARAM("state", "offline"); + else if (isPing || idleSeconds < 60) + Url << CHAR_PARAM("state", "active"); +} |