", pos) - pos);
pos++;
std::string author = utils::text::source_get_value2(&message, "author":", ",}");
// 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":"", """));
hContact = AddToContactList(&fbu, 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?
}
DWORD timestamp = utils::conversion::to_timestamp(utils::text::source_get_value2(&message, "timestamp":", ",}"));
std::string text = utils::text::source_get_value(&message, 2, "
", "");
text = utils::text::trim(utils::text::special_expressions_decode(utils::text::remove_html(text)));
// TODO: fix smileys in text
/*
"yH/r/viyyiQhRqLr.png" -> :-P
"yo/r/X8YPpi6kcyo.png" -> :-)
"yH/r/SOe5wIZyutW.png" -> :-D
...
*/
if (text.empty() || hContact == NULL)
continue;
LOG("Got unread message: \"%s\"", text.c_str());
ParseSmileys(text, hContact);
PROTORECVEVENT recv = {0};
recv.flags = PREF_UTF;
recv.szMessage = const_cast
(text.c_str());
recv.timestamp = timestamp;
ProtoChainRecvMsg(hContact, &recv);
}
}
}
void FacebookProto::ProcessMessages(void* data)
{
if (data == NULL)
return;
std::string* resp = (std::string*)data;
if (isOffline())
goto exit;
LOG("***** Starting processing messages");
CODE_BLOCK_TRY
std::vector< facebook_message* > messages;
std::vector< facebook_notification* > notifications;
facebook_json_parser* p = new facebook_json_parser(this);
p->parse_messages(data, &messages, ¬ifications);
delete p;
bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0);
for(std::vector::size_type i=0; iuser_id != facy.self_.user_id)
{
LOG(" Got message: %s", messages[i]->message_text.c_str());
facebook_user fbu;
fbu.user_id = messages[i]->user_id;
fbu.real_name = messages[i]->sender_name;
HANDLE hContact = AddToContactList(&fbu, CONTACT_NONE);
setString(hContact, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str());
// TODO: if contact is newly added, get his user info
// TODO: maybe create new "receiveMsg" function and use it for offline and channel messages?
ParseSmileys(messages[i]->message_text, hContact);
PROTORECVEVENT recv = {0};
recv.flags = PREF_UTF;
recv.szMessage = const_cast(messages[i]->message_text.c_str());
recv.timestamp = local_timestamp ? ::time(NULL) : messages[i]->time;
ProtoChainRecvMsg(hContact, &recv);
}
delete messages[i];
}
messages.clear();
for(std::vector::size_type i=0; itext.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, ¬ifications[i]->link, ¬ifications[i]->id);
mir_free(szTitle);
mir_free(szText);
delete notifications[i];
}
notifications.clear();
LOG("***** Messages processed");
CODE_BLOCK_CATCH
LOG("***** Error processing messages: %s", e.what());
CODE_BLOCK_END
exit:
delete resp;
}
void FacebookProto::ProcessNotifications(void*)
{
if (isOffline())
return;
if (!getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE))
return;
facy.handle_entry("notifications");
// Get notifications
http::response resp = facy.flap(REQUEST_NOTIFICATIONS);
// Process result data
facy.validate_response(&resp);
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("notifications");
return;
}
// Process notifications
LOG("***** Starting processing notifications");
CODE_BLOCK_TRY
std::vector< facebook_notification* > notifications;
facebook_json_parser* p = new facebook_json_parser(this);
p->parse_notifications(&(resp.data), ¬ifications);
delete p;
for(std::vector::size_type i=0; itext.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, ¬ifications[i]->link, ¬ifications[i]->id);
mir_free(szTitle);
mir_free(szText);
delete notifications[i];
}
notifications.clear();
LOG("***** Notifications processed");
CODE_BLOCK_CATCH
LOG("***** Error processing notifications: %s", e.what());
CODE_BLOCK_END
}
void FacebookProto::ProcessFriendRequests(void*)
{
facy.handle_entry("friendRequests");
// Get notifications
http::response resp = facy.flap(REQUEST_LOAD_REQUESTS);
// Process result data
facy.validate_response(&resp);
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("friendRequests");
return;
}
// Parse it
std::string reqs = utils::text::source_get_value(&resp.data, 2, "class=\"mRequestItem", "al aps\">");
std::string::size_type pos = 0;
std::string::size_type pos2 = 0;
bool last = false;
while (!last && !reqs.empty()) {
std::string req;
if ((pos2 = reqs.find("class=\"mRequestItem", pos)) != std::string::npos) {
req = reqs.substr(pos, pos2 - pos);
pos = pos2 + 19;
} else {
req = reqs.substr(pos);
last = true;
}
std::string get = utils::text::source_get_value(&req, 3, "