From b330de2b0bcf4d09a417c0ef154c3419b6930316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Mon, 20 May 2013 13:26:29 +0000 Subject: Facebook: Marking notifications as read with right click on popup. git-svn-id: http://svn.miranda-ng.org/main/trunk@4760 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/communication.cpp | 14 +++++++++++++- protocols/FacebookRM/src/constants.h | 1 + protocols/FacebookRM/src/contacts.cpp | 2 +- protocols/FacebookRM/src/entities.h | 5 ++++- protocols/FacebookRM/src/events.cpp | 30 +++++++++++++++++++----------- protocols/FacebookRM/src/json.cpp | 8 ++++++-- protocols/FacebookRM/src/messages.cpp | 2 +- protocols/FacebookRM/src/process.cpp | 4 ++-- protocols/FacebookRM/src/proto.cpp | 16 ++++++++++++++++ protocols/FacebookRM/src/proto.h | 3 ++- 10 files changed, 65 insertions(+), 20 deletions(-) (limited to 'protocols/FacebookRM/src') diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 793bef85ee..c92a1c7b5b 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -246,6 +246,7 @@ DWORD facebook_client::choose_security_level(int request_type) // case FACEBOOK_REQUEST_POKE: // case FACEBOOK_REQUEST_ASYNC: // case FACEBOOK_REQUEST_MARK_READ: +// case FACEBOOK_REQUEST_NOTIFICATIONS_READ: // case FACEBOOK_REQUEST_UNREAD_MESSAGES: // case FACEBOOK_REQUEST_TYPING_SEND: default: @@ -268,6 +269,7 @@ int facebook_client::choose_method(int request_type) case FACEBOOK_REQUEST_POKE: case FACEBOOK_REQUEST_ASYNC: case FACEBOOK_REQUEST_MARK_READ: + case FACEBOOK_REQUEST_NOTIFICATIONS_READ: case FACEBOOK_REQUEST_TYPING_SEND: case FACEBOOK_REQUEST_LOGOUT: case FACEBOOK_REQUEST_DELETE_FRIEND: @@ -336,6 +338,7 @@ std::string facebook_client::choose_server(int request_type, std::string* data, // case FACEBOOK_REQUEST_POKE: // case FACEBOOK_REQUEST_ASYNC: // case FACEBOOK_REQUEST_MARK_READ: +// case FACEBOOK_REQUEST_NOTIFICATIONS_READ: // case FACEBOOK_REQUEST_TYPING_SEND: // case FACEBOOK_REQUEST_SETUP_MACHINE: // case FACEBOOK_REQUEST_DELETE_FRIEND: @@ -496,6 +499,15 @@ std::string facebook_client::choose_action(int request_type, std::string* data, case FACEBOOK_REQUEST_MARK_READ: return "/ajax/mercury/change_read_status.php?__a=1"; + case FACEBOOK_REQUEST_NOTIFICATIONS_READ: + { + std::string action = "/ajax/notifications/mark_read.php?__a=1"; + if (get_data != NULL) { + action += "&" + (*get_data); + } + return action; + } + case FACEBOOK_REQUEST_TYPING_SEND: return "/ajax/messaging/typ.php?__a=1"; @@ -847,7 +859,7 @@ bool facebook_client::chat_state(bool online) std::string data = (online ? "visibility=1" : "visibility=0"); data += "&window_id=0"; - data += "&fb_dtsg=" + this->dtsg_; + data += "&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0"); data += "&phstamp=0&__user=" + self_.user_id; http::response resp = flap(FACEBOOK_REQUEST_VISIBILITY, &data); diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 82d6015931..34940132e1 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -107,6 +107,7 @@ along with this program. If not, see . #define FACEBOOK_REQUEST_MARK_READ 308 // marking messages read (new) #define FACEBOOK_REQUEST_THREAD_INFO 310 // getting thread info #define FACEBOOK_REQUEST_POKE 311 // sending pokes +#define FACEBOOK_REQUEST_NOTIFICATIONS_READ 312 // marking notifications read // Send message types #define MESSAGE_INBOX 0 diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 71a294b696..020bc38390 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -333,7 +333,7 @@ void FacebookProto::SendPokeWorker(void *p) std::string data = "uid=" + id; data += "&phstamp=0&pokeback=0&ask_for_confirm=0"; - data += "&fb_dtsg=" + facy.dtsg_; + data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0"); data += "&__user=" + facy.self_.user_id; // Send poke diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index acb395d52a..38869e326c 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -88,10 +88,11 @@ struct facebook_notification std::string user_id; std::string text; std::string link; + std::string id; facebook_notification() { - this->user_id = this->text = this->link = ""; + this->user_id = this->text = this->link = this->id = ""; } }; @@ -132,7 +133,9 @@ struct send_typing struct popup_data { + popup_data(FacebookProto *proto) : proto(proto) {} popup_data(FacebookProto *proto, std::string url) : proto(proto), url(url) {} FacebookProto *proto; std::string url; + std::string notification_id; }; \ No newline at end of file diff --git a/protocols/FacebookRM/src/events.cpp b/protocols/FacebookRM/src/events.cpp index 73024741ee..229bdd2716 100644 --- a/protocols/FacebookRM/src/events.cpp +++ b/protocols/FacebookRM/src/events.cpp @@ -47,19 +47,21 @@ LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa switch(message) { case WM_COMMAND: + case WM_CONTEXTMENU: { - //Get the plugin data (we need the Popup service to do it) + // Get the plugin data (we need the Popup service to do it) popup_data *data = (popup_data *)PUGetPluginData(hwnd); - if (data != NULL) - data->proto->OpenUrl(data->url); + if (data != NULL) { + if (!data->notification_id.empty()) + ForkThread(&FacebookProto::ReadNotificationWorker, data->proto, new std::string(data->notification_id)); - // After a click, destroy popup - PUDeletePopup(hwnd); - } break; + if (message == WM_COMMAND && !data->url.empty()) + data->proto->OpenUrl(data->url); + } - case WM_CONTEXTMENU: + // After a click, destroy popup PUDeletePopup(hwnd); - break; + } break; case UM_FREEPLUGINDATA: { @@ -76,7 +78,7 @@ LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return DefWindowProc(hwnd, message, wParam, lParam); }; -void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, std::string *url) +void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, std::string *url, std::string *notification_id) { int ret, timeout; COLORREF colorBack = 0, colorText = 0; @@ -148,8 +150,14 @@ void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD pd.iSeconds = timeout; pd.lchContact = contact; pd.lchIcon = icon; - if (url != NULL) - pd.PluginData = new popup_data(this, *url); + if (url != NULL || notification_id != NULL) { + popup_data *data = new popup_data(this); + if (url != NULL) + data->url = *url; + if (notification_id != NULL) + data->notification_id = *notification_id; + pd.PluginData = data; + } pd.PluginWindowProc = (WNDPROC)PopupDlgProc; lstrcpy(pd.lptzContactName, title); lstrcpy(pd.lptzText, info); diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 2482819bf1..67eb807346 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -237,7 +237,6 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_ const Object::Member& member = *payload_item; const Object& objMember = member.element; - const String& content = objMember["markup"]; const Number& unread = objMember["unread"]; @@ -251,6 +250,7 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_ notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "link = utils::text::source_get_value(&text, 3, "id = member.name; notifications->push_back(notification); } @@ -453,15 +453,19 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa //const String& text = objNotification["title"]["text"]; const String& text = objNotification["unaggregatedTitle"]["text"]; const String& link = objNotification["url"]; + const String& id = objNotification["alert_id"]; const Number& time_sent = objNotification["timestamp"]["time"]; - if (time_sent.Value() > proto->facy.last_notification_time_) // Check agains duplicit notifications + if (time_sent.Value() > proto->facy.last_notification_time_) // Check against duplicit notifications { proto->facy.last_notification_time_ = time_sent.Value(); facebook_notification* notification = new facebook_notification(); notification->text = utils::text::slashu_to_utf8(text.Value()); notification->link = utils::text::special_expressions_decode(link.Value()); + + std::string::size_type pos = id.Value().find(":"); + notification->id = (pos != std::string::npos) ? id.Value().substr(pos+1) : id.Value(); notifications->push_back(notification); } diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 58dcc8275f..2893d62016 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -152,7 +152,7 @@ void FacebookProto::SendTypingWorker(void *p) std::string data = "&source=mercury-chat"; data += (typing->status == PROTOTYPE_SELFTYPING_ON ? "&typ=1" : "&typ=0"); // PROTOTYPE_SELFTYPING_OFF data += "&to=" + std::string(dbv.pszVal); - data += "&fb_dtsg=" + facy.dtsg_; + data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0"); data += "&lsd=&phstamp=0&__user=" + facy.self_.user_id; http::response resp = facy.flap(FACEBOOK_REQUEST_TYPING_SEND, &data); diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index d9e26f7461..0a140724fe 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -493,7 +493,7 @@ void FacebookProto::ProcessMessages(void* data) LOG(" Got notification: %s", notifications[i]->text.c_str()); TCHAR* szTitle = mir_utf8decodeT(this->m_szModuleName); TCHAR* szText = mir_utf8decodeT(notifications[i]->text.c_str()); - NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, ¬ifications[i]->link); + NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, ¬ifications[i]->link, ¬ifications[i]->id); mir_free(szTitle); mir_free(szText); @@ -551,7 +551,7 @@ void FacebookProto::ProcessNotifications(void*) LOG(" Got notification: %s", notifications[i]->text.c_str()); TCHAR* szTitle = mir_utf8decodeT(this->m_szModuleName); TCHAR* szText = mir_utf8decodeT(notifications[i]->text.c_str()); - NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, ¬ifications[i]->link); + NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, ¬ifications[i]->link, ¬ifications[i]->id); mir_free(szTitle); mir_free(szText); diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index c5ecfea06d..03fd9c722e 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -628,3 +628,19 @@ void FacebookProto::OpenUrl(std::string url) ptrT data = mir_utf8decodeT(url.c_str()); CallService(MS_UTILS_OPENURL, (WPARAM)OUF_TCHAR, (LPARAM)data); } + +void FacebookProto::ReadNotificationWorker(void *p) +{ + if (p == NULL) + return; + + std::string *id = static_cast(p); + + std::string data = "seen=0&asyncSignal=&__dyn=&__req=a&alert_ids%5B0%5D=" + *id; + data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0"); + data += "&__user=" + facy.self_.user_id; + + facy.flap(FACEBOOK_REQUEST_NOTIFICATIONS_READ, NULL, &data); + + delete p; +} \ No newline at end of file diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 877c2a35da..69a62ac96c 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -156,6 +156,7 @@ public: void __cdecl SendChatMsgWorker(void*); void __cdecl SendTypingWorker(void*); void __cdecl ReadMessageWorker(void*); + void __cdecl ReadNotificationWorker(void*); void __cdecl DeleteContactFromServer(void*); void __cdecl AddContactToServer(void*); void __cdecl ApproveContactToServer(void*); @@ -209,5 +210,5 @@ public: // Information providing int Log(const char *fmt,...); - void NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, std::string *url = NULL); + void NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, std::string *url = NULL, std::string *notification_id = NULL); }; -- cgit v1.2.3