summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2015-05-30 22:05:31 +0000
committerRobert Pösel <robyer@seznam.cz>2015-05-30 22:05:31 +0000
commit978fdf664072386d3be6c2210452aa3d140200f7 (patch)
tree9ebfbbd35b0edf0e85f54b4bcf54399d09d3143d /protocols/FacebookRM/src
parent73ce939948a8ed16495db7999d34c2dafee5f390 (diff)
Facebook: Fix loading unread notifications on login (checks only last 20 items)
git-svn-id: http://svn.miranda-ng.org/main/trunk@13918 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/communication.cpp11
-rw-r--r--protocols/FacebookRM/src/constants.h1
-rw-r--r--protocols/FacebookRM/src/json.cpp24
-rw-r--r--protocols/FacebookRM/src/process.cpp10
4 files changed, 22 insertions, 24 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 4de82524ba..2583e7a377 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -375,16 +375,7 @@ std::string facebook_client::choose_action(RequestType request_type, std::string
case REQUEST_NOTIFICATIONS:
{
- // __req=5 .. poèítá poèet všech rùzných požadavkù (asi možná jen na /ajax/...)
-
- std::string action = "/ajax/notifications/client/get.php?__a=1&__dyn=&__req=&__rev=";
- action += "&__user=" + this->self_.user_id;
- action += "&fb_dtsg=" + this->dtsg_;
- action += "&cursor="; // when loading more
- action += "&length=15"; // number of items to load
- action += "&businessID="; // probably for pages? idk
- action += "&ttstamp=" + ttstamp();
- return action;
+ return "/ajax/notifications/client/get.php?__a=1";
}
case REQUEST_RECONNECT:
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h
index 01d4241234..ebb3e995df 100644
--- a/protocols/FacebookRM/src/constants.h
+++ b/protocols/FacebookRM/src/constants.h
@@ -52,6 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Various constants
#define FACEBOOK_NOTIFICATIONS_CHATROOM "_notifications"
#define FACEBOOK_CHATROOM_NAMES_COUNT 3 // number of participant names to use for chatrooms without specific name (on website it's 2)
+#define FACEBOOK_NOTIFICATIONS_LOAD_COUNT 20 // number of last notifications to load on login to notify
// Limits
#define FACEBOOK_MESSAGE_LIMIT 200000 // this is guessed limit, in reality it is bigger
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 3592a70f41..74698e3809 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -206,7 +206,7 @@ int facebook_json_parser::parse_notifications(std::string *data, std::map< std::
if (!root)
return EXIT_FAILURE;
- const JSONNode &list = root["payload"].at("notifications");
+ const JSONNode &list = root["payload"].at("nodes");
if (!list)
return EXIT_FAILURE;
@@ -214,24 +214,22 @@ int facebook_json_parser::parse_notifications(std::string *data, std::map< std::
proto->PrepareNotificationsChatRoom();
for (auto it = list.begin(); it != list.end(); ++it) {
- const char *id = (*it).name();
-
- const JSONNode &markup = (*it)["markup"];
- const JSONNode &unread = (*it)["unread"];
- const JSONNode &time = (*it)["time"];
+ const JSONNode &id_ = (*it)["alert_id"];
+ const JSONNode &state_ = (*it)["seen_state"];
+ const JSONNode &time_ = (*it)["timestamp"]["time"];
+ const JSONNode &text_ = (*it)["title"]["text"];
+ const JSONNode &url_ = (*it)["url"];
// Ignore empty and old notifications
- if (!markup || !unread || !time || unread.as_int() == 0)
+ if (!text_ || !state_ || state_.as_string() == "SEEN_AND_READ" || !time_)
continue;
- std::string text = utils::text::html_entities_decode(utils::text::slashu_to_utf8(markup.as_string()));
-
facebook_notification* notification = new facebook_notification();
- notification->id = id;
- notification->link = utils::text::source_get_value(&text, 3, "<a ", "href=\"", "\"");
- notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "<abbr"));
- notification->time = utils::time::from_string(time.as_string());
+ notification->id = id_.as_string();
+ notification->link = url_.as_string();
+ notification->text = utils::text::html_entities_decode(utils::text::slashu_to_utf8(text_.as_string()));
+ notification->time = utils::time::from_string(time_.as_string());
// Write notification to chatroom
proto->UpdateNotificationsChatRoom(notification);
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 6cc40d8391..b0b0cc888a 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -887,8 +887,16 @@ void FacebookProto::ProcessNotifications(void*)
facy.handle_entry("notifications");
+ std::string data = "/ajax/notifications/client/get.php?__a=1&__dyn=&__req=&__rev=";
+ data += "&__user=" + facy.self_.user_id;
+ data += "&fb_dtsg=" + facy.dtsg_;
+ data += "&cursor="; // when loading more
+ data += "&length=" + FACEBOOK_NOTIFICATIONS_LOAD_COUNT; // number of items to load
+ data += "&businessID="; // probably for pages?
+ data += "&ttstamp=" + facy.ttstamp();
+
// Get notifications
- http::response resp = facy.flap(REQUEST_NOTIFICATIONS);
+ http::response resp = facy.flap(REQUEST_NOTIFICATIONS, &data);
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("notifications");