summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2013-05-20 13:26:29 +0000
committerRobert Pösel <robyer@seznam.cz>2013-05-20 13:26:29 +0000
commitb330de2b0bcf4d09a417c0ef154c3419b6930316 (patch)
tree962eb53ad945a1a26204f4f2d738bb94354d3d2b /protocols/FacebookRM/src
parent7e065653a2ffe78094357f6838a5c15ac0fda885 (diff)
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
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/communication.cpp14
-rw-r--r--protocols/FacebookRM/src/constants.h1
-rw-r--r--protocols/FacebookRM/src/contacts.cpp2
-rw-r--r--protocols/FacebookRM/src/entities.h5
-rw-r--r--protocols/FacebookRM/src/events.cpp30
-rw-r--r--protocols/FacebookRM/src/json.cpp8
-rw-r--r--protocols/FacebookRM/src/messages.cpp2
-rw-r--r--protocols/FacebookRM/src/process.cpp4
-rw-r--r--protocols/FacebookRM/src/proto.cpp16
-rw-r--r--protocols/FacebookRM/src/proto.h3
10 files changed, 65 insertions, 20 deletions
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 <http://www.gnu.org/licenses/>.
#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, "<abbr"));
notification->link = utils::text::source_get_value(&text, 3, "<a ", "href=\"", "\"");
+ notification->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, &notifications[i]->link);
+ NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, &notifications[i]->link, &notifications[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, &notifications[i]->link);
+ NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, &notifications[i]->link, &notifications[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<std::string*>(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);
};