diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-05-21 13:46:45 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-05-21 13:46:45 +0000 |
commit | 9a90397f8161d9bd771a76b123883a65dd254651 (patch) | |
tree | 22c5cd14cb81cbe6b15e8a1d9ffecb00d2a67575 /protocols/FacebookRM | |
parent | 0129f9cbc4388c6525863818575aa839082c0690 (diff) |
Facebook: Pretty much fixed getting newsfeeds
git-svn-id: http://svn.miranda-ng.org/main/trunk@9270 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 19 | ||||
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 14 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 81 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 1 |
4 files changed, 80 insertions, 35 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 4caf79d536..e60e333b61 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -446,12 +446,12 @@ std::string facebook_client::choose_action(RequestType request_type, std::string case REQUEST_FEEDS: { - std::string action = "/ajax/intent.php?filter="; - action += get_newsfeed_type(); - action += "&request_type=4&__a=1&newest=%s&ignore_self=true&load_newer=true&__user=%s"; - std::string newest = utils::conversion::to_string((void*)&this->last_feeds_update_, UTILS_CONV_TIME_T); + std::string action = "/ajax/home/generic.php?" + get_newsfeed_type(); + action += "&__user=" + self_.user_id + "&__a=1"; + + /*std::string newest = utils::conversion::to_string((void*)&this->last_feeds_update_, UTILS_CONV_TIME_T); utils::text::replace_first(&action, "%s", newest); - utils::text::replace_first(&action, "%s", self_.user_id); + utils::text::replace_first(&action, "%s", self_.user_id);*/ return action; } @@ -604,8 +604,13 @@ std::string facebook_client::get_newsfeed_type() { BYTE feed_type = parent->getByte(FACEBOOK_KEY_FEED_TYPE, 0); if (feed_type >= SIZEOF(feed_types)) - feed_type = 0; - return feed_types[feed_type].id; + feed_type = 0; + + std::string ret = "sk="; + ret += feed_types[feed_type].id; + ret += "&key="; + ret += (feed_type < 2 ? "nf" : feed_types[feed_type].id); + return ret; } std::string facebook_client::get_server_type() diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 0ab83a7427..bfa54d2ec7 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -159,12 +159,14 @@ typedef struct { // News Feed types
static const ttype feed_types[] = {
- { LPGEN("Most Recent"), "lf_" }, //h_chr?
- { LPGEN("Wall Posts"), "app_2915120374" },
- { LPGEN("Top News"), "h_nor" }, //h
- { LPGEN("Photos"), "app_2305272732_2392950137" },
- { LPGEN("Links"), "app_2309869772" },
- { LPGEN("Apps and Games"), "appsandgames" },
+ { LPGEN("Top News"), "h_nor" },
+ { LPGEN("Most Recent"), "h_chr" },
+ { LPGEN("Pages"), "pages" },
+ //{ LPGEN("Apps and Games"), "FEED_FILTER_KEY_APPS_AND_GAMES" },
+
+ //{ LPGEN("Wall Posts"), "app_2915120374" },
+ //{ LPGEN("Photos"), "app_2305272732_2392950137" },
+ //{ LPGEN("Links"), "app_2309869772" },
};
// Server types
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 0478857926..7b7673d2c7 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -748,7 +748,7 @@ void FacebookProto::ProcessFeeds(void* data) return;
}
- if (resp.data.empty() || resp.data.find("\"num_stories\":0") != std::string::npos)
+ if (resp.data.empty() /*|| resp.data.find("\"num_stories\":0") != std::string::npos*/)
return;
CODE_BLOCK_TRY
@@ -760,33 +760,71 @@ void FacebookProto::ProcessFeeds(void* data) std::string::size_type pos = 0;
UINT limit = 0;
- resp.data = utils::text::slashu_to_utf8(resp.data);
- resp.data = utils::text::source_get_value(&resp.data, 2, "\"html\":\"", ">\"");
+ DWORD new_time = facy.last_feeds_update_;
- while ((pos = resp.data.find("<div class=\\\"mainWrapper\\\"", pos)) != std::string::npos && limit <= 25)
+ while ((pos = resp.data.find("<div class=\"userContentWrapper", pos)) != std::string::npos && limit <= 25)
{
- std::string::size_type pos2 = resp.data.find("<div class=\\\"mainWrapper\\\"", pos+5);
+ /*std::string::size_type pos2 = resp.data.find("<div class=\"userContentWrapper", pos+5);
if (pos2 == std::string::npos)
pos2 = resp.data.length();
- std::string post = resp.data.substr(pos, pos2 - pos);
+ std::string post = resp.data.substr(pos, pos2 - pos);*/
+ std::string post = resp.data.substr(pos, resp.data.find("</form>", pos) - pos);
pos += 5;
- std::string post_header = utils::text::source_get_value(&post, 4, "<h5 class=", "uiStreamHeadline", ">", "<\\/h5>");
- std::string post_message = utils::text::source_get_value(&post, 3, "<h5 class=\\\"uiStreamMessage userContentWrapper", ">", "<\\/h5>");
- std::string post_link = utils::text::source_get_value(&post, 3, "<span class=\\\"uiStreamSource\\\"", ">", "<\\/span>");
- std::string post_attach = utils::text::source_get_value(&post, 4, "<div class=", "uiStreamAttachments", ">", "<form");
+ std::string post_header = utils::text::source_get_value(&post, 3, "<h5", ">", "</h5>");
+ std::string post_message = utils::text::source_get_value(&post, 3, " userContent\"", ">", "<form");
+ std::string post_link = utils::text::source_get_value(&post, 4, "</h5>", "<a", "href=\"", "\"");
+ //std::string post_attach = utils::text::source_get_value(&post, 4, "<div class=", "uiStreamAttachments", ">", "<form");
- //std::string post_time = utils::text::source_get_value(&post_link, 2, "data-utime=\\\"", "\\\"");
- //std::string post_time_text = utils::text::source_get_value(&post_link, 3, "class=\\\"timestamp livetimestamp", ">", "<");
+ std::string post_time = utils::text::source_get_value(&post, 3, "</h5>", "<abbr", "</a>");
+
+ std::string time = utils::text::source_get_value(&post_time, 2, "data-utime=\"", "\"");
+ std::string time_text = utils::text::source_get_value(&post_time, 2, ">", "</abbr>");
+
+ DWORD ttime = utils::conversion::to_timestamp(time);
+ if (ttime > facy.last_feeds_update_)
+ new_time = ttime;
+ else
+ continue;
+
+ std::string post_place = utils::text::source_get_value(&post, 4, "</abbr>", "<a", ">", "</a>");
+
+ std::string premsg = "\n" + time_text;
+
+ post_place = utils::text::trim(
+ utils::text::remove_html(post_place));
+ if (!post_place.empty()) {
+ premsg += " - " + post_place;
+ }
+ premsg += "\n";
// in title keep only name, end of events like "X shared link" put into message
- pos2 = post_header.find("<\\/a>") + 5;
- post_message = post_header.substr(pos2, post_header.length() - pos2) + post_message;
- post_header = post_header.substr(0, pos2);
+ std::string::size_type pos2 = post_header.find("");
+
+ if (pos2 != std::string::npos) {
+ utils::text::replace_first(&post_header, "", " → ");
+ } else {
+ pos2 = post_header.find("</a></");
+ if (pos2 != std::string::npos) {
+ pos2 += 4;
+ std::string a = utils::text::trim(utils::text::remove_html(post_header.substr(pos2, post_header.length() - pos2)));
+ if (a.length() > 2)
+ premsg += a;
+ post_header = post_header.substr(0, pos2);
+ }
+ }
+
+ // Strip "Translate" link
+ pos2 = post_message.find("role=\"button\">");
+ if (pos2 != std::string::npos) {
+ post_message = post_message.substr(0, pos2 + 14); + }
+
+ post_message = premsg + post_message;
// append attachement to message (if any)
- post_message += utils::text::trim(post_attach);
+ //post_message += utils::text::trim(post_attach);
facebook_newsfeed* nf = new facebook_newsfeed;
@@ -796,15 +834,13 @@ void FacebookProto::ProcessFeeds(void* data) nf->user_id = utils::text::source_get_value(&post_header, 2, "user.php?id=", "&");
- nf->link = utils::text::special_expressions_decode(
- utils::text::source_get_value(&post_link, 2, "href=\\\"", "\\\">"));
+ nf->link = utils::text::special_expressions_decode(post_link);
+ //utils::text::source_get_value(&post_link, 2, "href=\\\"", "\\\">"));
nf->text = utils::text::trim(
utils::text::special_expressions_decode(
utils::text::remove_html(
- utils::text::edit_html(post_message))));
-
- //nf->text += "\n" + post_time_text;
+ utils::text::edit_html(post_message))));
if (!nf->title.length() || !nf->text.length())
{
@@ -833,7 +869,8 @@ void FacebookProto::ProcessFeeds(void* data) }
news.clear();
- this->facy.last_feeds_update_ = ::time(NULL);
+ this->facy.last_feeds_update_ = new_time;
+ //this->facy.last_feeds_update_ = ::time(NULL);
debugLogA("***** Feeds processed");
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index b94bd1d5db..bac50cd048 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -523,6 +523,7 @@ INT_PTR FacebookProto::CheckNewsfeeds(WPARAM, LPARAM) {
if (!isOffline()) {
facy.client_notify(TranslateT("Loading newsfeeds..."));
+ facy.last_feeds_update_ = 0;
ForkThread(&FacebookProto::ProcessFeeds, NULL);
}
return 0;
|