summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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");