From 3f36fc000f39da00d7865204ba4d00e745e0b822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Mon, 22 Oct 2012 19:31:16 +0000 Subject: Facebook: Reworked sending messages requests (should avoid rare ban from FB :)) git-svn-id: http://svn.miranda-ng.org/main/trunk@2050 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/client.h | 2 +- protocols/FacebookRM/src/communication.cpp | 126 +++++++++++++++++++++-------- protocols/FacebookRM/src/constants.h | 13 ++- protocols/FacebookRM/src/messages.cpp | 8 +- 4 files changed, 108 insertions(+), 41 deletions(-) (limited to 'protocols/FacebookRM') diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 6b0f320ba7..5882c62945 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -150,7 +150,7 @@ public: // Messages handling bool channel( ); - bool send_message( std::string message_recipient, std::string message_text, std::string *error_text, bool use_inbox = false, bool is_tid = false ); + bool send_message( std::string message_recipient, std::string message_text, std::string *error_text, int method ); void close_chat( std::string message_recipient ); void chat_mark_read( std::string message_recipient ); diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 121476b7ca..3605047aa2 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -240,6 +240,7 @@ DWORD facebook_client::choose_security_level( int request_type ) // case FACEBOOK_REQUEST_RECONNECT: // case FACEBOOK_REQUEST_STATUS_SET: // case FACEBOOK_REQUEST_MESSAGE_SEND: +// case FACEBOOK_REQUEST_MESSAGE_SEND2: // case FACEBOOK_REQUEST_THREAD_INFO: // case FACEBOOK_REQUEST_MESSAGES_RECEIVE: // case FACEBOOK_REQUEST_VISIBILITY: @@ -260,6 +261,7 @@ int facebook_client::choose_method( int request_type ) case FACEBOOK_REQUEST_BUDDY_LIST: case FACEBOOK_REQUEST_STATUS_SET: case FACEBOOK_REQUEST_MESSAGE_SEND: + case FACEBOOK_REQUEST_MESSAGE_SEND2: case FACEBOOK_REQUEST_THREAD_INFO: case FACEBOOK_REQUEST_VISIBILITY: case FACEBOOK_REQUEST_TABS: @@ -322,6 +324,7 @@ std::string facebook_client::choose_server( int request_type, std::string* data, // case FACEBOOK_REQUEST_RECONNECT: // case FACEBOOK_REQUEST_STATUS_SET: // case FACEBOOK_REQUEST_MESSAGE_SEND: +// case FACEBOOK_REQUEST_MESSAGE_SEND2: // case FACEBOOK_REQUEST_THREAD_INFO: // case FACEBOOK_REQUEST_VISIBILITY: // case FACEBOOK_REQUEST_TABS: @@ -438,6 +441,9 @@ std::string facebook_client::choose_action( int request_type, std::string* data, case FACEBOOK_REQUEST_MESSAGE_SEND: return "/ajax/mercury/send_messages.php?__a=1"; + case FACEBOOK_REQUEST_MESSAGE_SEND2: + return "/ajax/messaging/send.php"; + case FACEBOOK_REQUEST_THREAD_INFO: return "/ajax/mercury/thread_info.php?__a=1"; @@ -1057,44 +1063,98 @@ bool facebook_client::channel( ) } } -bool facebook_client::send_message( std::string message_recipient, std::string message_text, std::string *error_text, bool use_inbox, bool is_tid ) +bool facebook_client::send_message( std::string message_recipient, std::string message_text, std::string *error_text, int method ) { handle_entry( "send_message" ); http::response resp; - if (is_tid) - { - std::string data = "message_batch[0][action_type]=ma-type:user-generated-message"; - data += "&message_batch[0][thread_id]=" + message_recipient; - data += "&message_batch[0][author]=fbid:" + this->self_.user_id; - data += "&message_batch[0][timestamp]=" + utils::time::mili_timestamp(); - data += "&message_batch[0][timestamp_absolute]="; - data += "&message_batch[0][timestamp_relative]="; - data += "&message_batch[0][is_unread]=false"; - data += "&message_batch[0][is_cleared]=false"; - data += "&message_batch[0][is_forward]=false"; - data += "&message_batch[0][source]=source:chat:web"; - data += "&message_batch[0][body]=" + utils::url::encode(message_text); - data += "&message_batch[0][has_attachment]=false"; - data += "&message_batch[0][is_html]=false"; - data += "&message_batch[0][message_id]="; - data += "&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0"); - data += "&__user=" + this->self_.user_id; - data += "&phstamp=0"; - - resp = flap( FACEBOOK_REQUEST_MESSAGE_SEND, &data ); - } else { - std::string data = "action=send&body="; - data += utils::url::encode( message_text ); - data += "&recipients[0]="; - data += message_recipient; - data += "&lsd=&fb_dtsg="; - data += ( dtsg_.length( )) ? dtsg_ : "0"; - data += "&post_form_id="; - data += ( post_form_id_.length( )) ? post_form_id_ : "0"; - - resp = flap( FACEBOOK_REQUEST_ASYNC, &data ); + switch (method) { + case MESSAGE_INBOX: + { + parent->Log(" > Sending message through INBOX"); + std::string data = "action=send"; + data += "&body=" + utils::url::encode( message_text ); + data += "&recipients[0]=" + message_recipient; + data += "&__user=" + this->self_.user_id; + data += "&__a=1"; + data += "&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0"); + data += "&phstamp=0"; + + resp = flap( FACEBOOK_REQUEST_MESSAGE_SEND2, &data ); + break; + } + case MESSAGE_MERCURY: + { + parent->Log(" > Sending message through CHAT"); + std::string data = "message_batch[0][action_type]=ma-type:user-generated-message"; + data += "&message_batch[0][thread_id]"; + 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]"; + data += "&message_batch[0][is_unread]=false"; + data += "&message_batch[0][is_cleared]=false"; + data += "&message_batch[0][is_forward]=false"; + data += "&message_batch[0][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); + data += "&message_batch[0][has_attachment]=false"; + data += "&message_batch[0][html_body]=false"; + data += "&message_batch[0][specific_to_list][0]=fbid:" + message_recipient; + data += "&message_batch[0][specific_to_list][1]=fbid:" + this->self_.user_id; + data += "&message_batch[0][status]=0"; + data += "&message_batch[0][message_id]"; + data += "&message_batch[0][client_thread_id]=user:" + message_recipient; + data += "&client=mercury"; + data += "&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0"); + data += "&__user=" + this->self_.user_id; + data += "&__a=1"; + data += "&phstamp=0"; + + resp = flap( FACEBOOK_REQUEST_MESSAGE_SEND, &data ); + break; + } + case MESSAGE_TID: + { + parent->Log(" > Sending message through MERCURY (TID)"); + std::string data = "message_batch[0][action_type]=ma-type:user-generated-message"; + data += "&message_batch[0][thread_id]=" + message_recipient; + data += "&message_batch[0][author]=fbid:" + this->self_.user_id; + data += "&message_batch[0][timestamp]=" + utils::time::mili_timestamp(); + data += "&message_batch[0][timestamp_absolute]="; + data += "&message_batch[0][timestamp_relative]="; + data += "&message_batch[0][is_unread]=false"; + data += "&message_batch[0][is_cleared]=false"; + data += "&message_batch[0][is_forward]=false"; + data += "&message_batch[0][source]=source:chat:web"; + data += "&message_batch[0][body]=" + utils::url::encode(message_text); + data += "&message_batch[0][has_attachment]=false"; + data += "&message_batch[0][is_html]=false"; + data += "&message_batch[0][message_id]="; + data += "&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0"); + data += "&__user=" + this->self_.user_id; + data += "&phstamp=0"; + + resp = flap( FACEBOOK_REQUEST_MESSAGE_SEND, &data ); + break; + } + case MESSAGE_ASYNC: + { + parent->Log(" > Sending message through ASYNC"); + std::string data = "action=send"; + data += "&body=" + utils::url::encode( message_text ); + data += "&recipients[0]=" + message_recipient; + data += "&lsd="; + data += "&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0"); + data += "&post_form_id=" + (post_form_id_.length() ? post_form_id_ : "0"); + + resp = flap( FACEBOOK_REQUEST_ASYNC, &data ); + break; + } } validate_response(&resp); diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 5b2ae2af20..b2b71d82ea 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -23,8 +23,8 @@ along with this program. If not, see . #pragma once // Version management -#define __VERSION_DWORD PLUGIN_MAKE_VERSION(0, 0, 9, 1) -#define __VERSION_STRING "0.0.9.1" +#define __VERSION_DWORD PLUGIN_MAKE_VERSION(0, 0, 9, 2) +#define __VERSION_STRING "0.0.9.2" // Product management #define FACEBOOK_NAME "Facebook" @@ -102,7 +102,8 @@ along with this program. If not, see . #define FACEBOOK_REQUEST_RECONNECT 130 // getting __sequence_num__ and __channel_id__ #define FACEBOOK_REQUEST_STATUS_SET 251 // setting my "What's on my mind?" #define FACEBOOK_REQUEST_MESSAGE_SEND 300 // sending message -#define FACEBOOK_REQUEST_MESSAGES_RECEIVE 301 // receiving messages +#define FACEBOOK_REQUEST_MESSAGE_SEND2 301 // sending message through inbox +#define FACEBOOK_REQUEST_MESSAGES_RECEIVE 302 // receiving messages #define FACEBOOK_REQUEST_TYPING_SEND 304 // sending typing notification #define FACEBOOK_REQUEST_VISIBILITY 305 // setting chat visibility #define FACEBOOK_REQUEST_TABS 306 // closing message window @@ -112,6 +113,12 @@ along with this program. If not, see . #define FACEBOOK_RECV_MESSAGE 1 #define FACEBOOK_SEND_MESSAGE 2 +// Send message types +#define MESSAGE_INBOX 0 +#define MESSAGE_MERCURY 1 +#define MESSAGE_TID 2 +#define MESSAGE_ASYNC 3 + // Contact types #define FACEBOOK_CONTACT_FRIEND 1 // contact that IS on our server list #define FACEBOOK_CONTACT_NONE 2 // contact that ISN'T on our server list diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 8b27b4721f..596fab0424 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -58,7 +58,7 @@ void FacebookProto::SendMsgWorker(void *p) std::string error_text = ""; bool result = false; while (!result && retries > 0) { - result = facy.send_message(dbv.pszVal, data->msg, &error_text, retries % 2 == 0 ); + result = facy.send_message(dbv.pszVal, data->msg, &error_text, retries % 2 == 0 ? MESSAGE_INBOX : MESSAGE_MERCURY); retries--; } if (result) { @@ -104,7 +104,7 @@ void FacebookProto::SendChatMsgWorker(void *p) } if (!tid.empty()) - facy.send_message(tid, data->msg, &err_message, false, true ); + facy.send_message(tid, data->msg, &err_message, MESSAGE_TID); } delete data; @@ -117,14 +117,14 @@ int FacebookProto::SendMsg(HANDLE hContact, int flags, const char *msg) msg = mir_utf8encode(msg); facy.msgid_ = (facy.msgid_ % 1024)+1; - ForkThread( &FacebookProto::SendMsgWorker, this,new send_direct(hContact,msg,(HANDLE)facy.msgid_)); + ForkThread( &FacebookProto::SendMsgWorker, this, new send_direct(hContact, msg, (HANDLE)facy.msgid_)); return facy.msgid_; } int FacebookProto::UserIsTyping(HANDLE hContact,int type) { if (hContact && isOnline()) - ForkThread(&FacebookProto::SendTypingWorker, this,new send_typing(hContact,type)); + ForkThread(&FacebookProto::SendTypingWorker, this, new send_typing(hContact, type)); return 0; } -- cgit v1.2.3