diff options
author | Robert Pösel <robyer@seznam.cz> | 2012-11-03 19:03:28 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2012-11-03 19:03:28 +0000 |
commit | f1c8069fba15a042ba2824ee6dc48a891f8ccd2d (patch) | |
tree | d2d36917a46892184facda5bd59efecf8222ed59 /protocols/FacebookRM | |
parent | 31b191bc8ddb639e488ab8306f71ac1dbabf16f0 (diff) |
Facebook:
- use homepage from mobile facebook = much faster (and smaller ;)) logging in
- always getting unread messages (not "experimental" anymore)
git-svn-id: http://svn.miranda-ng.org/main/trunk@2168 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 96 | ||||
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 18 | ||||
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 7 | ||||
-rw-r--r-- | protocols/FacebookRM/src/theme.cpp | 18 |
4 files changed, 49 insertions, 90 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 3605047aa2..43d9cf127e 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -227,6 +227,7 @@ DWORD facebook_client::choose_security_level( int request_type ) // case FACEBOOK_REQUEST_LOGOUT:
// case FACEBOOK_REQUEST_HOME:
+// case FACEBOOK_REQUEST_DTSG:
// case FACEBOOK_REQUEST_BUDDY_LIST:
// case FACEBOOK_REQUEST_LOAD_FRIENDS:
// case FACEBOOK_REQUEST_LOAD_REQUESTS:
@@ -275,6 +276,7 @@ int facebook_client::choose_method( int request_type ) return REQUEST_POST;
// case FACEBOOK_REQUEST_HOME:
+// case FACEBOOK_REQUEST_DTSG:
// case FACEBOOK_REQUEST_MESSAGES_RECEIVE:
// case FACEBOOK_REQUEST_FEEDS:
// case FACEBOOK_REQUEST_NOTIFICATIONS:
@@ -310,13 +312,14 @@ std::string facebook_client::choose_server( int request_type, std::string* data, return server;
}
+ case FACEBOOK_REQUEST_HOME:
+ case FACEBOOK_REQUEST_DTSG:
case FACEBOOK_REQUEST_APPROVE_FRIEND:
case FACEBOOK_REQUEST_LOAD_REQUESTS:
case FACEBOOK_REQUEST_SEARCH:
return FACEBOOK_SERVER_MOBILE;
// case FACEBOOK_REQUEST_LOGOUT:
-// case FACEBOOK_REQUEST_HOME:
// case FACEBOOK_REQUEST_BUDDY_LIST:
// case FACEBOOK_REQUEST_LOAD_FRIENDS:
// case FACEBOOK_REQUEST_FEEDS:
@@ -353,7 +356,10 @@ std::string facebook_client::choose_action( int request_type, std::string* data, return "/logout.php";
case FACEBOOK_REQUEST_HOME:
- return "/home.php?_fb_noscript=1";
+ return "/profile.php?v=edit";
+
+ case FACEBOOK_REQUEST_DTSG:
+ return "/editprofile.php?edit=current_city&type=basic";
case FACEBOOK_REQUEST_BUDDY_LIST:
return "/ajax/chat/buddy_list.php?__a=1";
@@ -754,7 +760,17 @@ bool facebook_client::home( ) {
handle_entry( "home" );
- http::response resp = flap( FACEBOOK_REQUEST_HOME );
+
+ // get fb_dtsg
+ http::response resp = flap( FACEBOOK_REQUEST_DTSG );
+
+ this->dtsg_ = utils::text::source_get_value( &resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\"" );
+ parent->Log(" Got self dtsg: %s", this->dtsg_.c_str());
+
+ if (this->dtsg_.empty())
+ return false;
+
+ resp = flap( FACEBOOK_REQUEST_HOME );
// Process result data
validate_response(&resp);
@@ -763,18 +779,11 @@ bool facebook_client::home( ) {
case HTTP_CODE_OK:
{
- if ( resp.data.find( "id=\"navAccountName\"" ) != std::string::npos )
- { // Backup for old fb version
- // Get real_name
- this->self_.real_name = utils::text::remove_html( utils::text::special_expressions_decode( utils::text::source_get_value( &resp.data, 2, " id=\"navAccountName\">", "</a" )) );
- DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NAME,this->self_.real_name.c_str());
- DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NICK,this->self_.real_name.c_str());
- parent->Log(" Got self real name: %s", this->self_.real_name.c_str());
- } else if ( resp.data.find("id=\"pageNav\"") != std::string::npos ) {
- // Get real_name
- this->self_.real_name = utils::text::remove_html( utils::text::special_expressions_decode( utils::text::source_get_value( &resp.data, 3, " class=\"headerTinymanName\"", ">", "</a" )) );
- DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NAME,this->self_.real_name.c_str());
- DBWriteContactSettingUTF8String(NULL,parent->m_szModuleName,FACEBOOK_KEY_NICK,this->self_.real_name.c_str());
+ // Get real_name
+ this->self_.real_name = utils::text::source_get_value( &resp.data, 2, "<strong class=\"profileName\">", "</strong>" );
+ if (!this->self_.real_name.empty()) {
+ DBWriteContactSettingUTF8String(NULL, parent->m_szModuleName, FACEBOOK_KEY_NAME, this->self_.real_name.c_str());
+ DBWriteContactSettingUTF8String(NULL, parent->m_szModuleName, FACEBOOK_KEY_NICK, this->self_.real_name.c_str());
parent->Log(" Got self real name: %s", this->self_.real_name.c_str());
} else {
client_notify(TranslateT("Something happened to Facebook. Maybe there was some major update so you should wait for an update."));
@@ -782,67 +791,14 @@ bool facebook_client::home( ) }
// Get avatar
- std::string avatar = utils::text::source_get_value( &resp.data, 4, "fbxWelcomeBoxImg", "src=", "\"", "\"" );
- if (avatar[avatar.length()-1] == '\\')
- avatar = avatar.substr(0, avatar.length()-1);
-
- this->self_.image_url = utils::text::trim( utils::text::special_expressions_decode( avatar ));
+ this->self_.image_url = utils::text::source_get_value( &resp.data, 4, "<i class=", "profpic", "<img src=\"", "\"" );
parent->Log(" Got self avatar: %s", this->self_.image_url.c_str());
parent->CheckAvatarChange(NULL, this->self_.image_url);
- // Get post_form_id
- this->post_form_id_ = utils::text::source_get_value( &resp.data, 3, "name=\"post_form_id\"", "value=\"", "\"" );
- parent->Log(" Got self post form id: %s", this->post_form_id_.c_str());
-
- // Get dtsg
- this->dtsg_ = utils::text::source_get_value( &resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\"" );
- parent->Log(" Got self dtsg: %s", this->dtsg_.c_str());
-
// Get logout hash
- this->logout_hash_ = utils::text::source_get_value( &resp.data, 2, "<input type=\"hidden\" autocomplete=\"off\" name=\"h\" value=\"", "\"" );
+ this->logout_hash_ = utils::text::source_get_value2( &resp.data, "/logout.php?h=", "&\"" );
parent->Log(" Got self logout hash: %s", this->logout_hash_.c_str());
- std::string str_count;
-
- if (!DBGetContactSettingByte(NULL,parent->m_szModuleName,FACEBOOK_KEY_PARSE_MESSAGES, DEFAULT_PARSE_MESSAGES))
- {
- str_count = utils::text::source_get_value( &resp.data, 2, "<span id=\"messagesCountValue\">", "</span>" );
- if ( str_count.length() && str_count != std::string( "0" ))
- {
- std::string message = Translate("Got new messages: ") + str_count;
-
- TCHAR* tmessage = mir_a2t(message.c_str());
- parent->NotifyEvent( parent->m_tszUserName, tmessage, NULL, FACEBOOK_EVENT_OTHER, TEXT(FACEBOOK_URL_MESSAGES));
- mir_free( tmessage );
- }
- }
-
- str_count = utils::text::source_get_value( &resp.data, 2, "<span id=\"notificationsCountValue\">", "</span>" );
- if ( str_count.length() && str_count != std::string( "0" ))
- {
- // Parse notifications directly to popups
- ForkThread( &FacebookProto::ProcessNotifications, this->parent, NULL );
- }
-
- if (DBGetContactSettingByte(NULL, parent->m_szModuleName, FACEBOOK_KEY_ENABLE_GROUPCHATS, DEFAULT_ENABLE_GROUPCHATS)) {
- // Get group chats
- std::string favorites = utils::text::source_get_value( &resp.data, 2, "<div id=\"leftCol\"", "<div id=\"contentCol\"" );
-
- std::string::size_type pos = 0;
- while ((pos = favorites.find("href=\"/groups/",pos)) != std::string::npos) {
- pos += 14;
- std::string item = favorites.substr(pos, favorites.find("</a>", pos) - pos);
- std::string id = item.substr(0, item.find("/"));
-
- if (!id.empty()) {
- std::string name = utils::text::source_get_value( &item, 3, "class=\"linkWrap", ">", "</div>" );
- name = utils::text::special_expressions_decode(utils::text::slashu_to_utf8( name ));
- parent->Log(" Got new group chat: %s (id: %s)", name.c_str(), id.c_str());
- if (!name.empty())
- parent->AddChat(id.c_str(), name.c_str());
- }
- }
- }
return handle_success( "home" );
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index d041e0344f..4abded5872 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -82,20 +82,19 @@ void FacebookProto::ChangeStatus(void*) ResetEvent(update_loop_lock_);
- if ( NegotiateConnection( ))
- {
- facy.last_feeds_update_ = ::time( NULL );
-
- facy.home();
+ if (NegotiateConnection() && facy.home())
+ {
facy.reconnect();
-
facy.load_friends();
// Process Friends requests
ForkThread( &FacebookProto::ProcessFriendRequests, this, NULL );
- if (getByte(FACEBOOK_KEY_PARSE_MESSAGES, DEFAULT_PARSE_MESSAGES))
- ForkThread( &FacebookProto::ProcessUnreadMessages, this );
+ // Get unread messages
+ ForkThread( &FacebookProto::ProcessUnreadMessages, this );
+
+ // Get notifications
+ ForkThread( &FacebookProto::ProcessNotifications, this );
setDword( "LogonTS", (DWORD)time(NULL));
ForkThread( &FacebookProto::UpdateLoop, this );
@@ -180,6 +179,9 @@ bool FacebookProto::NegotiateConnection( ) DBFreeVariant(&dbv);
}
+ // Refresh last time of feeds update
+ facy.last_feeds_update_ = ::time(NULL);
+
// Get info about secured connection
facy.https_ = DBGetContactSettingByte(NULL, m_szModuleName, FACEBOOK_KEY_FORCE_HTTPS, DEFAULT_FORCE_HTTPS ) != 0;
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 0f04dc55fe..b08c98a102 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -84,8 +84,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define FACEBOOK_REQUEST_LOGIN 100 // connecting physically
#define FACEBOOK_REQUEST_SETUP_MACHINE 102 // setting machine name
#define FACEBOOK_REQUEST_LOGOUT 106 // disconnecting physically
-#define FACEBOOK_REQUEST_HOME 110 // getting __post_form_id__ + __fb_dtsg__ + ...
-#define FACEBOOK_REQUEST_SEARCH 111 // searching
+#define FACEBOOK_REQUEST_HOME 110 // getting own name, avatar, ...
+#define FACEBOOK_REQUEST_DTSG 111 // getting __fb_dtsg__
+#define FACEBOOK_REQUEST_SEARCH 112 // searching
#define FACEBOOK_REQUEST_BUDDY_LIST 120 // getting regular updates (friends online, ...)
#define FACEBOOK_REQUEST_LOAD_FRIENDS 121 // getting list of all friends
#define FACEBOOK_REQUEST_FEEDS 122 // getting feeds
@@ -94,7 +95,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define FACEBOOK_REQUEST_REQUEST_FRIEND 126 // requesting friends
#define FACEBOOK_REQUEST_APPROVE_FRIEND 127 // approving friends
#define FACEBOOK_REQUEST_DELETE_FRIEND 128 // deleting friends
-#define FACEBOOK_REQUEST_CANCEL_REQUEST 129 // cancel friends request
+#define FACEBOOK_REQUEST_CANCEL_REQUEST 129 // canceling friends request
#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
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp index a223351533..859f1f9e56 100644 --- a/protocols/FacebookRM/src/theme.cpp +++ b/protocols/FacebookRM/src/theme.cpp @@ -281,6 +281,15 @@ int FacebookProto::OnBuildStatusMenu(WPARAM wParam,LPARAM lParam) mi.icolibItem = NULL;
m_hMenuServicesRoot = Menu_AddProtoMenuItem(&mi);
+ CreateProtoService(m_szModuleName,"/RefreshBuddyList",&FacebookProto::RefreshBuddyList,this);
+ strcpy(tDest,"/RefreshBuddyList");
+ mi.flags = CMIF_ICONFROMICOLIB | CMIF_ROOTHANDLE;
+ mi.pszName = LPGEN("Refresh Buddy List");
+ mi.pszPopupName = LPGEN("Services");
+ mi.icolibItem = NULL;
+ mi.hParentMenu = m_hMenuServicesRoot;
+ Menu_AddProtoMenuItem(&mi);
+
CreateProtoService(m_szModuleName,"/CheckFriendRequests",&FacebookProto::CheckFriendRequests,this);
strcpy(tDest,"/CheckFriendRequests");
mi.flags = CMIF_ICONFROMICOLIB | CMIF_ROOTHANDLE;
@@ -298,15 +307,6 @@ int FacebookProto::OnBuildStatusMenu(WPARAM wParam,LPARAM lParam) mi.hParentMenu = m_hMenuServicesRoot;
Menu_AddProtoMenuItem(&mi);
- CreateProtoService(m_szModuleName,"/RefreshBuddyList",&FacebookProto::RefreshBuddyList,this);
- strcpy(tDest,"/RefreshBuddyList");
- mi.flags = CMIF_ICONFROMICOLIB | CMIF_ROOTHANDLE;
- mi.pszName = LPGEN("Refresh buddy list");
- mi.pszPopupName = LPGEN("Services");
- mi.icolibItem = NULL;
- mi.hParentMenu = m_hMenuServicesRoot;
- Menu_AddProtoMenuItem(&mi);
-
return 0;
}
|