summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2012-06-11 13:32:53 +0000
committerRobert Pösel <robyer@seznam.cz>2012-06-11 13:32:53 +0000
commit50017f9b1e19f8a89aad7c4b68e1f58f81045dad (patch)
tree3d28ad857ce2b596788776a6ae11f59b680f7d35 /protocols/FacebookRM
parent26791cc7ee10c73b00df9cc3cc38ff7ba06d8102 (diff)
FacebookRM sync.
git-svn-id: http://svn.miranda-ng.org/main/trunk@387 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/client.h2
-rw-r--r--protocols/FacebookRM/communication.cpp98
-rw-r--r--protocols/FacebookRM/constants.h5
-rw-r--r--protocols/FacebookRM/contacts.cpp25
-rw-r--r--protocols/FacebookRM/db.h1
-rw-r--r--protocols/FacebookRM/facebook.rc8
-rw-r--r--protocols/FacebookRM/messages.cpp25
-rw-r--r--protocols/FacebookRM/proto.h1
8 files changed, 110 insertions, 55 deletions
diff --git a/protocols/FacebookRM/client.h b/protocols/FacebookRM/client.h
index 40555c2dfc..b4874de23b 100644
--- a/protocols/FacebookRM/client.h
+++ b/protocols/FacebookRM/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 send_message( std::string message_recipient, std::string message_text, std::string *error_text, bool use_inbox = false, bool is_tid = false );
void close_chat( std::string message_recipient );
void chat_mark_read( std::string message_recipient );
diff --git a/protocols/FacebookRM/communication.cpp b/protocols/FacebookRM/communication.cpp
index d9d93632e7..4afb031cac 100644
--- a/protocols/FacebookRM/communication.cpp
+++ b/protocols/FacebookRM/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_THREAD_INFO:
// case FACEBOOK_REQUEST_MESSAGES_RECEIVE:
// case FACEBOOK_REQUEST_VISIBILITY:
// case FACEBOOK_REQUEST_TABS:
@@ -259,6 +260,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_THREAD_INFO:
case FACEBOOK_REQUEST_VISIBILITY:
case FACEBOOK_REQUEST_TABS:
case FACEBOOK_REQUEST_ASYNC:
@@ -323,6 +325,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_THREAD_INFO:
// case FACEBOOK_REQUEST_VISIBILITY:
// case FACEBOOK_REQUEST_TABS:
// case FACEBOOK_REQUEST_ASYNC:
@@ -436,7 +439,10 @@ std::string facebook_client::choose_action( int request_type, std::string* data,
return "/ajax/updatestatus.php?__a=1";
case FACEBOOK_REQUEST_MESSAGE_SEND:
- return "/ajax/messaging/send.php?__a=1";
+ return "/ajax/mercury/send_messages.php?__a=1";
+
+ case FACEBOOK_REQUEST_THREAD_INFO:
+ return "/ajax/mercury/thread_info.php?__a=1";
case FACEBOOK_REQUEST_MESSAGES_RECEIVE:
{
@@ -611,7 +617,26 @@ bool facebook_client::login(const std::string &username,const std::string &passw
{
resp = flap( FACEBOOK_REQUEST_SETUP_MACHINE );
- std::string inner_data = "machine_name=MirandaIM&submit[Save%20Device]=Save%20Device";
+ std::string inner_data;
+ if (resp.data.find("name=\"submit[Continue]\"") != std::string::npos) {
+ // Multi step with approving last unrecognized device
+ // 1) Continue
+ inner_data = "submit[Continue]=Continue";
+ inner_data += "&lsd=" + utils::text::source_get_value(&resp.data, 3, "name=\"lsd\"", "value=\"", "\"" );
+ inner_data += "&nh=" + utils::text::source_get_value(&resp.data, 3, "name=\"nh\"", "value=\"", "\"" );
+ resp = flap( FACEBOOK_REQUEST_SETUP_MACHINE, &inner_data );
+
+ // 2) Approve last unknown login
+ // inner_data = "submit[I%20don't%20recognize]=I%20don't%20recognize"; // Don't recognize - this will force to change account password
+ inner_data = "submit[This%20is%20Okay]=This%20is%20Okay"; // Recognize
+ inner_data += "&lsd=" + utils::text::source_get_value(&resp.data, 3, "name=\"lsd\"", "value=\"", "\"" );
+ inner_data += "&nh=" + utils::text::source_get_value(&resp.data, 3, "name=\"nh\"", "value=\"", "\"" );
+ resp = flap( FACEBOOK_REQUEST_SETUP_MACHINE, &inner_data );
+ }
+
+ // Save actual machine name
+ // inner_data = "machine_name=Miranda%20IM&submit[Don't%20Save]=Don't%20Save"; // Don't save
+ inner_data = "machine_name=Miranda%20IM&submit[Save%20Device]=Save%20Device"; // Save
inner_data += "&post_form_id=" + utils::text::source_get_value(&resp.data, 3, "name=\"post_form_id\"", "value=\"", "\"" );
inner_data += "&lsd=" + utils::text::source_get_value(&resp.data, 3, "name=\"lsd\"", "value=\"", "\"" );
inner_data += "&nh=" + utils::text::source_get_value(&resp.data, 3, "name=\"nh\"", "value=\"", "\"" );
@@ -1054,14 +1079,34 @@ 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 facebook_client::send_message( std::string message_recipient, std::string message_text, std::string *error_text, bool use_inbox, bool is_tid )
{
handle_entry( "send_message" );
http::response resp;
-// if (parent->isInvisible() || use_inbox) {
- // Use inbox send message when invisible
+ 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]=";
@@ -1072,48 +1117,7 @@ bool facebook_client::send_message( std::string message_recipient, std::string m
data += ( post_form_id_.length( ) ) ? post_form_id_ : "0";
resp = flap( FACEBOOK_REQUEST_ASYNC, &data );
-/* } else {
- // Use standard send message
- std::string timestamp = utils::time::mili_timestamp();
-
- std::string data = "mid=id." + timestamp;
-
- //data += "&tids[0]=";
-/* data += "&last_msg[subject]&last_msg[body]=" + utils::url::encode( message_text );
- data += "&last_msg[timestamp]=" + timestamp;
- data += "&last_msg[mid]=id." + timestamp;
- //data += "&last_msg[tid]=";
- data += "&last_msg[sender_fbid]=" + this->self_.user_id;
- data += "&last_msg[offline_threading_id]&last_msg[sender]=Robyer%40facebook.com&last_msg[sender_name]=Robert%20P%C3%B6sel"
- data += "&last_msg[tags]=source%3Atitan%3Aweb%2Cinbox&last_msg[source]=source%3Atitan%3Aweb&&last_msg[forward]=0&last_msg[replyActionType]=0&last_msg[coordinates]&last_msg[action_id]=0";
-*/ /*
- data += "&mode=2&gigaboxx_reply=&&body=" + utils::url::encode(message_text);
- data += "&action=send&force_sms&send_on_enter=true&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0");
- data += "&__user=" + this->self_.user_id;
- data += "&phstamp=0";
-
- std::string data = "msg_text=";
- data += utils::url::encode( message_text );
- data += "&msg_id=";
- data += utils::time::mili_timestamp( );
- data += "%3A";
- data += utils::time::unix_timestamp( );
- data += "&to=";
- data += message_recipient;
- data += "&__user=";
- data += this->self_.user_id;
- data += "&client_time=";
- data += utils::time::mili_timestamp( );
- data += "&pvs_time&fb_dtsg=";
- data += ( dtsg_.length( ) ) ? dtsg_ : "0";
- data += "&to_offline=false&to_idle=false&lsd&post_form_id_source=AsyncRequest&num_tabs=1";
- data += "&window_id=0&sidebar_launched=false&sidebar_enabled=false&sidebar_capable=false&sidebar_should_show=false&sidebar_visible=false";
- data += "&post_form_id=";
- data += ( post_form_id_.length( ) ) ? post_form_id_ : "0";
-
- resp = flap( FACEBOOK_REQUEST_MESSAGE_SEND, &data );
- }*/
-
+ }
validate_response(&resp);
*error_text = resp.error_text;
diff --git a/protocols/FacebookRM/constants.h b/protocols/FacebookRM/constants.h
index 8662c7c145..30f65b9df3 100644
--- a/protocols/FacebookRM/constants.h
+++ b/protocols/FacebookRM/constants.h
@@ -23,8 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
// Version management
-#define __VERSION_DWORD PLUGIN_MAKE_VERSION(0, 0, 8, 1)
-#define __VERSION_STRING "0.0.8.1"
+#define __VERSION_DWORD PLUGIN_MAKE_VERSION(0, 0, 9, 0)
+#define __VERSION_STRING "0.0.9.0"
// Product management
#define FACEBOOK_NAME "Facebook"
@@ -108,6 +108,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_REQUEST_VISIBILITY 305 // setting chat visibility
#define FACEBOOK_REQUEST_TABS 306 // closing message window
#define FACEBOOK_REQUEST_ASYNC 307 // marking messages read and getting other things
+#define FACEBOOK_REQUEST_THREAD_INFO 310 // getting thread info
#define FACEBOOK_RECV_MESSAGE 1
#define FACEBOOK_SEND_MESSAGE 2
diff --git a/protocols/FacebookRM/contacts.cpp b/protocols/FacebookRM/contacts.cpp
index 66c1c3cacd..32cc1ce269 100644
--- a/protocols/FacebookRM/contacts.cpp
+++ b/protocols/FacebookRM/contacts.cpp
@@ -38,6 +38,31 @@ bool FacebookProto::IsMyContact(HANDLE hContact, bool include_chat)
}
}
+HANDLE FacebookProto::ChatIDToHContact(std::string chat_id)
+{
+ for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ hContact;
+ hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0) )
+ {
+ if(!IsMyContact(hContact, true))
+ continue;
+
+ DBVARIANT dbv;
+ if( !DBGetContactSettingString(hContact,m_szModuleName,"ChatRoomID",&dbv) )
+ {
+ if( strcmp(chat_id.c_str(),dbv.pszVal) == 0 )
+ {
+ DBFreeVariant(&dbv);
+ return hContact;
+ } else {
+ DBFreeVariant(&dbv);
+ }
+ }
+ }
+
+ return 0;
+}
+
HANDLE FacebookProto::ContactIDToHContact(std::string user_id)
{
for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
diff --git a/protocols/FacebookRM/db.h b/protocols/FacebookRM/db.h
index c397522f3c..a58904fee5 100644
--- a/protocols/FacebookRM/db.h
+++ b/protocols/FacebookRM/db.h
@@ -40,6 +40,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// DB keys
#define FACEBOOK_KEY_LOGIN "Email"
#define FACEBOOK_KEY_ID "ID"
+#define FACEBOOK_KEY_TID "ThreadID"
#define FACEBOOK_KEY_NAME "RealName"
#define FACEBOOK_KEY_NICK "Nick"
#define FACEBOOK_KEY_PASS "Password"
diff --git a/protocols/FacebookRM/facebook.rc b/protocols/FacebookRM/facebook.rc
index ae7489daa4..0c46928c8c 100644
--- a/protocols/FacebookRM/facebook.rc
+++ b/protocols/FacebookRM/facebook.rc
@@ -256,8 +256,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,0,8,1
- PRODUCTVERSION 0,9,43,0
+ FILEVERSION 0,0,9,0
+ PRODUCTVERSION 0,0,9,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -273,12 +273,12 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Facebook protocol plugin for Miranda IM"
- VALUE "FileVersion", "0.0.8.1"
+ VALUE "FileVersion", "0.0.9.0"
VALUE "InternalName", "Facebook RM"
VALUE "LegalCopyright", "Copyright © 2009-2011 Michal Zelinka, 2011-2012 Robert Pösel"
VALUE "OriginalFilename", "facebook.dll"
VALUE "ProductName", "Facebook Protocol RM"
- VALUE "ProductVersion", "0.9.43.0"
+ VALUE "ProductVersion", "0.0.9.0"
END
END
BLOCK "VarFileInfo"
diff --git a/protocols/FacebookRM/messages.cpp b/protocols/FacebookRM/messages.cpp
index 9725ec40c9..def7a6b64b 100644
--- a/protocols/FacebookRM/messages.cpp
+++ b/protocols/FacebookRM/messages.cpp
@@ -83,7 +83,30 @@ void FacebookProto::SendChatMsgWorker(void *p)
send_chat *data = static_cast<send_chat*>(p);
std::string err_message = "";
- facy.send_message(data->chat_id, data->msg, &err_message, false );
+ HANDLE hContact = ChatIDToHContact(data->chat_id);
+ if (hContact) {
+ std::string tid;
+ DBVARIANT dbv;
+ if (!DBGetContactSettingString(hContact, m_szModuleName, FACEBOOK_KEY_TID, &dbv)) {
+ tid = dbv.pszVal;
+ DBFreeVariant(&dbv);
+ } else {
+ std::string post_data = "threads[group_ids][0]=" + data->chat_id;
+ post_data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0");
+ post_data += "&__user=" + facy.self_.user_id;
+ post_data += "&phstamp=0";
+
+ http::response resp = facy.flap( FACEBOOK_REQUEST_THREAD_INFO, &post_data );
+ facy.validate_response(&resp);
+
+ tid = utils::text::source_get_value(&resp.data, 2, "\"thread_id\":\"", "\"");
+ DBWriteContactSettingString(hContact, m_szModuleName, FACEBOOK_KEY_TID, tid.c_str());
+ Log(" Got thread info: %s = %s", data->chat_id.c_str(), tid.c_str());
+ }
+
+ if (!tid.empty())
+ facy.send_message(tid, data->msg, &err_message, false, true );
+ }
delete data;
}
diff --git a/protocols/FacebookRM/proto.h b/protocols/FacebookRM/proto.h
index 6d956b0db9..f04f59937c 100644
--- a/protocols/FacebookRM/proto.h
+++ b/protocols/FacebookRM/proto.h
@@ -168,6 +168,7 @@ public:
// Contacts handling
bool IsMyContact(HANDLE, bool include_chat = false);
HANDLE ContactIDToHContact(std::string);
+ HANDLE ChatIDToHContact(std::string);
HANDLE AddToContactList(facebook_user*, BYTE type, bool dont_check = false, const char *new_name = "");
void SetAllContactStatuses(int);
HANDLE HContactFromAuthEvent(HANDLE hEvent);