From 11705ab059a43f26a6928775179c0abcd369d1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Fri, 25 May 2012 20:20:00 +0000 Subject: Facebook: More search results (up to 50) git-svn-id: http://svn.miranda-ng.org/main/trunk@179 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/process.cpp | 139 ++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 62 deletions(-) (limited to 'protocols') diff --git a/protocols/FacebookRM/process.cpp b/protocols/FacebookRM/process.cpp index 4c51141cb1..056b8115dc 100644 --- a/protocols/FacebookRM/process.cpp +++ b/protocols/FacebookRM/process.cpp @@ -730,80 +730,95 @@ void FacebookProto::SearchAckThread(void *targ) { facy.handle_entry( "searchAckThread" ); - char *arg = mir_utf8encodeT((TCHAR*)targ); - std::string search = utils::url::encode( arg ); + int count = 0; - // Get notifications - http::response resp = facy.flap( FACEBOOK_REQUEST_SEARCH, NULL, &search ); + char *arg = mir_utf8encodeT((TCHAR*)targ); + std::string search = utils::url::encode( arg ); + std::string ssid; - // Process result data - facy.validate_response(&resp); - - if (resp.code == HTTP_CODE_OK) + while (count < 50 && !isOffline()) { - std::string items = utils::text::source_get_value(&resp.data, 3, "", ""); + std::string get_data = search + "&s=" + utils::conversion::to_string(&count, UTILS_CONV_UNSIGNED_NUMBER); + if (!ssid.empty()) + get_data += "&ssid=" + ssid; - std::string::size_type pos = 0; - std::string::size_type pos2 = 0; - bool last = false; + // Get notifications + http::response resp = facy.flap( FACEBOOK_REQUEST_SEARCH, NULL, &get_data ); - while (!last) { - std::string item; - if ((pos2 = items.find("
", pos)) != std::string::npos) { - item = items.substr(pos, pos2 - pos); - pos = pos2 + 14; - } else { - item = items.substr(pos); - last = true; - } + // Process result data + facy.validate_response(&resp); - std::string id = utils::text::source_get_value2(&item, "?id=", "&\""); - if (id.empty()) - id = utils::text::source_get_value2(&item, "?slog=", "&\""); + if (resp.code == HTTP_CODE_OK) + { + std::string items = utils::text::source_get_value(&resp.data, 3, "", ""); + + std::string::size_type pos = 0; + std::string::size_type pos2 = 0; + bool last = false; + + while (!last) { + std::string item; + if ((pos2 = items.find("
", pos)) != std::string::npos) { + item = items.substr(pos, pos2 - pos); + pos = pos2 + 14; + } else { + item = items.substr(pos); + last = true; + } - std::string name = utils::text::source_get_value(&item, 2, "", ""); - std::string surname; - std::string nick; - std::string common = utils::text::source_get_value(&item, 2, "", ""); + count++; - if ((pos2 = name.find(" ")) != std::string::npos) { - nick = name.substr(pos2 + 31, name.length() - pos2 - 32); // also remove brackets around nickname - name = name.substr(0, pos2); - } + std::string id = utils::text::source_get_value2(&item, "?id=", "&\""); + if (id.empty()) + id = utils::text::source_get_value2(&item, "?slog=", "&\""); + + std::string name = utils::text::source_get_value(&item, 2, "", ""); + std::string surname; + std::string nick; + std::string common = utils::text::source_get_value(&item, 2, "", ""); + + if ((pos2 = name.find(" ")) != std::string::npos) { + nick = name.substr(pos2 + 31, name.length() - pos2 - 32); // also remove brackets around nickname + name = name.substr(0, pos2); + } + + if ((pos2 = name.find(" ")) != std::string::npos) { + surname = name.substr(pos2 + 1, name.length() - pos2 - 1); + name = name.substr(0, pos2); + } - if ((pos2 = name.find(" ")) != std::string::npos) { - surname = name.substr(pos2 + 1, name.length() - pos2 - 1); - name = name.substr(0, pos2); + // ignore self contact and empty ids + if (id.empty() || id == facy.self_.user_id) + continue; + + TCHAR* tid = mir_a2t_cp(id.c_str(), CP_UTF8); + TCHAR* tname = mir_a2t_cp(name.c_str(), CP_UTF8); + TCHAR* tsurname = mir_a2t_cp(surname.c_str(), CP_UTF8); + TCHAR* tnick = mir_a2t_cp(nick.c_str(), CP_UTF8); + TCHAR* tcommon = mir_a2t_cp(common.c_str(), CP_UTF8); + + PROTOSEARCHRESULT isr = {0}; + isr.cbSize = sizeof(isr); + isr.flags = PSR_TCHAR; + isr.id = tid; + isr.nick = tnick; + isr.firstName = tname; + isr.lastName = tsurname; + isr.email = tcommon; + + ProtoBroadcastAck(m_szModuleName, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, targ, (LPARAM)&isr); + + mir_free(tid); + mir_free(tnick); + mir_free(tname); + mir_free(tsurname); + mir_free(tcommon); } - // ignore self contact and empty ids - if (id.empty() || id == facy.self_.user_id) - continue; - - TCHAR* tid = mir_a2t_cp(id.c_str(), CP_UTF8); - TCHAR* tname = mir_a2t_cp(name.c_str(), CP_UTF8); - TCHAR* tsurname = mir_a2t_cp(surname.c_str(), CP_UTF8); - TCHAR* tnick = mir_a2t_cp(nick.c_str(), CP_UTF8); - TCHAR* tcommon = mir_a2t_cp(common.c_str(), CP_UTF8); - - PROTOSEARCHRESULT isr = {0}; - isr.cbSize = sizeof(isr); - isr.flags = PSR_TCHAR; - isr.id = tid; - isr.nick = tnick; - isr.firstName = tname; - isr.lastName = tsurname; - isr.email = tcommon; - - ProtoBroadcastAck(m_szModuleName, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, targ, (LPARAM)&isr); - - mir_free(tid); - mir_free(tnick); - mir_free(tname); - mir_free(tsurname); - mir_free(tcommon); + ssid = utils::text::source_get_value(&items, 3, "id=\"more_objects\"", "ssid=", "&"); + if (ssid.empty()) + break; // No more results } - } ProtoBroadcastAck(m_szModuleName, NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, targ, 0); -- cgit v1.2.3