diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-01-31 11:36:42 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-01-31 11:36:42 +0000 |
commit | ab48390f184da37486fe37237f2c11e51fe7859d (patch) | |
tree | 3e2937c74687061c8f20669bc29acb3500c6d4e1 | |
parent | 8cafc95b05fb3714110a24ea4f611c89bdfb3aa1 (diff) |
Facebook: Ability to receive only inbox messages (hidden option)
git-svn-id: http://svn.miranda-ng.org/main/trunk@7970 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/FacebookRM/src/db.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 27 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.h | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 17 |
4 files changed, 37 insertions, 14 deletions
diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h index 03e4ed507d..d1094388ec 100644 --- a/protocols/FacebookRM/src/db.h +++ b/protocols/FacebookRM/src/db.h @@ -59,6 +59,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define FACEBOOK_KEY_LOCALE "Locale" // [HIDDEN] - en_US, cs_CZ, etc.
#define FACEBOOK_KEY_LOCAL_TIMESTAMP_UNREAD "UseLocalTimestampUnread" // [HIDDEN] - 1 = use local timestamp for offline messages
#define FACEBOOK_KEY_KEEP_UNREAD "KeepUnread" // [HIDDEN] - 1 = don't mark messages as read on server (works globally or per contact)
+#define FACEBOOK_KEY_INBOX_ONLY "InboxOnly" // [HIDDEN] - 1 = load messages only from "inbox" folder
#define FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE "EventNotificationsEnable"
#define FACEBOOK_KEY_EVENT_FEEDS_ENABLE "EventFeedsEnable"
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 4611d3119b..06118a9381 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -251,7 +251,7 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_ notification->id = id;
notification->link = utils::text::source_get_value(&text, 3, "<a ", "href=\"", "\"");
- notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "<abbr"));
+ notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "<abbr"));
notifications->push_back(notification);
}
@@ -349,7 +349,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)
+int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::vector< facebook_notification* >* notifications, bool inboxOnly)
{
std::string jsonData = static_cast< std::string* >(data)->substr(9);
@@ -451,6 +451,10 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa // inbox message (multiuser or direct)
JSONNODE *msg = json_get(it, "message");
+ JSONNODE *folder = json_get(it, "folder");
+
+ if (inboxOnly && json_as_pstring(folder) != "inbox")
+ continue;
JSONNODE *sender_fbid = json_get(msg, "sender_fbid");
JSONNODE *sender_name = json_get(msg, "sender_name");
@@ -729,7 +733,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa return EXIT_SUCCESS;
}
-int facebook_json_parser::parse_unread_threads(void* data, std::vector< std::string >* threads)
+int facebook_json_parser::parse_unread_threads(void* data, std::vector< std::string >* threads, bool inboxOnly)
{
std::string jsonData = static_cast< std::string* >(data)->substr(9);
@@ -755,6 +759,9 @@ int facebook_json_parser::parse_unread_threads(void* data, std::vector< std::str JSONNODE *folder = json_get(it, "folder");
JSONNODE *thread_ids = json_get(it, "thread_ids");
+ if (inboxOnly && json_as_pstring(folder) != "inbox")
+ continue;
+
for (unsigned int j = 0; j < json_size(thread_ids); j++) {
JSONNODE *id = json_at(thread_ids, j);
threads->push_back(json_as_pstring(id));
@@ -765,7 +772,7 @@ int facebook_json_parser::parse_unread_threads(void* data, std::vector< std::str return EXIT_SUCCESS;
}
-int facebook_json_parser::parse_thread_messages(void* data, std::vector< facebook_message* >* messages, std::map< std::string, facebook_chatroom* >* chatrooms, bool unreadOnly, int limit)
+int facebook_json_parser::parse_thread_messages(void* data, std::vector< facebook_message* >* messages, std::map< std::string, facebook_chatroom* >* chatrooms, bool unreadOnly, bool inboxOnly, int limit)
{
std::string jsonData = static_cast< std::string* >(data)->substr(9);
@@ -811,6 +818,7 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo JSONNODE *thread_id = json_get(it, "thread_id");
JSONNODE *name = json_get(it, "name");
JSONNODE *unread_count = json_get(it, "unread_count"); // TODO: use it to check against number of loaded messages... but how?
+ JSONNODE *folder = json_get(it, "folder");
std::map<std::string, facebook_chatroom*>::iterator iter = chatrooms->find(json_as_pstring(thread_id));
if (iter != chatrooms->end()) {
@@ -820,6 +828,9 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo if (canonical == NULL || thread_id == NULL)
continue;
+ if (inboxOnly && json_as_pstring(folder) != "inbox")
+ continue;
+
std::string id = json_as_pstring(canonical);
if (id == "null")
continue;
@@ -838,15 +849,19 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo JSONNODE *mid = json_get(it, "message_id");
JSONNODE *timestamp = json_get(it, "timestamp");
JSONNODE *filtered = json_get(it, "is_filtered_content");
+ JSONNODE *folder = json_get(it, "folder");
if (author == NULL || body == NULL || mid == NULL || tid == NULL || timestamp == NULL)
continue;
+ if (inboxOnly && json_as_pstring(folder) != "inbox")
+ continue;
+
std::string thread_id = json_as_pstring(tid);
- std::string message_id = json_as_pstring(mid);
+ std::string message_id = json_as_pstring(mid);
std::string message_text = json_as_pstring(body);
std::string author_id = json_as_pstring(author);
- std::string::size_type pos = author_id.find(":");
+ std::string::size_type pos = author_id.find(":");
if (pos != std::string::npos)
author_id = author_id.substr(pos+1);
diff --git a/protocols/FacebookRM/src/json.h b/protocols/FacebookRM/src/json.h index d506f0f50c..6cd89faac0 100644 --- a/protocols/FacebookRM/src/json.h +++ b/protocols/FacebookRM/src/json.h @@ -33,9 +33,9 @@ public: int parse_buddy_list(void*, List::List< facebook_user >*);
int parse_friends(void*, std::map< std::string, facebook_user* >*);
int parse_notifications(void*, std::vector< facebook_notification* >*);
- int parse_messages(void*, std::vector< facebook_message* >*, std::vector< facebook_notification* >*);
- int parse_unread_threads(void*, std::vector< std::string >*);
- int parse_thread_messages(void*, std::vector< facebook_message* >*, std::map< std::string, facebook_chatroom* >*, bool unreadOnly, int limit);
+ int parse_messages(void*, std::vector< facebook_message* >*, std::vector< facebook_notification* >*, bool inboxOnly);
+ int parse_unread_threads(void*, std::vector< std::string >*, bool inboxOnly);
+ int parse_thread_messages(void*, std::vector< facebook_message* >*, std::map< std::string, facebook_chatroom* >*, bool unreadOnly, bool inboxOnly, int limit);
int parse_thread_info(void* data, std::string* user_id);
facebook_json_parser(FacebookProto* proto)
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index e7528bda30..777ce172db 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -265,10 +265,11 @@ void FacebookProto::ProcessUnreadMessages(void*) {
facy.handle_entry("ProcessUnreadMessages");
- bool loadOther = true; // TODO: db setting? or use everytime?
+ // receive messages from all folders by default, use hidden setting to receive only inbox messages
+ bool inboxOnly = getBool(FACEBOOK_KEY_INBOX_ONLY, 0);
std::string data = "folders[0]=inbox";
- if (loadOther)
+ if (!inboxOnly)
data += "&folders[1]=other";
data += "&client=mercury";
data += "__user=" + facy.self_.user_id;
@@ -284,7 +285,7 @@ void FacebookProto::ProcessUnreadMessages(void*) std::vector<std::string> threads;
facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_unread_threads(&resp.data, &threads);
+ p->parse_unread_threads(&resp.data, &threads, inboxOnly);
delete p;
ForkThread(&FacebookProto::ProcessUnreadMessage, new std::vector<std::string>(threads));
@@ -319,6 +320,9 @@ void FacebookProto::ProcessUnreadMessage(void *p) // don't use local_timestamp for unread messages by default, use hidden setting to enable it
bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP_UNREAD, 0);
+ // receive messages from all folders by default, use hidden setting to receive only inbox messages
+ bool inboxOnly = getBool(FACEBOOK_KEY_INBOX_ONLY, 0);
+
http::response resp;
while (!threads.empty()) {
@@ -351,7 +355,7 @@ void FacebookProto::ProcessUnreadMessage(void *p) std::map<std::string, facebook_chatroom*> chatrooms;
facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_thread_messages(&resp.data, &messages, &chatrooms, true, limit);
+ p->parse_thread_messages(&resp.data, &messages, &chatrooms, true, inboxOnly, limit);
delete p;
for (std::map<std::string, facebook_chatroom*>::iterator it = chatrooms.begin(); it != chatrooms.end(); ) {
@@ -456,6 +460,9 @@ void FacebookProto::ProcessMessages(void* data) std::string* resp = (std::string*)data;
+ // receive messages from all folders by default, use hidden setting to receive only inbox messages
+ bool inboxOnly = getBool(FACEBOOK_KEY_INBOX_ONLY, 0);
+
if (isOffline())
goto exit;
@@ -467,7 +474,7 @@ void FacebookProto::ProcessMessages(void* data) std::vector< facebook_notification* > notifications;
facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_messages(data, &messages, ¬ifications);
+ p->parse_messages(data, &messages, ¬ifications, inboxOnly);
delete p;
bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0);
|