From b279ec16b7668408a9cd6e883e1031b26972024f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 28 Jul 2013 15:28:28 +0000 Subject: Facebook: Post status improvements (final part) - ability to post statuses to own pages (you need to enable it in options first) git-svn-id: http://svn.miranda-ng.org/main/trunk@5513 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/res/facebook.rc | 5 ++- protocols/FacebookRM/src/client.h | 2 + protocols/FacebookRM/src/communication.cpp | 68 ++++++++++++++++++++++++++++-- protocols/FacebookRM/src/connection.cpp | 2 + protocols/FacebookRM/src/constants.h | 3 ++ protocols/FacebookRM/src/db.h | 1 + protocols/FacebookRM/src/dialogs.cpp | 16 ++++--- protocols/FacebookRM/src/entities.h | 6 ++- protocols/FacebookRM/src/proto.cpp | 16 ++++--- protocols/FacebookRM/src/resource.h | 1 + 10 files changed, 104 insertions(+), 16 deletions(-) diff --git a/protocols/FacebookRM/res/facebook.rc b/protocols/FacebookRM/res/facebook.rc index b2d556e40c..35d5aa98e1 100644 --- a/protocols/FacebookRM/res/facebook.rc +++ b/protocols/FacebookRM/res/facebook.rc @@ -182,6 +182,8 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,108,267,10 COMBOBOX IDC_URL_SERVER,156,135,96,59,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Use this server for opening links:",IDC_STATIC,17,137,135,8 + CONTROL "Allow posting statuses to my pages (may slow down login)",IDC_LOAD_PAGES, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,122,267,10 END @@ -275,8 +277,7 @@ END // // Generated from the TEXTINCLUDE 3 resource. // - - + ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 152c5564c0..d38a0ca528 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -94,6 +94,7 @@ public: HANDLE cookies_lock_; std::map cookies; + std::map pages; std::string get_newsfeed_type(); std::string get_server_type(); @@ -146,6 +147,7 @@ public: bool buddy_list(); bool load_friends(); + bool load_pages(); bool feeds(); //////////////////////////////////////////////////////////// diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index c79342c25d..fb48ce5347 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -233,6 +233,7 @@ DWORD facebook_client::choose_security_level(RequestType request_type) // case REQUEST_APPROVE_FRIEND: // case REQUEST_CANCEL_REQUEST: // case REQUEST_FEEDS: +// case REQUEST_PAGES: // case REQUEST_NOTIFICATIONS: // case REQUEST_RECONNECT: // case REQUEST_POST_STATUS: @@ -285,6 +286,7 @@ int facebook_client::choose_method(RequestType request_type) // case REQUEST_DTSG: // case REQUEST_MESSAGES_RECEIVE: // case REQUEST_FEEDS: +// case REQUEST_PAGES: // case REQUEST_NOTIFICATIONS: // case REQUEST_RECONNECT: // case REQUEST_LOAD_FRIENDS: @@ -335,6 +337,7 @@ std::string facebook_client::choose_server(RequestType request_type, std::string // case REQUEST_BUDDY_LIST: // case REQUEST_LOAD_FRIENDS: // case REQUEST_FEEDS: +// case REQUEST_PAGES: // case REQUEST_NOTIFICATIONS: // case REQUEST_RECONNECT: // case REQUEST_POST_STATUS: @@ -467,6 +470,11 @@ std::string facebook_client::choose_action(RequestType request_type, std::string return action; } + case REQUEST_PAGES: + { + return "/bookmarks/pages"; + } + case REQUEST_NOTIFICATIONS: { std::string action = "/ajax/notifications/get.php?__a=1&user=%s&time=0&version=2&__user=%s"; @@ -1034,6 +1042,60 @@ bool facebook_client::feeds() } } +bool facebook_client::load_pages() +{ + if (!parent->getByte(FACEBOOK_KEY_LOAD_PAGES, DEFAULT_LOAD_PAGES)) + return true; + + handle_entry("load_pages"); + + // Get feeds + http::response resp = flap(REQUEST_PAGES); + + // Process result data + validate_response(&resp); + + switch (resp.code) { + case HTTP_CODE_OK: + { + std::string content = utils::text::source_get_value(&resp.data, 2, "id=\"bookmarksSeeAllSection\"", ""); + + std::string::size_type start, end; + start = content.find(""); + + start = content.find("Log(" Got page: %s (%s)", title.c_str(), id.c_str()); + pages[id] = title; + } + + return handle_success("load_pages"); + } + case HTTP_CODE_FAKE_ERROR: + case HTTP_CODE_FAKE_DISCONNECTED: + default: + return handle_error("load_pages"); + } +} + bool facebook_client::channel() { handle_entry("channel"); @@ -1255,7 +1317,7 @@ bool facebook_client::post_status(status_data *status) data += "&composerid=u_jsonp_2_b"; data += "&targetid=" + (status->user_id.empty() ? this->self_.user_id : status->user_id); data += "&istimeline=1&composercontext=composer&onecolumn=1&nctr[_mod]=pagelet_timeline_recent&__a=1&ttstamp=0"; - data += "&__user=" + this->self_.user_id; + data += "&__user=" + (status->isPage && !status->user_id.empty() ? status->user_id : this->self_.user_id); data += "&loaded_components[0]=maininput&loaded_components[1]=backdateicon&loaded_components[2]=withtaggericon&loaded_components[3]=cameraicon&loaded_components[4]=placetaggericon&loaded_components[5]=mainprivacywidget&loaded_components[6]=withtaggericon&loaded_components[7]=backdateicon&loaded_components[8]=placetaggericon&loaded_components[9]=cameraicon&loaded_components[10]=mainprivacywidget&loaded_components[11]=maininput&loaded_components[12]=explicitplaceinput&loaded_components[13]=hiddenplaceinput&loaded_components[14]=placenameinput&loaded_components[15]=hiddensessionid&loaded_components[16]=withtagger&loaded_components[17]=backdatepicker&loaded_components[18]=placetagger&loaded_components[19]=citysharericon"; http::response resp = flap(REQUEST_LINK_SCRAPER, &data, &status->url); resp.data = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(resp.data)); @@ -1273,12 +1335,12 @@ bool facebook_client::post_status(status_data *status) data += "fb_dtsg=" + (this->dtsg_.length() ? this->dtsg_ : "0"); data += "&xhpc_targetid=" + (status->user_id.empty() ? this->self_.user_id : status->user_id); - data += "&__user=" + this->self_.user_id; + data += "&__user=" + (status->isPage && !status->user_id.empty() ? status->user_id : this->self_.user_id); data += "&xhpc_message=" + text; data += "&xhpc_message_text=" + text; data += "&audience[0][value]=" + get_privacy_type(); if (!status->place.empty()) { - data += "&composertags_place_name="; + data += "&composertags_place_name="; data += utils::url::encode(status->place); } diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 04deb1a7a5..131e00bb9d 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -53,6 +53,7 @@ void FacebookProto::ChangeStatus(void*) facy.clear_cookies(); facy.buddies.clear(); facy.messages_ignore.clear(); + facy.pages.clear(); if (facy.hMsgCon) Netlib_CloseHandle(facy.hMsgCon); @@ -79,6 +80,7 @@ void FacebookProto::ChangeStatus(void*) { facy.reconnect(); facy.load_friends(); + facy.load_pages(); // Process Friends requests ForkThread(&FacebookProto::ProcessFriendRequests, NULL); diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 1c833dd4d6..9f17d88890 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -63,6 +63,8 @@ along with this program. If not, see . #define DEFAULT_MAP_STATUSES 0 #define DEFAULT_LOAD_MOBILE 0 #define DEFAULT_CUSTOM_SMILEYS 0 +#define DEFAULT_LOCAL_TIME 0 +#define DEFAULT_LOAD_PAGES 0 #define DEFAULT_EVENT_NOTIFICATIONS_ENABLE 1 #define DEFAULT_EVENT_FEEDS_ENABLE 1 @@ -92,6 +94,7 @@ enum RequestType { REQUEST_FEEDS, // getting feeds REQUEST_NOTIFICATIONS, // getting notifications REQUEST_LOAD_REQUESTS, // getting friend requests + REQUEST_PAGES, // getting pages list REQUEST_POST_STATUS, // posting status to our or friends's wall REQUEST_STATUS_COMPOSER, // posting status to our or friends's wall with url links diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h index 595dc8b395..7d8d07fde6 100644 --- a/protocols/FacebookRM/src/db.h +++ b/protocols/FacebookRM/src/db.h @@ -52,6 +52,7 @@ along with this program. If not, see . #define FACEBOOK_KEY_PRIVACY_TYPE "PrivacyType" #define FACEBOOK_KEY_PLACE "Place" #define FACEBOOK_KEY_LAST_WALL "LastWall" +#define FACEBOOK_KEY_LOAD_PAGES "LoadPages" #define FACEBOOK_KEY_POLL_RATE "PollRate" // [HIDDEN] #define FACEBOOK_KEY_TIMEOUTS_LIMIT "TimeoutsLimit" // [HIDDEN] diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp index 45b1467375..113c08175e 100644 --- a/protocols/FacebookRM/src/dialogs.cpp +++ b/protocols/FacebookRM/src/dialogs.cpp @@ -146,7 +146,7 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara SetDlgItemText(hwnd, IDC_PLACE, place != NULL ? place : _T("Miranda NG")); for (std::vector::size_type i = 0; i < data->walls.size(); i++) - SendDlgItemMessageA(hwnd, IDC_WALL, CB_INSERTSTRING, i, reinterpret_cast(data->walls[i]->title.c_str())); + SendDlgItemMessage(hwnd, IDC_WALL, CB_INSERTSTRING, i, reinterpret_cast(data->walls[i]->title)); SendDlgItemMessage(hwnd, IDC_WALL, CB_SETCURSEL, 0, 0); SendDlgItemMessage(hwnd, IDC_WALL, CB_SETCURSEL, data->proto->getByte(FACEBOOK_KEY_LAST_WALL, 0), 0); RefreshPrivacy(hwnd, data); @@ -207,8 +207,11 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara ptrA place(mir_utf8encodeT(placeT)); data->proto->setString(FACEBOOK_KEY_PLACE, place); + int wall_id = SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCURSEL, 0, 0); + status_data *status = new status_data(); - status->user_id = data->walls[SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCURSEL, 0, 0)]->user_id; + status->user_id = data->walls[wall_id]->user_id; + status->isPage = data->walls[wall_id]->isPage; status->privacy = privacy_types[SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0)].id; status->place = place; status->url = _T2A(urlT); @@ -235,8 +238,10 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara case WM_DESTROY: data = reinterpret_cast(GetWindowLongPtr(hwnd,GWLP_USERDATA)); - for(std::vector::size_type i = 0; i < data->walls.size(); i++) + for(std::vector::size_type i = 0; i < data->walls.size(); i++) { + mir_free(data->walls[i]->title); delete data->walls[i]; + } delete data; } @@ -370,8 +375,8 @@ INT_PTR CALLBACK FBOptionsAdvancedProc(HWND hwnd, UINT message, WPARAM wparam, L LoadDBCheckState(proto, hwnd, IDC_LOGGING, FACEBOOK_KEY_LOGGING_ENABLE, DEFAULT_LOGGING_ENABLE); LoadDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES, DEFAULT_MAP_STATUSES); LoadDBCheckState(proto, hwnd, IDC_CUSTOM_SMILEYS, FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS); - - LoadDBCheckState(proto, hwnd, IDC_USE_LOCAL_TIME, FACEBOOK_KEY_LOCAL_TIMESTAMP, 0); + LoadDBCheckState(proto, hwnd, IDC_USE_LOCAL_TIME, FACEBOOK_KEY_LOCAL_TIMESTAMP, DEFAULT_LOCAL_TIME); + LoadDBCheckState(proto, hwnd, IDC_LOAD_PAGES, FACEBOOK_KEY_LOAD_PAGES, DEFAULT_LOAD_PAGES); EnableWindow(GetDlgItem(hwnd, IDC_SECURE_CHANNEL), IsDlgButtonChecked(hwnd, IDC_SECURE)); @@ -403,6 +408,7 @@ INT_PTR CALLBACK FBOptionsAdvancedProc(HWND hwnd, UINT message, WPARAM wparam, L StoreDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES); StoreDBCheckState(proto, hwnd, IDC_CUSTOM_SMILEYS, FACEBOOK_KEY_CUSTOM_SMILEYS); StoreDBCheckState(proto, hwnd, IDC_USE_LOCAL_TIME, FACEBOOK_KEY_LOCAL_TIMESTAMP); + StoreDBCheckState(proto, hwnd, IDC_LOAD_PAGES, FACEBOOK_KEY_LOAD_PAGES); BOOL setStatus = IsDlgButtonChecked(hwnd, IDC_SET_STATUS); BOOL setStatusOld = proto->getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS); diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index 93eef6ea70..b80a75da1b 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -147,12 +147,16 @@ struct status_data std::string url; std::string place; std::string privacy; + bool isPage; }; struct wall_data { + wall_data() {} + wall_data(std::string user_id, TCHAR *title, bool isPage = false) : user_id(user_id), title(title), isPage(isPage) {} std::string user_id; - std::string title; + TCHAR *title; + bool isPage; }; struct post_status_data { diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 6ab1526553..42e675e9c1 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -465,15 +465,21 @@ INT_PTR FacebookProto::OnMind(WPARAM wParam, LPARAM lParam) // TODO: why isn't wParam == 0 when is status menu moved to main menu? if (wParam != 0 && !IsMyContact(hContact)) return 1; - + wall_data *wall = new wall_data(); wall->user_id = ptrA(getStringA(hContact, FACEBOOK_KEY_ID)); - if (wall->user_id == facy.self_.user_id) - wall->title = Translate("Own wall"); - else - wall->title = ptrA(getStringA(hContact, FACEBOOK_KEY_NAME)); + if (wall->user_id == facy.self_.user_id) { + wall->title = _tcsdup(TranslateT("Own wall")); + } else + wall->title = getTStringA(hContact, FACEBOOK_KEY_NAME); post_status_data *data = new post_status_data(this, wall); + + if (wall->user_id == facy.self_.user_id) { + for (std::map::iterator iter = facy.pages.begin(); iter != facy.pages.end(); ++iter) { + data->walls.push_back(new wall_data(iter->first, mir_utf8decodeT(iter->second.c_str()), true)); + } + } HWND hDlg = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_MIND), (HWND)0, FBMindProc, reinterpret_cast(data)); ShowWindow(hDlg, SW_SHOW); diff --git a/protocols/FacebookRM/src/resource.h b/protocols/FacebookRM/src/resource.h index 1643894516..444c7c7699 100644 --- a/protocols/FacebookRM/src/resource.h +++ b/protocols/FacebookRM/src/resource.h @@ -28,6 +28,7 @@ #define IDC_LOAD_MOBILE 1033 #define IDC_CUSTOM_SMILEYS 1034 #define IDC_USE_LOCAL_TIME 1035 +#define IDC_LOAD_PAGES 1036 #define IDC_NOTIFICATIONS_ENABLE 1041 #define IDC_FEEDS_ENABLE 1042 #define IDC_OTHER_ENABLE 1043 -- cgit v1.2.3