summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2013-07-28 15:28:28 +0000
committerRobert Pösel <robyer@seznam.cz>2013-07-28 15:28:28 +0000
commitb279ec16b7668408a9cd6e883e1031b26972024f (patch)
tree5eff60e2d23097a609e846d5793e32766d3d7cf8
parentf18684245d19f4aaecaa25727b0a4121f9aab7cd (diff)
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
-rw-r--r--protocols/FacebookRM/res/facebook.rc5
-rw-r--r--protocols/FacebookRM/src/client.h2
-rw-r--r--protocols/FacebookRM/src/communication.cpp68
-rw-r--r--protocols/FacebookRM/src/connection.cpp2
-rw-r--r--protocols/FacebookRM/src/constants.h3
-rw-r--r--protocols/FacebookRM/src/db.h1
-rw-r--r--protocols/FacebookRM/src/dialogs.cpp16
-rw-r--r--protocols/FacebookRM/src/entities.h6
-rw-r--r--protocols/FacebookRM/src/proto.cpp16
-rw-r--r--protocols/FacebookRM/src/resource.h1
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<std::string, std::string> cookies;
+ std::map<std::string, std::string> 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\"", "</code>");
+
+ std::string::size_type start, end;
+ start = content.find("<li", 0);
+ while (start != std::string::npos) {
+ end = content.find("<li", start+1);
+ if (end == std::string::npos)
+ end = content.length();
+
+ std::string item = content.substr(start, end - start);
+ //item = utils::text::source_get_value(&item, 2, "data-gt=", ">");
+
+ start = content.find("<li", start+1);
+
+ std::string id = utils::text::source_get_value(&item, 3, "data-gt=", "bmid&quot;:&quot;", "&quot;");
+ std::string title = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&item, 3, "data-gt=", "title=\"", "\"")));
+ std::string href = utils::text::source_get_value(&item, 3, "data-gt=", "href=\"", "\"");
+
+ // Ignore pages channel
+ if (href.find("/pages/feed") != std::string::npos)
+ continue;
+
+ if (id.empty() || title.empty())
+ continue;
+
+ parent->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 <http://www.gnu.org/licenses/>.
#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 <http://www.gnu.org/licenses/>.
#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<wall_data*>::size_type i = 0; i < data->walls.size(); i++)
- SendDlgItemMessageA(hwnd, IDC_WALL, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(data->walls[i]->title.c_str()));
+ SendDlgItemMessage(hwnd, IDC_WALL, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(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<post_status_data*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
- for(std::vector<wall_data*>::size_type i = 0; i < data->walls.size(); i++)
+ for(std::vector<wall_data*>::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<std::string, std::string>::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<LPARAM>(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