summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/src/communication.cpp14
-rw-r--r--protocols/FacebookRM/src/constants.h170
-rw-r--r--protocols/FacebookRM/src/process.cpp130
3 files changed, 149 insertions, 165 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index d56242bc01..c356c948df 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -244,6 +244,7 @@ DWORD facebook_client::choose_security_level(int request_type)
// case FACEBOOK_REQUEST_ASYNC:
// case FACEBOOK_REQUEST_MARK_READ:
// case FACEBOOK_REQUEST_NOTIFICATIONS_READ:
+// case FACEBOOK_REQUEST_UNREAD_THREADS:
// case FACEBOOK_REQUEST_UNREAD_MESSAGES:
// case FACEBOOK_REQUEST_TYPING_SEND:
default:
@@ -284,6 +285,7 @@ int facebook_client::choose_method(int request_type)
// case FACEBOOK_REQUEST_LOAD_FRIENDS:
// case FACEBOOK_REQUEST_LOAD_REQUESTS:
// case FACEBOOK_REQUEST_SEARCH:
+// case FACEBOOK_REQUEST_UNREAD_THREADS:
// case FACEBOOK_REQUEST_UNREAD_MESSAGES:
default:
return REQUEST_GET;
@@ -318,6 +320,7 @@ std::string facebook_client::choose_server(int request_type, std::string* data,
case FACEBOOK_REQUEST_APPROVE_FRIEND:
case FACEBOOK_REQUEST_LOAD_REQUESTS:
case FACEBOOK_REQUEST_SEARCH:
+ case FACEBOOK_REQUEST_UNREAD_THREADS:
case FACEBOOK_REQUEST_UNREAD_MESSAGES:
return FACEBOOK_SERVER_MOBILE;
@@ -389,7 +392,7 @@ std::string facebook_client::choose_action(int request_type, std::string* data,
return action;
}
- case FACEBOOK_REQUEST_UNREAD_MESSAGES:
+ case FACEBOOK_REQUEST_UNREAD_THREADS:
{
std::string action = "/messages/?folder=unread";
if (get_data != NULL) {
@@ -397,6 +400,15 @@ std::string facebook_client::choose_action(int request_type, std::string* data,
}
return action;
}
+
+ case FACEBOOK_REQUEST_UNREAD_MESSAGES:
+ {
+ std::string action = "/messages/read/?";
+ if (get_data != NULL) {
+ action += *get_data;
+ }
+ return action;
+ }
case FACEBOOK_REQUEST_DELETE_FRIEND:
{
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h
index e15b52b6bb..c0711edd66 100644
--- a/protocols/FacebookRM/src/constants.h
+++ b/protocols/FacebookRM/src/constants.h
@@ -23,103 +23,109 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
// Product management
-#define FACEBOOK_NAME "Facebook"
-#define FACEBOOK_MOBILE "Facebook (Mobile)"
-#define FACEBOOK_URL_HOMEPAGE "http://www.facebook.com"
-#define FACEBOOK_URL_REQUESTS "http://www.facebook.com/n/?reqs.php"
-#define FACEBOOK_URL_MESSAGES "http://www.facebook.com/n/?inbox"
-#define FACEBOOK_URL_NOTIFICATIONS "http://www.facebook.com/n/?notifications.php"
-#define FACEBOOK_URL_PROFILE "http://www.facebook.com/profile.php?id="
-#define FACEBOOK_URL_GROUP "http://www.facebook.com/n/?home.php&sk=group_"
+#define FACEBOOK_NAME "Facebook"
+#define FACEBOOK_MOBILE "Facebook (Mobile)"
+#define FACEBOOK_URL_HOMEPAGE "http://www.facebook.com"
+#define FACEBOOK_URL_REQUESTS "http://www.facebook.com/n/?reqs.php"
+#define FACEBOOK_URL_MESSAGES "http://www.facebook.com/n/?inbox"
+#define FACEBOOK_URL_NOTIFICATIONS "http://www.facebook.com/n/?notifications.php"
+#define FACEBOOK_URL_PROFILE "http://www.facebook.com/profile.php?id="
+#define FACEBOOK_URL_GROUP "http://www.facebook.com/n/?home.php&sk=group_"
// Connection
-#define FACEBOOK_SERVER_REGULAR "www.facebook.com"
-#define FACEBOOK_SERVER_MOBILE "m.facebook.com"
-#define FACEBOOK_SERVER_CHAT "%s-%s.facebook.com"
-#define FACEBOOK_SERVER_LOGIN "login.facebook.com"
-#define FACEBOOK_SERVER_APPS "apps.facebook.com"
+#define FACEBOOK_SERVER_REGULAR "www.facebook.com"
+#define FACEBOOK_SERVER_MOBILE "m.facebook.com"
+#define FACEBOOK_SERVER_CHAT "%s-%s.facebook.com"
+#define FACEBOOK_SERVER_LOGIN "login.facebook.com"
+#define FACEBOOK_SERVER_APPS "apps.facebook.com"
// Limits
-#define FACEBOOK_MESSAGE_LIMIT 1024
-#define FACEBOOK_MESSAGE_LIMIT_TEXT "1024"
-#define FACEBOOK_MIND_LIMIT 420
-#define FACEBOOK_MIND_LIMIT_TEXT "420"
-#define FACEBOOK_TIMEOUTS_LIMIT 5
-#define FACEBOOK_GROUP_NAME_LIMIT 100
+#define FACEBOOK_MESSAGE_LIMIT 1024
+#define FACEBOOK_MESSAGE_LIMIT_TEXT "1024"
+#define FACEBOOK_MIND_LIMIT 420
+#define FACEBOOK_MIND_LIMIT_TEXT "420"
+#define FACEBOOK_TIMEOUTS_LIMIT 5
+#define FACEBOOK_GROUP_NAME_LIMIT 100
// Defaults
-#define FACEBOOK_MINIMAL_POLL_RATE 10
-#define FACEBOOK_DEFAULT_POLL_RATE 24 // in seconds
-#define FACEBOOK_MAXIMAL_POLL_RATE 60
-
-#define DEFAULT_FORCE_HTTPS 0
-#define DEFAULT_FORCE_HTTPS_CHANNEL 0
-#define DEFAULT_SET_MIRANDA_STATUS 0
-#define DEFAULT_LOGGING_ENABLE 0
-#define DEFAULT_SYSTRAY_NOTIFY 0
-#define DEFAULT_DISABLE_STATUS_NOTIFY 0
-#define DEFAULT_BIG_AVATARS 0
-#define DEFAULT_DISCONNECT_CHAT 0
-#define DEFAULT_MAP_STATUSES 0
-#define DEFAULT_LOAD_MOBILE 0
-#define DEFAULT_CUSTOM_SMILEYS 0
-
-#define DEFAULT_EVENT_NOTIFICATIONS_ENABLE 1
-#define DEFAULT_EVENT_FEEDS_ENABLE 1
-#define DEFAULT_EVENT_OTHER_ENABLE 1
-#define DEFAULT_EVENT_CLIENT_ENABLE 1
-#define DEFAULT_EVENT_COLBACK 0x00ffffff
-#define DEFAULT_EVENT_COLTEXT 0x00000000
-#define DEFAULT_EVENT_TIMEOUT_TYPE 0
-#define DEFAULT_EVENT_TIMEOUT 20
+#define FACEBOOK_MINIMAL_POLL_RATE 10
+#define FACEBOOK_DEFAULT_POLL_RATE 24 // in seconds
+#define FACEBOOK_MAXIMAL_POLL_RATE 60
+
+#define DEFAULT_FORCE_HTTPS 0
+#define DEFAULT_FORCE_HTTPS_CHANNEL 0
+#define DEFAULT_SET_MIRANDA_STATUS 0
+#define DEFAULT_LOGGING_ENABLE 0
+#define DEFAULT_SYSTRAY_NOTIFY 0
+#define DEFAULT_DISABLE_STATUS_NOTIFY 0
+#define DEFAULT_BIG_AVATARS 0
+#define DEFAULT_DISCONNECT_CHAT 0
+#define DEFAULT_MAP_STATUSES 0
+#define DEFAULT_LOAD_MOBILE 0
+#define DEFAULT_CUSTOM_SMILEYS 0
+
+#define DEFAULT_EVENT_NOTIFICATIONS_ENABLE 1
+#define DEFAULT_EVENT_FEEDS_ENABLE 1
+#define DEFAULT_EVENT_OTHER_ENABLE 1
+#define DEFAULT_EVENT_CLIENT_ENABLE 1
+#define DEFAULT_EVENT_COLBACK 0x00ffffff
+#define DEFAULT_EVENT_COLTEXT 0x00000000
+#define DEFAULT_EVENT_TIMEOUT_TYPE 0
+#define DEFAULT_EVENT_TIMEOUT 20
// Event flags
-#define FACEBOOK_EVENT_CLIENT 0x10000000 // Facebook error or info message
-#define FACEBOOK_EVENT_NEWSFEED 0x20000000 // Facebook newsfeed (wall) message
-#define FACEBOOK_EVENT_NOTIFICATION 0x40000000 // Facebook new notification
-#define FACEBOOK_EVENT_OTHER 0x80000000 // Facebook other event - friend requests/new messages
+#define FACEBOOK_EVENT_CLIENT 0x10000000 // Facebook error or info message
+#define FACEBOOK_EVENT_NEWSFEED 0x20000000 // Facebook newsfeed (wall) message
+#define FACEBOOK_EVENT_NOTIFICATION 0x40000000 // Facebook new notification
+#define FACEBOOK_EVENT_OTHER 0x80000000 // Facebook other event - friend requests/new messages
// Facebook request types // TODO: Provide MS_ and release in FB plugin API?
-#define FACEBOOK_REQUEST_LOGIN 100 // connecting physically
-#define FACEBOOK_REQUEST_SETUP_MACHINE 102 // setting machine name
-#define FACEBOOK_REQUEST_LOGOUT 106 // disconnecting physically
-#define FACEBOOK_REQUEST_HOME 110 // getting own name, avatar, ...
-#define FACEBOOK_REQUEST_DTSG 111 // getting __fb_dtsg__
-#define FACEBOOK_REQUEST_SEARCH 112 // searching
-#define FACEBOOK_REQUEST_BUDDY_LIST 120 // getting regular updates (friends online, ...)
-#define FACEBOOK_REQUEST_LOAD_FRIENDS 121 // getting list of all friends
-#define FACEBOOK_REQUEST_FEEDS 122 // getting feeds
-#define FACEBOOK_REQUEST_NOTIFICATIONS 123 // getting notifications
-#define FACEBOOK_REQUEST_UNREAD_MESSAGES 124 // getting unread messages
-#define FACEBOOK_REQUEST_LOAD_REQUESTS 125 // getting friend requests
-#define FACEBOOK_REQUEST_REQUEST_FRIEND 126 // requesting friends
-#define FACEBOOK_REQUEST_APPROVE_FRIEND 127 // approving friends
-#define FACEBOOK_REQUEST_DELETE_FRIEND 128 // deleting friends
-#define FACEBOOK_REQUEST_CANCEL_REQUEST 129 // canceling friends request
-#define FACEBOOK_REQUEST_RECONNECT 130 // getting __sequence_num__ and __channel_id__
-#define FACEBOOK_REQUEST_STATUS_SET 251 // setting my "What's on my mind?"
-#define FACEBOOK_REQUEST_MESSAGE_SEND 300 // sending message
+#define FACEBOOK_REQUEST_LOGIN 100 // connecting physically
+#define FACEBOOK_REQUEST_LOGOUT 101 // disconnecting physically
+#define FACEBOOK_REQUEST_SETUP_MACHINE 102 // setting machine name
+#define FACEBOOK_REQUEST_HOME 103 // getting own name, avatar, ...
+#define FACEBOOK_REQUEST_DTSG 104 // getting __fb_dtsg__
+#define FACEBOOK_REQUEST_RECONNECT 105 // getting __sequence_num__ and __channel_id__
+#define FACEBOOK_REQUEST_VISIBILITY 305 // setting chat visibility
+
+#define FACEBOOK_REQUEST_FEEDS 120 // getting feeds
+#define FACEBOOK_REQUEST_NOTIFICATIONS 121 // getting notifications
+#define FACEBOOK_REQUEST_LOAD_REQUESTS 122 // getting friend requests
+
+#define FACEBOOK_REQUEST_STATUS_SET 130 // setting my "What's on my mind?"
+#define FACEBOOK_REQUEST_SEARCH 140 // searching
+#define FACEBOOK_REQUEST_POKE 150 // sending pokes
+#define FACEBOOK_REQUEST_NOTIFICATIONS_READ 151 // marking notifications read
+
+#define FACEBOOK_REQUEST_BUDDY_LIST 200 // getting regular updates (friends online, ...)
+#define FACEBOOK_REQUEST_LOAD_FRIENDS 201 // getting list of all friends
+#define FACEBOOK_REQUEST_REQUEST_FRIEND 210 // requesting friends
+#define FACEBOOK_REQUEST_APPROVE_FRIEND 211 // approving friends
+#define FACEBOOK_REQUEST_DELETE_FRIEND 212 // deleting friends
+#define FACEBOOK_REQUEST_CANCEL_REQUEST 213 // canceling friends request
+
+#define FACEBOOK_REQUEST_MESSAGE_SEND 300 // sending message
#define FACEBOOK_REQUEST_MESSAGE_SEND2 301 // sending message through inbox
-#define FACEBOOK_REQUEST_MESSAGES_RECEIVE 302 // receiving messages
-#define FACEBOOK_REQUEST_TYPING_SEND 304 // sending typing notification
-#define FACEBOOK_REQUEST_VISIBILITY 305 // setting chat visibility
-#define FACEBOOK_REQUEST_ASYNC 307 // marking messages read and getting other things
-#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
+#define FACEBOOK_REQUEST_MESSAGES_RECEIVE 302 // receiving messages
+#define FACEBOOK_REQUEST_TYPING_SEND 303 // sending typing notification
+
+#define FACEBOOK_REQUEST_THREAD_INFO 400 // getting thread info
+#define FACEBOOK_REQUEST_UNREAD_THREADS 401 // getting unread threads
+#define FACEBOOK_REQUEST_UNREAD_MESSAGES 402 // getting unread messages
+#define FACEBOOK_REQUEST_ASYNC 403 // marking messages read and getting other things
+#define FACEBOOK_REQUEST_MARK_READ 404 // marking messages read (new)
// Send message types
-#define MESSAGE_INBOX 0
-#define MESSAGE_MERCURY 1
-#define MESSAGE_TID 2
-#define MESSAGE_ASYNC 3
+#define MESSAGE_INBOX 0
+#define MESSAGE_MERCURY 1
+#define MESSAGE_TID 2
+#define MESSAGE_ASYNC 3
// Contact types
-#define FACEBOOK_CONTACT_FRIEND 1 // contact that IS on our server list
-#define FACEBOOK_CONTACT_NONE 2 // contact that ISN'T on our server list
-#define FACEBOOK_CONTACT_REQUEST 3 // contact that we asked for friendship
-#define FACEBOOK_CONTACT_APPROVE 4 // contact that is asking us for approval of friendship
+#define FACEBOOK_CONTACT_FRIEND 1 // contact that IS on our server list
+#define FACEBOOK_CONTACT_NONE 2 // contact that ISN'T on our server list
+#define FACEBOOK_CONTACT_REQUEST 3 // contact that we asked for friendship
+#define FACEBOOK_CONTACT_APPROVE 4 // contact that is asking us for approval of friendship
typedef struct {
const char *name;
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index ce440d6019..9ec6aec3b0 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -273,7 +273,7 @@ void FacebookProto::ProcessUnreadMessages(void*)
{
std::string get_data = "&page=" + page;
- http::response resp = facy.flap(FACEBOOK_REQUEST_UNREAD_MESSAGES, NULL, &get_data);
+ http::response resp = facy.flap(FACEBOOK_REQUEST_UNREAD_THREADS, NULL, &get_data);
// Process result data
facy.validate_response(&resp);
@@ -310,119 +310,85 @@ void FacebookProto::ProcessUnreadMessage(void *tid_data)
if (tid_data == NULL)
return;
- std::string* tid = (std::string*)tid_data;
+ // TODO: get them from /ajax/mercury/thread_info.php
- std::string data = "&fb_dtsg=" + facy.dtsg_;
- data += "&lsd=&phstamp=" + utils::time::mili_timestamp();
- data += "&__user=" + facy.self_.user_id;
-
- std::string get_data = "sk=inbox&query=is%3Aunread&thread_query=is%3Aunread&action=read&tid=" + *tid;
- http::response resp = facy.flap(FACEBOOK_REQUEST_ASYNC, &data, &get_data);
- // TODO: move this to new thread...
+ std::string get_data = "tid=" + *(std::string*)tid_data;
+ delete (std::string*)tid_data;
+ http::response resp = facy.flap(FACEBOOK_REQUEST_UNREAD_MESSAGES, NULL, &get_data);
facy.validate_response(&resp);
if (resp.code != HTTP_CODE_OK) {
LOG(" !! !! Error when getting messages list");
- delete tid;
return;
}
-
- std::string messageslist = utils::text::slashu_to_utf8(resp.data);
-
- std::string user_id = utils::text::source_get_value(&messageslist, 2, "single_thread_id\":", ",");
- if (user_id.empty()) {
- LOG(" !! !! Thread id is empty - this is groupchat message."); // TODO: remove as this is not such 'error'
- delete tid;
+
+ if (resp.data.find("<option value=\"leave_conversation\">") != std::string::npos) {
+ LOG(" !! !! This is multi user chat");
return;
}
- facebook_user fbu;
- fbu.user_id = user_id;
- fbu.real_name = utils::text::source_get_value(&messageslist, 2, "sender_name\":\"", "\"");
+ std::string messageslist = utils::text::source_get_value(&resp.data, 2, "id=\"messageGroup\">", "</form>");
- HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE);
- // TODO: if contact is newly added, get his user info
- // TODO: maybe create new "receiveMsg" function and use it for offline and channel messages?
+ facebook_user fbu;
+ HANDLE hContact;
- std::string::size_type pos2 = 0;
- while ((pos2 = messageslist.find("class=\\\"MessagingMessage ", pos2)) != std::string::npos) {
- pos2 += 8;
- std::string strclass = messageslist.substr(pos2, messageslist.find("\\\"", pos2) - pos2);
+ std::string::size_type pos, pos2 = 0;
+ while ((pos2 = messageslist.find("class=\"acw apl abt", pos2)) != std::string::npos) {
+ pos2 += 19;
+ std::string group = messageslist.substr(pos2, messageslist.find("class=\"actions ", pos2) - pos2);
- if (strclass.find("MessagingMessageUnread") == std::string::npos)
- continue; // ignoring old messages
+ if (group.find("has_attachment&quot;:true") != std::string::npos) {
+ // TODO: do something different for attachements? (inspiration in revision <5236)
+ }
- //std::string::size_type pos3 = messageslist.find("/li>", pos2); // TODO: ne proti tomuhle li, protože i přílohy mají li...
- std::string::size_type pos3 = messageslist.find("class=\\\"MessagingMessage ", pos2);
- std::string messagesgroup = messageslist.substr(pos2, pos3 - pos2);
+ while ((pos = group.find("<div data-store=", pos)) != std::string::npos) {
+ std::string message = group.substr(pos, group.find("</div>", pos) - pos);
+ pos++;
- DWORD timestamp = utils::conversion::to_timestamp(utils::text::source_get_value(&messagesgroup, 2, "data-utime=\\\"", "\\\""));
+ std::string author = utils::text::source_get_value2(&message, "author&quot;:", ",}");
- pos3 = 0;
- while ((pos3 = messagesgroup.find("class=\\\"content noh", pos3)) != std::string::npos)
- {
- std::string message_attachments = "";
- std::string::size_type pos4 = 0;
- if ((pos4 = messagesgroup.find("class=\\\"attachments\\\"", pos4)) != std::string::npos) {
- std::string attachments = messagesgroup.substr(pos4, messagesgroup.find("<\\/ul", pos4) - pos4);
-
- pos4 = 0;
- while ((pos4 = attachments.find("<li", pos4)) != std::string::npos) {
- std::string attachment = attachments.substr(pos4, attachments.find("<\\/li>", pos4) - pos4);
- std::string link = utils::text::source_get_value(&attachment, 4, "<a class=", "attachment", "href=\\\"", "\\\"");
-
- link = utils::text::trim(
- utils::text::special_expressions_decode(link));
-
- // or first: std::string name = utils::text::source_get_value(&attachment, 4, "<a class=", "attachment", ">", "<\\/a>");
- std::string name = utils::text::trim(
- utils::text::special_expressions_decode(
- utils::text::remove_html(attachment)));
-
- if (link.find("/ajax/messaging/attachments/photo/dialog.php?uri=") != std::string::npos) {
- link = link.substr(49);
- link = utils::url::decode(link);
- }
-
- message_attachments += "< " + name + " > " + FACEBOOK_URL_HOMEPAGE;
- message_attachments += link + "\r\n";
-
- pos4++;
- }
+ // Ignore our messages
+ if (author == facy.self_.user_id)
+ continue;
+ // Get/create contact
+ if (hContact == NULL) {
+ fbu.user_id = author;
+ fbu.real_name = utils::text::slashu_to_utf8(utils::text::source_get_value(&group, 2, "name&quot;:&quot;", "&quot;"));
+ hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE);
+ // TODO: if contact is newly added, get his user info
+ // TODO: maybe create new "receiveMsg" function and use it for offline and channel messages?
}
- std::string message_text = messagesgroup.substr(pos3, messagesgroup.find("<\\/div", pos3) + 6 - pos3);
- message_text = utils::text::source_get_value(&message_text, 2, "\\\">", "<\\/div");
- message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::remove_html(message_text)), true);
- pos3++;
+ DWORD timestamp = utils::conversion::to_timestamp(utils::text::source_get_value2(&message, "timestamp&quot;:", ",}"));
+ std::string text = utils::text::source_get_value(&message, 2, "<span>", "</span>");
- if (message_text.empty())
- continue;
+ text = utils::text::trim(utils::text::special_expressions_decode(utils::text::remove_html(text)));
+ // TODO: fix smileys in text
+ /*
+ <img src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/yH/r/SOe5wIZyutW.png" width="16" height="16" class="img"/>
- LOG("Got unread message: \"%s\"", message_text.c_str());
+ "yH/r/viyyiQhRqLr.png" -> :-P
+ "yo/r/X8YPpi6kcyo.png" -> :-)
+ "yH/r/SOe5wIZyutW.png" -> :-D
+ ...
+ */
- ParseSmileys(message_text, hContact);
+ if (text.empty() || hContact == NULL)
+ continue;
- if (!message_attachments.empty()) {
- if (!message_text.empty())
- message_text += "\r\n\r\n";
+ LOG("Got unread message: \"%s\"", text.c_str());
- message_text += Translate("Attachments:");
- message_text += "\r\n" + message_attachments;
- }
+ ParseSmileys(text, hContact);
PROTORECVEVENT recv = {0};
recv.flags = PREF_UTF;
- recv.szMessage = const_cast<char*>(message_text.c_str());
+ recv.szMessage = const_cast<char*>(text.c_str());
recv.timestamp = timestamp;
ProtoChainRecvMsg(hContact, &recv);
}
-
}
-
- delete tid;
}
void FacebookProto::ProcessMessages(void* data)