From 725ee7bd32418048b1739c04ff6abf63fffab817 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 10 Jun 2019 18:22:59 +0300 Subject: fixes #1978 (Facebook notification issue) --- protocols/FacebookRM/src/json.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'protocols/FacebookRM/src/json.cpp') diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 2ff53ff346..de642b4186 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -226,15 +226,18 @@ int FacebookProto::ParseNotifications(std::string *data, std::map< std::string, if (!text_ || !state_ || state_.as_string() == "SEEN_AND_READ" || !time_) continue; - facebook_notification *notification = new facebook_notification(); - - notification->id = id_.as_string(); - // Fix notification ID - std::string::size_type pos = notification->id.find(":"); + std::string msgid = id_.as_string(); + std::string::size_type pos = msgid.find(":"); if (pos != std::string::npos) - notification->id = notification->id.substr(pos + 1); + msgid = msgid.substr(pos + 1); + + // Skip duplicate notifications + if (notifications->find(msgid) != notifications->end()) + continue; + facebook_notification *notification = new facebook_notification(); + notification->id = msgid; 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()); @@ -242,12 +245,7 @@ int FacebookProto::ParseNotifications(std::string *data, std::map< std::string, // Write notification to chatroom UpdateNotificationsChatRoom(notification); - - // If it's unseen, remember it, otherwise forget it - if (notifications->find(notification->id) == notifications->end()) - notifications->insert(std::make_pair(notification->id, notification)); - else - delete notification; + notifications->insert(std::make_pair(notification->id, notification)); } return EXIT_SUCCESS; -- cgit v1.2.3