title.c_str(), news[i]->text.c_str());
ptrT szTitle( mir_utf8decodeT(news[i]->title.c_str()));
ptrT szText( mir_utf8decodeT(news[i]->text.c_str()));
NotifyEvent(szTitle,szText,this->ContactIDToHContact(news[i]->user_id),FACEBOOK_EVENT_NEWSFEED, &news[i]->link);
delete news[i];
}
news.clear();
this->facy.last_feeds_update_ = ::time(NULL);
debugLogA("***** Feeds processed");
CODE_BLOCK_CATCH
debugLogA("***** Error processing feeds: %s", e.what());
CODE_BLOCK_END
exit:
delete resp;
}
void FacebookProto::SearchAckThread(void *targ)
{
facy.handle_entry("searchAckThread");
int count = 0;
char *arg = mir_utf8encodeT((TCHAR*)targ);
std::string search = utils::url::encode(arg);
std::string ssid;
while (count < 50 && !isOffline())
{
std::string get_data = search + "&s=" + utils::conversion::to_string(&count, UTILS_CONV_UNSIGNED_NUMBER);
if (!ssid.empty())
get_data += "&ssid=" + ssid;
http::response resp = facy.flap(REQUEST_SEARCH, NULL, &get_data);
if (resp.code == HTTP_CODE_OK)
{
std::string items = utils::text::source_get_value(&resp.data, 2, "");
std::string::size_type pos = 0;
std::string::size_type pos2 = 0;
while ((pos = items.find("", pos)) != std::string::npos) {
std::string item = items.substr(pos, items.find("", pos) - pos);
pos++; count++;
std::string id = utils::text::source_get_value2(&item, "?id=", "&\"");
if (id.empty())
id = utils::text::source_get_value2(&item, "?ids=", "&\"");
std::string name = utils::text::source_get_value(&item, 4, " | ", "", "");
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 + 30, name.length() - pos2 - 31); // also remove brackets around nickname
name = name.substr(0, pos2 - 1);
}
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;
ptrT tid( mir_utf8decodeT(id.c_str()));
ptrT tname( mir_utf8decodeT(utils::text::special_expressions_decode(name).c_str()));
ptrT tsurname( mir_utf8decodeT(utils::text::special_expressions_decode(surname).c_str()));
ptrT tnick( mir_utf8decodeT(utils::text::special_expressions_decode(nick).c_str()));
ptrT tcommon( mir_utf8decodeT(utils::text::special_expressions_decode(common).c_str()));
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(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, targ, (LPARAM)&isr);
}
ssid = utils::text::source_get_value(&items, 3, "id=\"more_objects\"", "ssid=", "&");
if (ssid.empty())
break; // No more results
}
}
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, targ, 0);
facy.handle_success("searchAckThread");
mir_free(targ);
mir_free(arg);
}
void FacebookProto::SearchIdAckThread(void *targ)
{
facy.handle_entry("searchIdAckThread");
char *arg = mir_utf8encodeT((TCHAR*)targ);
std::string search = utils::url::encode(arg) + "?";
if (!isOffline())
{
http::response resp = facy.flap(REQUEST_USER_INFO, NULL, &search);
if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end()) {
search = utils::text::source_get_value(&resp.headers["Location"], 2, FACEBOOK_SERVER_MOBILE"/", "_rdr", true);
resp = facy.flap(REQUEST_USER_INFO, NULL, &search);
}
if (resp.code == HTTP_CODE_OK)
{
std::string about = utils::text::source_get_value(&resp.data, 2, " ", "");
std::string surname;
std::string::size_type pos;
if ((pos = name.find(" ")) != std::string::npos) {
surname = name.substr(pos + 1, name.length() - pos - 1);
name = name.substr(0, pos);
}
// ignore self contact and empty ids
if (!id.empty() && id != facy.self_.user_id){
ptrT tid( mir_utf8decodeT(id.c_str()));
ptrT tname( mir_utf8decodeT(name.c_str()));
ptrT tsurname( mir_utf8decodeT(surname.c_str()));
PROTOSEARCHRESULT isr = {0};
isr.cbSize = sizeof(isr);
isr.flags = PSR_TCHAR;
isr.id = tid;
isr.firstName = tname;
isr.lastName = tsurname;
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, targ, (LPARAM)&isr);
}
}
}
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, targ, 0);
facy.handle_success("searchIdAckThread");
mir_free(targ);
mir_free(arg);
}
|