From 5e8e5ed54e602e0de3d328098ff828cba441b2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sat, 5 Apr 2014 09:03:20 +0000 Subject: Facebook: Correct implementation of managing number of unread notifications git-svn-id: http://svn.miranda-ng.org/main/trunk@8858 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/json.cpp | 50 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'protocols/FacebookRM/src/json.cpp') diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index dc824d0cbf..110a82d127 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -225,7 +225,7 @@ int facebook_json_parser::parse_friends(void* data, std::map< std::string, faceb } -int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_notification* > *notifications) +int facebook_json_parser::parse_notifications(void *data, std::map< std::string, facebook_notification* > *notifications) { std::string jsonData = static_cast< std::string* >(data)->substr(9); @@ -265,7 +265,10 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_ notification->link = utils::text::source_get_value(&text, 3, "text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "push_back(notification); + if (notifications->find(notification->id) == notifications->end()) + notifications->insert(std::make_pair(notification->id, notification)); + else + delete notification; } json_delete(root); @@ -365,7 +368,7 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE } } -int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::vector< facebook_notification* >* notifications, bool inboxOnly) +int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::map< std::string, facebook_notification* >* notifications, bool inboxOnly) { // remove old received messages from map for (std::map::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end();) { @@ -599,20 +602,10 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa messages->push_back(message); } } - } else if (t == "notifications_read") { - JSONNODE *alerts = json_get(it, "alert_ids"); - proto->facy.notifications_count_ -= json_size(alerts); - - if (proto->facy.notifications_count_ < 0) - proto->facy.notifications_count_ = 0; } else if (t == "notification_json") { // event notification JSONNODE *nodes = json_get(it, "nodes"); - proto->facy.notifications_count_ += json_size(nodes); - if (!proto->getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE)) - continue; - for (unsigned int j = 0; j < json_size(nodes); j++) { JSONNODE *itNodes = json_at(nodes, j); @@ -645,7 +638,10 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa if (pos != std::string::npos) notification->id = notification->id.substr(pos+1); - notifications->push_back(notification); + if (notifications->find(notification->id) == notifications->end()) + notifications->insert(std::make_pair(notification->id, notification)); + else + delete notification; } } } else if (t == "typ") { @@ -706,14 +702,6 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa /* if (!text.empty()) { proto->NotifyEvent() }*/ - } else if (t == "inbox") { - // count of unread/unseen messages - pretty useless info for us - /* JSONNODE *unread_ = json_get(it, "unread"); - JSONNODE *unseen_ = json_get(it, "unseen"); - JSONNODE *other_unread_ = json_get(it, "other_unread"); - JSONNODE *other_unseen_ = json_get(it, "other_unseen"); - JSONNODE *seen_timestamp_ = json_get(it, "seen_timestamp"); */ - continue; } else if (t == "mercury") { // rename multi user chat, ... @@ -741,12 +729,20 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa proto->UpdateChat(thread_id.c_str(), NULL, NULL, message.c_str()); } } else if (t == "notifications_read") { - // TODO: close popups with these IDs - JSONNODE *alert_ids = json_get(it, "alert_ids"); - for (unsigned int n = 0; n < json_size(alert_ids); n++) { - JSONNODE *idItr = json_at(alert_ids, n); + JSONNODE *alerts = json_get(it, "alert_ids"); - // PUDeletePopup(hWndPopup); + for (unsigned int j = 0; j < json_size(alerts); j++) { + JSONNODE *itAlerts = json_at(alerts, j); + std::string id = json_as_pstring(itAlerts); + + std::map::iterator it = notifications->find(id); + if (it != notifications->end()) { + if (it->second->hWndPopup != NULL) + PUDeletePopup(it->second->hWndPopup); // close popup + + delete it->second; + notifications->erase(it); + } } } else continue; -- cgit v1.2.3