summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2012-05-24 15:40:11 +0000
committerRobert Pösel <robyer@seznam.cz>2012-05-24 15:40:11 +0000
commit73d90fba8c5a90e1195481efa7e59535cf156413 (patch)
tree5a840a24e5f5da25fbc30921d01fae2c31b6adb3
parentf78628ed14bc7aa0fd3a7e10c5cb25c71e7748db (diff)
Update for Facebook RM (processing friend requests, searching support,...)
git-svn-id: http://svn.miranda-ng.org/main/trunk@164 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/FacebookRM/chat.cpp4
-rw-r--r--protocols/FacebookRM/communication.cpp97
-rw-r--r--protocols/FacebookRM/connection.cpp9
-rw-r--r--protocols/FacebookRM/constants.h6
-rw-r--r--protocols/FacebookRM/contacts.cpp57
-rw-r--r--protocols/FacebookRM/db.h1
-rw-r--r--protocols/FacebookRM/entities.h2
-rw-r--r--protocols/FacebookRM/json.cpp15
-rw-r--r--protocols/FacebookRM/messages.cpp4
-rw-r--r--protocols/FacebookRM/process.cpp148
-rw-r--r--protocols/FacebookRM/proto.cpp88
-rw-r--r--protocols/FacebookRM/proto.h8
-rw-r--r--protocols/FacebookRM/stubs.cpp27
-rw-r--r--protocols/FacebookRM/theme.cpp18
-rw-r--r--protocols/FacebookRM/utils.cpp18
-rw-r--r--protocols/FacebookRM/utils.h4
16 files changed, 422 insertions, 84 deletions
diff --git a/protocols/FacebookRM/chat.cpp b/protocols/FacebookRM/chat.cpp
index 7326254541..5fc0c8ac6e 100644
--- a/protocols/FacebookRM/chat.cpp
+++ b/protocols/FacebookRM/chat.cpp
@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common.h"
-void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message)
+void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp)
{
GCDEST gcd = { m_szModuleName };
gcd.ptszID = mir_a2t(chat_id);
@@ -30,7 +30,7 @@ void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *
GCEVENT gce = {sizeof(gce)};
gce.pDest = &gcd;
gce.ptszText = mir_a2t_cp(message,CP_UTF8);
- gce.time = ::time(NULL);
+ gce.time = timestamp ? timestamp : ::time(NULL);
gce.dwFlags = GC_TCHAR;
gcd.iType = GC_EVENT_MESSAGE;
gce.bIsMe = !strcmp(id,facy.self_.user_id.c_str());
diff --git a/protocols/FacebookRM/communication.cpp b/protocols/FacebookRM/communication.cpp
index d17e40e5a5..5b2cb60ace 100644
--- a/protocols/FacebookRM/communication.cpp
+++ b/protocols/FacebookRM/communication.cpp
@@ -229,8 +229,11 @@ DWORD facebook_client::choose_security_level( int request_type )
// case FACEBOOK_REQUEST_HOME:
// case FACEBOOK_REQUEST_BUDDY_LIST:
// case FACEBOOK_REQUEST_LOAD_FRIENDS:
+// case FACEBOOK_REQUEST_LOAD_REQUESTS:
+// case FACEBOOK_REQUEST_SEARCH:
// case FACEBOOK_REQUEST_DELETE_FRIEND:
-// case FACEBOOK_REQUEST_ADD_FRIEND:
+// case FACEBOOK_REQUEST_REQUEST_FRIEND:
+// case FACEBOOK_REQUEST_APPROVE_FRIEND:
// case FACEBOOK_REQUEST_FEEDS:
// case FACEBOOK_REQUEST_NOTIFICATIONS:
// case FACEBOOK_REQUEST_RECONNECT:
@@ -261,7 +264,8 @@ int facebook_client::choose_method( int request_type )
case FACEBOOK_REQUEST_TYPING_SEND:
case FACEBOOK_REQUEST_LOGOUT:
case FACEBOOK_REQUEST_DELETE_FRIEND:
- case FACEBOOK_REQUEST_ADD_FRIEND:
+ case FACEBOOK_REQUEST_REQUEST_FRIEND:
+ case FACEBOOK_REQUEST_APPROVE_FRIEND:
return REQUEST_POST;
// case FACEBOOK_REQUEST_HOME:
@@ -269,7 +273,9 @@ int facebook_client::choose_method( int request_type )
// case FACEBOOK_REQUEST_FEEDS:
// case FACEBOOK_REQUEST_NOTIFICATIONS:
// case FACEBOOK_REQUEST_RECONNECT:
-// case FACEBOOK_REQUEST_LOAD_FRIENDS:
+// case FACEBOOK_REQUEST_LOAD_FRIENDS:
+// case FACEBOOK_REQUEST_LOAD_REQUESTS:
+// case FACEBOOK_REQUEST_SEARCH:
default:
return REQUEST_GET;
}
@@ -292,6 +298,8 @@ std::string facebook_client::choose_proto( int request_type )
// case FACEBOOK_REQUEST_RECONNECT:
// case FACEBOOK_REQUEST_BUDDY_LIST:
// case FACEBOOK_REQUEST_LOAD_FRIENDS:
+// case FACEBOOK_REQUEST_LOAD_REQUESTS:
+// case FACEBOOK_REQUEST_SEARCH:
// case FACEBOOK_REQUEST_STATUS_SET:
// case FACEBOOK_REQUEST_MESSAGE_SEND:
// case FACEBOOK_REQUEST_MESSAGES_RECEIVE:
@@ -300,7 +308,8 @@ std::string facebook_client::choose_proto( int request_type )
// case FACEBOOK_REQUEST_ASYNC:
// case FACEBOOK_REQUEST_TYPING_SEND:
// case FACEBOOK_REQUEST_DELETE_FRIEND:
-// case FACEBOOK_REQUEST_ADD_FRIEND:
+// case FACEBOOK_REQUEST_REQUEST_FRIEND:
+// case FACEBOOK_REQUEST_APPROVE_FRIEND:
default:
return HTTP_PROTO_REGULAR;
@@ -328,6 +337,11 @@ std::string facebook_client::choose_server( int request_type, std::string* data,
return server;
}
+ case FACEBOOK_REQUEST_APPROVE_FRIEND:
+ case FACEBOOK_REQUEST_LOAD_REQUESTS:
+ case FACEBOOK_REQUEST_SEARCH:
+ return FACEBOOK_SERVER_MOBILE;
+
// case FACEBOOK_REQUEST_LOGOUT:
// case FACEBOOK_REQUEST_HOME:
// case FACEBOOK_REQUEST_BUDDY_LIST:
@@ -343,7 +357,7 @@ std::string facebook_client::choose_server( int request_type, std::string* data,
// case FACEBOOK_REQUEST_TYPING_SEND:
// case FACEBOOK_REQUEST_SETUP_MACHINE:
// case FACEBOOK_REQUEST_DELETE_FRIEND:
-// case FACEBOOK_REQUEST_ADD_FRIEND:
+// case FACEBOOK_REQUEST_REQUEST_FRIEND:
default:
return FACEBOOK_SERVER_REGULAR;
}
@@ -375,16 +389,39 @@ std::string facebook_client::choose_action( int request_type, std::string* data,
return action;
}
+ case FACEBOOK_REQUEST_LOAD_REQUESTS:
+ {
+ return "/friends/";
+ }
+
+ case FACEBOOK_REQUEST_SEARCH:
+ {
+ std::string action = "/search/?search=people&query=";
+ if (get_data != NULL) {
+ action += *get_data;
+ }
+ return action;
+ }
+
case FACEBOOK_REQUEST_DELETE_FRIEND:
{
return "/ajax/profile/removefriend.php?__a=1";
}
- case FACEBOOK_REQUEST_ADD_FRIEND:
+ case FACEBOOK_REQUEST_REQUEST_FRIEND:
{
return "/ajax/add_friend/action.php?__a=1";
}
+ case FACEBOOK_REQUEST_APPROVE_FRIEND:
+ {
+ std::string action = "/a/notifications.php?__a=1";
+ if (get_data != NULL) {
+ action += "&" + (*get_data);
+ }
+ return action;
+ }
+
case FACEBOOK_REQUEST_FEEDS:
{
std::string action = "/ajax/intent.php?filter=";
@@ -421,7 +458,7 @@ std::string facebook_client::choose_action( int request_type, std::string* data,
return "/ajax/updatestatus.php?__a=1";
case FACEBOOK_REQUEST_MESSAGE_SEND:
- return "/ajax/chat/send.php?__a=1";
+ return "/ajax/messaging/send.php?__a=1";
case FACEBOOK_REQUEST_MESSAGES_RECEIVE:
{
@@ -477,6 +514,8 @@ NETLIBHTTPHEADER* facebook_client::get_request_headers( int request_type, int* h
case FACEBOOK_REQUEST_SETUP_MACHINE:
case FACEBOOK_REQUEST_BUDDY_LIST:
case FACEBOOK_REQUEST_LOAD_FRIENDS:
+ case FACEBOOK_REQUEST_LOAD_REQUESTS:
+ case FACEBOOK_REQUEST_SEARCH:
case FACEBOOK_REQUEST_STATUS_SET:
case FACEBOOK_REQUEST_MESSAGE_SEND:
case FACEBOOK_REQUEST_VISIBILITY:
@@ -484,7 +523,8 @@ NETLIBHTTPHEADER* facebook_client::get_request_headers( int request_type, int* h
case FACEBOOK_REQUEST_ASYNC:
case FACEBOOK_REQUEST_TYPING_SEND:
case FACEBOOK_REQUEST_DELETE_FRIEND:
- case FACEBOOK_REQUEST_ADD_FRIEND:
+ case FACEBOOK_REQUEST_REQUEST_FRIEND:
+ case FACEBOOK_REQUEST_APPROVE_FRIEND:
*headers_count = 5;
break;
@@ -506,6 +546,8 @@ NETLIBHTTPHEADER* facebook_client::get_request_headers( int request_type, int* h
case FACEBOOK_REQUEST_SETUP_MACHINE:
case FACEBOOK_REQUEST_BUDDY_LIST:
case FACEBOOK_REQUEST_LOAD_FRIENDS:
+ case FACEBOOK_REQUEST_LOAD_REQUESTS:
+ case FACEBOOK_REQUEST_SEARCH:
case FACEBOOK_REQUEST_STATUS_SET:
case FACEBOOK_REQUEST_MESSAGE_SEND:
case FACEBOOK_REQUEST_VISIBILITY:
@@ -513,7 +555,8 @@ NETLIBHTTPHEADER* facebook_client::get_request_headers( int request_type, int* h
case FACEBOOK_REQUEST_ASYNC:
case FACEBOOK_REQUEST_TYPING_SEND:
case FACEBOOK_REQUEST_DELETE_FRIEND:
- case FACEBOOK_REQUEST_ADD_FRIEND:
+ case FACEBOOK_REQUEST_REQUEST_FRIEND:
+ case FACEBOOK_REQUEST_APPROVE_FRIEND:
headers[4].szName = "Content-Type";
headers[4].szValue = "application/x-www-form-urlencoded; charset=utf-8";
@@ -813,18 +856,8 @@ bool facebook_client::home( )
// Get logout hash
this->logout_hash_ = utils::text::source_get_value( &resp.data, 2, "<input type=\"hidden\" autocomplete=\"off\" name=\"h\" value=\"", "\"" );
parent->Log(" Got self logout hash: %s", this->logout_hash_.c_str());
-
- // TODO: DIrectly get that friend requests
- // Get friend requests count and notify it
- std::string str_count = utils::text::source_get_value( &resp.data, 2, "<span id=\"requestsCountValue\">", "</span>" );
- if ( str_count.length() && str_count != std::string( "0" ) )
- {
- std::string message = Translate("Got new friend requests: ") + str_count;
- TCHAR* tmessage = mir_a2t(message.c_str());
- parent->NotifyEvent( parent->m_tszUserName, tmessage, NULL, FACEBOOK_EVENT_OTHER, TEXT(FACEBOOK_URL_REQUESTS) );
- mir_free( tmessage );
- }
+ std::string str_count;
if (!DBGetContactSettingByte(NULL,parent->m_szModuleName,FACEBOOK_KEY_PARSE_MESSAGES, DEFAULT_PARSE_MESSAGES))
{
@@ -1108,7 +1141,7 @@ bool facebook_client::send_message( std::string message_recipient, std::string m
http::response resp;
- if (parent->isInvisible() || use_inbox) {
+// if (parent->isInvisible() || use_inbox) {
// Use inbox send message when invisible
std::string data = "action=send&body=";
data += utils::url::encode( message_text );
@@ -1120,8 +1153,26 @@ bool facebook_client::send_message( std::string message_recipient, std::string m
data += ( post_form_id_.length( ) ) ? post_form_id_ : "0";
resp = flap( FACEBOOK_REQUEST_ASYNC, &data );
- } else {
+/* } else {
// Use standard send message
+ std::string timestamp = utils::time::mili_timestamp();
+
+ std::string data = "mid=id." + timestamp;
+
+ //data += "&tids[0]=";
+/* data += "&last_msg[subject]&last_msg[body]=" + utils::url::encode( message_text );
+ data += "&last_msg[timestamp]=" + timestamp;
+ data += "&last_msg[mid]=id." + timestamp;
+ //data += "&last_msg[tid]=";
+ data += "&last_msg[sender_fbid]=" + this->self_.user_id;
+ data += "&last_msg[offline_threading_id]&last_msg[sender]=Robyer%40facebook.com&last_msg[sender_name]=Robert%20P%C3%B6sel"
+ data += "&last_msg[tags]=source%3Atitan%3Aweb%2Cinbox&last_msg[source]=source%3Atitan%3Aweb&&last_msg[forward]=0&last_msg[replyActionType]=0&last_msg[coordinates]&last_msg[action_id]=0";
+*/ /*
+ data += "&mode=2&gigaboxx_reply=&&body=" + utils::url::encode(message_text);
+ data += "&action=send&force_sms&send_on_enter=true&fb_dtsg=" + (dtsg_.length() ? dtsg_ : "0");
+ data += "&__user=" + this->self_.user_id;
+ data += "&phstamp=0";
+
std::string data = "msg_text=";
data += utils::url::encode( message_text );
data += "&msg_id=";
@@ -1142,7 +1193,7 @@ bool facebook_client::send_message( std::string message_recipient, std::string m
data += ( post_form_id_.length( ) ) ? post_form_id_ : "0";
resp = flap( FACEBOOK_REQUEST_MESSAGE_SEND, &data );
- }
+ }*/
validate_response(&resp);
diff --git a/protocols/FacebookRM/connection.cpp b/protocols/FacebookRM/connection.cpp
index d60b1ec969..14b5c181c1 100644
--- a/protocols/FacebookRM/connection.cpp
+++ b/protocols/FacebookRM/connection.cpp
@@ -91,6 +91,9 @@ void FacebookProto::ChangeStatus(void*)
facy.load_friends();
+ // Process Friends requests
+ ForkThread( &FacebookProto::ProcessFriendRequests, this, NULL );
+
if (getByte(FACEBOOK_KEY_PARSE_MESSAGES, DEFAULT_PARSE_MESSAGES))
ForkThread( &FacebookProto::ProcessUnreadMessages, this );
@@ -188,7 +191,7 @@ void FacebookProto::UpdateLoop(void *)
time_t tim = ::time(NULL);
LOG( ">>>>> Entering Facebook::UpdateLoop[%d]", tim );
- for ( int i = -1; !isOffline(); i = ++i % 6 )
+ for ( int i = -1; !isOffline(); i = ++i % 100 )
{
if ( i != -1 ) {
if ( !facy.invisible_ )
@@ -198,6 +201,10 @@ void FacebookProto::UpdateLoop(void *)
if ( i == 2 && getByte( FACEBOOK_KEY_EVENT_FEEDS_ENABLE, DEFAULT_EVENT_FEEDS_ENABLE ) )
if ( !facy.feeds( ) )
break;
+
+ if ( i == 99 )
+ ForkThread( &FacebookProto::ProcessFriendRequests, this, NULL );
+
LOG( "***** FacebookProto::UpdateLoop[%d] going to sleep...", tim );
if ( WaitForSingleObjectEx( update_loop_lock_, GetPollRate( ) * 1000, true ) != WAIT_TIMEOUT )
break;
diff --git a/protocols/FacebookRM/constants.h b/protocols/FacebookRM/constants.h
index 3e0aaacb8e..93ae6022ee 100644
--- a/protocols/FacebookRM/constants.h
+++ b/protocols/FacebookRM/constants.h
@@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// 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_CHAT2 "%s-%s.facebook.com"
#define FACEBOOK_SERVER_LOGIN "login.facebook.com"
@@ -89,12 +90,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_REQUEST_SETUP_MACHINE 102 // setting machine name
#define FACEBOOK_REQUEST_LOGOUT 106 // disconnecting physically
#define FACEBOOK_REQUEST_HOME 110 // getting __post_form_id__ + __fb_dtsg__ + ...
+#define FACEBOOK_REQUEST_SEARCH 111 // 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_DELETE_FRIEND 122 // deleting friends
-#define FACEBOOK_REQUEST_ADD_FRIEND 123 // adding friends
+#define FACEBOOK_REQUEST_REQUEST_FRIEND 123 // requesting friends
+#define FACEBOOK_REQUEST_APPROVE_FRIEND 124 // approving friends
#define FACEBOOK_REQUEST_FEEDS 125 // getting feeds
#define FACEBOOK_REQUEST_NOTIFICATIONS 126 // getting notifications
+#define FACEBOOK_REQUEST_LOAD_REQUESTS 127 // getting friend requests
#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
diff --git a/protocols/FacebookRM/contacts.cpp b/protocols/FacebookRM/contacts.cpp
index 2a2cf4b368..0f1759e628 100644
--- a/protocols/FacebookRM/contacts.cpp
+++ b/protocols/FacebookRM/contacts.cpp
@@ -168,7 +168,7 @@ void FacebookProto::DeleteContactFromServer(void *data)
DBWriteContactSettingDword(fbu->handle, m_szModuleName, FACEBOOK_KEY_DELETED, ::time(NULL)); // set deleted time
}
- NotifyEvent(TranslateT("Deleting contact"), TranslateT("Contact was sucessfully removed from server."), NULL, FACEBOOK_EVENT_OTHER, NULL);
+ NotifyEvent(TranslateT("Deleting contact"), TranslateT("Contact was sucessfully removed from your server list."), NULL, FACEBOOK_EVENT_OTHER, NULL);
} else {
facy.client_notify( TranslateT("Error occured when removing contact from server.") );
}
@@ -198,7 +198,7 @@ void FacebookProto::AddContactToServer(void *data)
delete data;
// Get unread inbox threads
- http::response resp = facy.flap( FACEBOOK_REQUEST_ADD_FRIEND, &query );
+ http::response resp = facy.flap( FACEBOOK_REQUEST_REQUEST_FRIEND, &query );
// Process result data
facy.validate_response(&resp);
@@ -220,6 +220,46 @@ void FacebookProto::AddContactToServer(void *data)
}
+void FacebookProto::ApproveContactToServer(void *data)
+{
+ facy.handle_entry( "ApproveContactToServer" );
+
+ if ( data == NULL )
+ return;
+
+ std::string *id = (std::string*)data;
+
+ std::string post_data = "fb_dtsg=" + facy.dtsg_;
+ post_data += "&charset_test=%e2%82%ac%2c%c2%b4%2c%e2%82%ac%2c%c2%b4%2c%e6%b0%b4%2c%d0%94%2c%d0%84&confirm_button=";
+
+ std::string get_data;
+
+ HANDLE *hContact = (HANDLE*)data;
+
+ DBVARIANT dbv;
+ if (!DBGetContactSettingString(*hContact, m_szModuleName, FACEBOOK_KEY_APPROVE, &dbv))
+ {
+ get_data = dbv.pszVal;
+ DBFreeVariant(&dbv);
+ }
+
+ // replace absolute link to params only
+ utils::text::replace_first(&get_data, "/a/notifications.php?", "&");
+
+ http::response resp = facy.flap( FACEBOOK_REQUEST_APPROVE_FRIEND, &post_data, &get_data );
+
+ // Process result data
+ facy.validate_response(&resp);
+
+ if (resp.code != HTTP_CODE_OK)
+ facy.handle_error( "ApproveContactToServer" );
+ else {
+ NotifyEvent(TranslateT("Adding contact"), TranslateT("Contact was added to your server list."), NULL, FACEBOOK_EVENT_OTHER, NULL);
+ DBDeleteContactSetting(*hContact, m_szModuleName, FACEBOOK_KEY_APPROVE);
+ }
+
+ delete data;
+}
HANDLE FacebookProto::GetAwayMsg(HANDLE hContact)
{
@@ -231,15 +271,17 @@ int FacebookProto::OnContactDeleted(WPARAM wparam,LPARAM)
HANDLE hContact = (HANDLE)wparam;
DBVARIANT dbv;
- TCHAR text[512];
- if ( !DBGetContactSettingTString(hContact, m_szModuleName, FACEBOOK_KEY_NAME, &dbv) ) {
- mir_sntprintf(text,SIZEOF(text),TranslateT("Do you want to delete contact '%s' from server list?"),dbv.ptszVal);
+ char str[256];
+
+ if ( !DBGetContactSettingUTF8String(hContact, m_szModuleName, FACEBOOK_KEY_NAME, &dbv) ) {
+ mir_snprintf(str,SIZEOF(str),Translate("Do you want to delete contact '%s' from server list?"), dbv.pszVal);
DBFreeVariant(&dbv);
- } else if( !DBGetContactSettingTString(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv) ) {
- mir_sntprintf(text,SIZEOF(text),TranslateT("Do you want to delete contact '%s' from server list?"),dbv.ptszVal);
+ } else if( !DBGetContactSettingUTF8String(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv) ) {
+ mir_snprintf(str,SIZEOF(str),Translate("Do you want to delete contact '%s' from server list?"), dbv.pszVal);
DBFreeVariant(&dbv);
}
+ TCHAR *text = mir_a2t_cp(str, CP_UTF8);
if (MessageBox( 0, text, m_tszUserName, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2 ) == IDYES) {
if( !DBGetContactSettingString(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv) )
@@ -258,6 +300,7 @@ int FacebookProto::OnContactDeleted(WPARAM wparam,LPARAM)
}
}
+ mir_free(text);
return 0;
}
diff --git a/protocols/FacebookRM/db.h b/protocols/FacebookRM/db.h
index d928300e59..cadddef8ca 100644
--- a/protocols/FacebookRM/db.h
+++ b/protocols/FacebookRM/db.h
@@ -48,6 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_KEY_AV_URL "AvatarURL"
#define FACEBOOK_KEY_DELETED "Deleted"
#define FACEBOOK_KEY_CONTACT_TYPE "ContactType"
+#define FACEBOOK_KEY_APPROVE "ApproveAction"
#define FACEBOOK_KEY_DEF_GROUP "DefaultGroup"
#define FACEBOOK_KEY_FORCE_HTTPS "ForceHTTPS"
diff --git a/protocols/FacebookRM/entities.h b/protocols/FacebookRM/entities.h
index dbe32b8b51..c551e1ac53 100644
--- a/protocols/FacebookRM/entities.h
+++ b/protocols/FacebookRM/entities.h
@@ -62,7 +62,7 @@ struct facebook_message
std::string user_id;
std::string message_text;
std::string sender_name;
- time_t time;
+ DWORD time;
facebook_message( )
{
diff --git a/protocols/FacebookRM/json.cpp b/protocols/FacebookRM/json.cpp
index 4293f336f9..2231596882 100644
--- a/protocols/FacebookRM/json.cpp
+++ b/protocols/FacebookRM/json.cpp
@@ -288,7 +288,7 @@ int facebook_json_parser::parse_messages( void* data, std::vector< facebook_mess
const String& text = messageContent["text"];
//"tab_type":"friend", objMember["tab_type"]
- //const Number& time_sent = messageContent["time"];
+ const Number& time_sent = messageContent["time"];
// proto->Log("????? Checking time %15.2f > %15.2f", time_sent.Value(), proto->facy.last_message_time_);
if ((messageContent.Find("truncated") != messageContent.End())
@@ -299,11 +299,10 @@ int facebook_json_parser::parse_messages( void* data, std::vector< facebook_mess
proto->Log(msg.c_str());
} else if (last_msg != text.Value()) {
last_msg = text.Value();
-
facebook_message* message = new facebook_message( );
message->message_text = utils::text::special_expressions_decode(
utils::text::slashu_to_utf8( text.Value( ) ) );
- message->time = ::time( NULL ); // TODO: use real time from facebook
+ message->time = utils::time::fix_timestamp( time_sent.Value() );
message->user_id = was_id;
messages->push_back( message );
@@ -337,8 +336,7 @@ int facebook_json_parser::parse_messages( void* data, std::vector< facebook_mess
std::string row = ((const String &)objMember["thread_row"]).Value();
- //const Number& time_sent = messageContent["timestamp"];
-
+ const Number& time_sent = messageContent["timestamp"];
//proto->Log("????? Checking time %15.2f > %15.2f", time_sent.Value(), proto->facy.last_message_time_);
if (last_msg != text.Value()) {
@@ -351,7 +349,7 @@ int facebook_json_parser::parse_messages( void* data, std::vector< facebook_mess
message->sender_name = utils::text::special_expressions_decode(
utils::text::slashu_to_utf8( sender_name.Value( ) ) );
- message->time = ::time( NULL ); // TODO: user real time from facebook
+ message->time = utils::time::fix_timestamp( time_sent.Value() );
message->user_id = was_id; // TODO: Check if we have contact with this ID in friendlist and then do something different?
if (row.find("uiSplitPic",0) != std::string::npos) {
@@ -421,8 +419,11 @@ int facebook_json_parser::parse_messages( void* data, std::vector< facebook_mess
if (!proto->IsChatContact(group_id, was_id))
proto->AddChatContact(group_id, was_id, name.c_str());
+ const Number& time_sent = messageContent["time"];
+ DWORD timestamp = utils::time::fix_timestamp( time_sent.Value() );
+
// Add message into chat
- proto->UpdateChat(group_id, was_id, name.c_str(), msg.c_str());
+ proto->UpdateChat(group_id, was_id, name.c_str(), msg.c_str(), timestamp);
}
else if ( type.Value( ) == "thread_msg" ) // multiuser message
{
diff --git a/protocols/FacebookRM/messages.cpp b/protocols/FacebookRM/messages.cpp
index d6873d60e4..d8fd7e6d58 100644
--- a/protocols/FacebookRM/messages.cpp
+++ b/protocols/FacebookRM/messages.cpp
@@ -114,6 +114,10 @@ void FacebookProto::SendTypingWorker(void *p)
send_typing *typing = static_cast<send_typing*>(p);
+ // Dont send typing notifications to contacts, that are offline
+ if ( DBGetContactSettingWord(typing->hContact,m_szModuleName,"Status", 0) == ID_STATUS_OFFLINE )
+ return;
+
// TODO RM: maybe better send typing optimalization
facy.is_typing_ = (typing->status == PROTOTYPE_SELFTYPING_ON);
SleepEx( 2000, true );
diff --git a/protocols/FacebookRM/process.cpp b/protocols/FacebookRM/process.cpp
index 4136e1b323..eceea978a5 100644
--- a/protocols/FacebookRM/process.cpp
+++ b/protocols/FacebookRM/process.cpp
@@ -329,11 +329,8 @@ void FacebookProto::ProcessUnreadMessages( void* )
std::string::size_type pos3 = messageslist.find( "class=\\\"MessagingMessage ", pos2 );
std::string messagesgroup = messageslist.substr( pos2, pos3 - pos2 );
- DWORD timestamp = NULL;
- std::string strtime = utils::text::source_get_value( &messagesgroup, 2, "data-utime=\\\"", "\\\"" );
- if (!utils::conversion::from_string<DWORD>(timestamp, strtime, std::dec)) {
- timestamp = static_cast<DWORD>(::time(NULL));
- }
+ DWORD timestamp = utils::conversion::to_timestamp(
+ utils::text::source_get_value( &messagesgroup, 2, "data-utime=\\\"", "\\\"" ) );
pos3 = 0;
while ( ( pos3 = messagesgroup.find( "class=\\\"content noh", pos3 ) ) != std::string::npos )
@@ -444,7 +441,7 @@ void FacebookProto::ProcessMessages( void* data )
recv.flags = PREF_UTF;
recv.szMessage = const_cast<char*>(messages[i]->message_text.c_str());
- recv.timestamp = static_cast<DWORD>(messages[i]->time);
+ recv.timestamp = messages[i]->time;
ccs.hContact = hContact;
ccs.szProtoService = PSR_MESSAGE;
@@ -539,6 +536,57 @@ void FacebookProto::ProcessNotifications( void* )
CODE_BLOCK_END
}
+void FacebookProto::ProcessFriendRequests( void* )
+{
+ facy.handle_entry( "friendRequests" );
+
+ // Get notifications
+ http::response resp = facy.flap( FACEBOOK_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, "<div class=\"mRequestItem", "<div class=\"al aps\">");
+
+ std::string::size_type pos = 0;
+ std::string::size_type pos2 = 0;
+ bool last = false;
+
+ while (!last) {
+ std::string req;
+ if ((pos2 = reqs.find("<div class=\"mRequestItem", pos)) != std::string::npos) {
+ req = reqs.substr(pos, pos2 - pos);
+ pos = pos2 + 24;
+ } else {
+ req = reqs.substr(pos);
+ last = true;
+ }
+
+ std::string get = utils::text::source_get_value(&req, 3, "<form", "action=\"", "\">");
+
+ facebook_user *fbu = new facebook_user();
+ fbu->real_name = utils::text::source_get_value(&req, 2, "class=\"actor\">", "</");
+ fbu->user_id = utils::text::source_get_value(&get, 2, "id=", "&");
+
+ if (fbu->user_id.length() && fbu->real_name.length())
+ {
+ HANDLE hContact = this->AddToContactList(fbu, false, fbu->real_name.c_str());
+ DBWriteContactSettingString(hContact, this->m_szModuleName, FACEBOOK_KEY_APPROVE, get.c_str());
+
+ LOG(" Friendship request from: %s (%s)", fbu->real_name.c_str(), fbu->user_id.c_str());
+ } else {
+ LOG(" !!! Wrong friendship request");
+ }
+ }
+
+ facy.handle_success( "friendRequests" );
+}
void FacebookProto::ProcessFeeds( void* data )
{
@@ -644,3 +692,91 @@ void FacebookProto::ProcessFeeds( void* data )
exit:
delete resp;
}
+
+void FacebookProto::SearchAckThread(void *targ)
+{
+ facy.handle_entry( "searchAckThread" );
+
+ char *arg = mir_utf8encodeT((TCHAR*)targ);
+ std::string search = utils::url::encode( arg );
+
+ // Get notifications
+ http::response resp = facy.flap( FACEBOOK_REQUEST_SEARCH, NULL, &search );
+
+ // Process result data
+ facy.validate_response(&resp);
+
+ if (resp.code == HTTP_CODE_OK)
+ {
+ std::string items = utils::text::source_get_value(&resp.data, 3, "<body", "<div class=\"c\">", "</body>");
+
+ std::string::size_type pos = 0;
+ std::string::size_type pos2 = 0;
+ bool last = false;
+
+ while (!last) {
+ std::string item;
+ if ((pos2 = items.find("<div class=\"c\">", pos)) != std::string::npos) {
+ item = items.substr(pos, pos2 - pos);
+ pos = pos2 + 14;
+ } else {
+ item = items.substr(pos);
+ last = true;
+ }
+
+ 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, "<span>", "</span>");
+ std::string surname;
+ std::string nick;
+ std::string common = utils::text::source_get_value(&item, 2, "<span class=\"fcg\">", "</span>");
+
+ if ((pos2 = name.find(" <span class=\"alternate_name\">")) != 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);
+ }
+
+ // 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);
+ }
+
+ }
+
+ ProtoBroadcastAck(m_szModuleName, NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, targ, 0);
+
+ facy.handle_success( "searchAckThread" );
+
+ mir_free(targ);
+ mir_free(arg);
+}
diff --git a/protocols/FacebookRM/proto.cpp b/protocols/FacebookRM/proto.cpp
index 692de07521..14a9dcfedc 100644
--- a/protocols/FacebookRM/proto.cpp
+++ b/protocols/FacebookRM/proto.cpp
@@ -113,10 +113,14 @@ DWORD_PTR FacebookProto::GetCaps( int type, HANDLE hContact )
switch(type)
{
case PFLAGNUM_1: // TODO: Other caps available: PF1_BASICSEARCH, PF1_SEARCHBYEMAIL
+ {
+ DWORD_PTR flags = PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | PF1_ADDED | PF1_BASICSEARCH | PF1_USERIDISEMAIL | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME | PF1_ADDSEARCHRES; // | PF1_VISLIST | PF1_INVISLIST;
+
if ( getByte( FACEBOOK_KEY_SET_MIRANDA_STATUS, 0 ) )
- return PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_MODEMSG;
+ return flags |= PF1_MODEMSG;
else
- return PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_MODEMSGRECV;
+ return flags |= PF1_MODEMSGRECV;
+ }
case PFLAGNUM_2:
return PF2_ONLINE | PF2_INVISIBLE | PF2_ONTHEPHONE | PF2_IDLE; // | PF2_SHORTAWAY;
case PFLAGNUM_3:
@@ -125,7 +129,7 @@ DWORD_PTR FacebookProto::GetCaps( int type, HANDLE hContact )
else
return 0;
case PFLAGNUM_4:
- return PF4_FORCEAUTH | PF4_NOCUSTOMAUTH | PF4_SUPPORTIDLE | PF4_IMSENDUTF | PF4_AVATARS | PF4_SUPPORTTYPING | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE;
+ return PF4_NOCUSTOMAUTH | PF4_FORCEADDED | PF4_IMSENDUTF | PF4_AVATARS | PF4_SUPPORTTYPING | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE;
case PFLAGNUM_5:
return PF2_ONTHEPHONE;
case PFLAG_MAXLENOFMESSAGE:
@@ -223,6 +227,67 @@ void FacebookProto::SetAwayMsgWorker(void *)
facy.set_status( last_status_msg_ );
}
+HANDLE FacebookProto::SearchBasic( const PROTOCHAR* id )
+{
+ if (isOffline())
+ return 0;
+
+ TCHAR* email = mir_tstrdup(id);
+ ForkThread(&FacebookProto::SearchAckThread, this, (void*)email);
+
+ return email;
+}
+
+HANDLE FacebookProto::SearchByEmail( const PROTOCHAR* email )
+{
+ return SearchBasic(email);
+}
+
+HANDLE FacebookProto::SearchByName( const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName )
+{
+ TCHAR arg[200];
+ _sntprintf (arg, SIZEOF(arg), _T("%s %s %s"), nick, firstName, lastName);
+ return SearchBasic(arg);
+}
+
+HANDLE FacebookProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
+{
+ char *id = mir_t2a_cp(psr->id, CP_UTF8);
+ char *name = mir_t2a_cp(psr->firstName, CP_UTF8);
+ char *surname = mir_t2a_cp(psr->lastName, CP_UTF8);
+
+ facebook_user fbu;
+ fbu.user_id = id;
+ fbu.real_name = name;
+ fbu.real_name += " ";
+ fbu.real_name += surname;
+
+ HANDLE hContact = AddToContactList(&fbu, false, fbu.real_name.c_str());
+ if (hContact) {
+ if (flags & PALF_TEMPORARY)
+ {
+ DBWriteContactSettingByte(hContact, "Clist", "Hidden", 1);
+ DBWriteContactSettingByte(hContact, "Clist", "NotOnList", 1);
+ }
+ else if (DBGetContactSettingByte(hContact, "CList", "NotOnList", 0))
+ {
+ DBDeleteContactSetting(hContact, "CList", "Hidden");
+ DBDeleteContactSetting(hContact, "CList", "NotOnList");
+ }
+ }
+
+ mir_free(id);
+ mir_free(name);
+ mir_free(surname);
+
+ return hContact;
+}
+
+int FacebookProto::AuthRequest(HANDLE hContact,const PROTOCHAR *message)
+{
+ return AddFriend((WPARAM)hContact, NULL);
+}
+
//////////////////////////////////////////////////////////////////////////////
// SERVICES
@@ -491,6 +556,23 @@ int FacebookProto::AddFriend(WPARAM wParam,LPARAM lParam)
return 0;
}
+int FacebookProto::ApproveFriend(WPARAM wParam,LPARAM lParam)
+{
+ if (wParam == NULL)
+ { // self contact
+// CallService(MS_UTILS_OPENURL,1,reinterpret_cast<LPARAM>(FACEBOOK_URL_PROFILE));
+ return 0;
+ }
+
+ if (isOffline())
+ return 0;
+
+ HANDLE *hContact = new HANDLE(reinterpret_cast<HANDLE>(wParam));
+ ForkThread( &FacebookProto::ApproveContactToServer, this, ( void* )hContact );
+
+ return 0;
+}
+
void FacebookProto::ToggleStatusMenuItems( BOOL bEnable )
{
CLISTMENUITEM clmi = { 0 };
diff --git a/protocols/FacebookRM/proto.h b/protocols/FacebookRM/proto.h
index db236b8777..bacdc5c109 100644
--- a/protocols/FacebookRM/proto.h
+++ b/protocols/FacebookRM/proto.h
@@ -117,7 +117,8 @@ public:
int __cdecl GetAvatarCaps(WPARAM, LPARAM );
int __cdecl VisitProfile(WPARAM, LPARAM );
int __cdecl RemoveFriend(WPARAM, LPARAM );
- int __cdecl AddFriend(WPARAM, LPARAM );
+ int __cdecl AddFriend(WPARAM, LPARAM );
+ int __cdecl ApproveFriend(WPARAM, LPARAM );
// Events
int __cdecl OnModulesLoaded(WPARAM, LPARAM);
@@ -145,6 +146,8 @@ public:
void __cdecl ProcessUnreadMessages(void*);
void __cdecl ProcessFeeds(void*);
void __cdecl ProcessNotifications(void*);
+ void __cdecl ProcessFriendRequests(void*);
+ void __cdecl SearchAckThread(void*);
// Worker threads
void __cdecl SignOn(void*);
@@ -158,6 +161,7 @@ public:
void __cdecl MessagingWorker(void*);
void __cdecl DeleteContactFromServer(void*);
void __cdecl AddContactToServer(void*);
+ void __cdecl ApproveContactToServer(void*);
// Contacts handling
bool IsMyContact(HANDLE, bool include_chat = false);
@@ -167,7 +171,7 @@ public:
// Chats handling
void AddChat(const char *id, const char *name);
- void UpdateChat(const char *chat_id, const char *id, const char *name, const char *message);
+ void UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp = 0);
bool IsChatContact(const char *chat_id, const char *id);
void AddChatContact(const char *chat_id, const char *id, const char *name);
void RemoveChatContact(const char *chat_id, const char *id);
diff --git a/protocols/FacebookRM/stubs.cpp b/protocols/FacebookRM/stubs.cpp
index 4cf01cd4c8..2bbb2ffb3b 100644
--- a/protocols/FacebookRM/stubs.cpp
+++ b/protocols/FacebookRM/stubs.cpp
@@ -22,15 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common.h"
-HANDLE FacebookProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
-{
- return 0;
-};
-
HANDLE FacebookProto::AddToListByEvent(int flags,int iContact,HANDLE hDbEvent)
{
return 0;
-};
+}
int FacebookProto::Authorize(HANDLE hContact)
{
@@ -47,11 +42,6 @@ int FacebookProto::AuthRecv(HANDLE hContact,PROTORECVEVENT *)
return 0;
}
-int FacebookProto::AuthRequest(HANDLE hContact,const PROTOCHAR *message)
-{
- return 0;
-}
-
HANDLE FacebookProto::ChangeInfo(int type,void *info_data)
{
MessageBoxA(0,"ChangeInfo","",0);
@@ -84,21 +74,6 @@ int FacebookProto::GetInfo( HANDLE hContact, int infoType )
return 1;
}
-HANDLE FacebookProto::SearchBasic( const PROTOCHAR* id )
-{
- return 0;
-}
-
-HANDLE FacebookProto::SearchByEmail( const PROTOCHAR* email )
-{
- return 0;
-}
-
-HANDLE FacebookProto::SearchByName( const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName )
-{
- return 0;
-}
-
HWND FacebookProto::SearchAdvanced(HWND owner)
{
return 0;
diff --git a/protocols/FacebookRM/theme.cpp b/protocols/FacebookRM/theme.cpp
index 7bc62a2317..ddf612e4d6 100644
--- a/protocols/FacebookRM/theme.cpp
+++ b/protocols/FacebookRM/theme.cpp
@@ -37,7 +37,8 @@ static const icons[] =
{ "mind", LPGEN("Mind"), IDI_MIND },
{ "removeFriend", LPGEN("Remove from server"), IDI_REMOVEFRIEND },
{ "addFriend", LPGEN("Request friendship"), IDI_ADDFRIEND },
-
+ { "approveFriend", LPGEN("Approve friendship"), 0, "core_main_8" }, // TODO: add better icon
+
{ "homepage", LPGEN("Visit Profile"), 0, "core_main_2" },
};
@@ -106,7 +107,7 @@ char *GetIconDescription(const char* name)
}
// Contact List menu stuff
-HANDLE g_hMenuItems[4];
+HANDLE g_hMenuItems[5];
// Helper functions
static FacebookProto * GetInstanceByHContact(HANDLE hContact)
@@ -138,7 +139,7 @@ static int PrebuildContactMenu(WPARAM wParam,LPARAM lParam)
return proto ? proto->OnPrebuildContactMenu(wParam,lParam) : 0;
}
-HANDLE hHookPreBuildMenu,sVisitProfile,sAddFriend,sRemoveFriend;
+HANDLE hHookPreBuildMenu, sVisitProfile, sAddFriend, sRemoveFriend, sApproveFriend;
void InitContactMenus()
{
hHookPreBuildMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU,PrebuildContactMenu);
@@ -169,6 +170,14 @@ void InitContactMenus()
sAddFriend = CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::AddFriend>);
g_hMenuItems[3] = reinterpret_cast<HANDLE>(
CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi) );
+
+ mi.position=-2000006000;
+ mi.icolibItem = GetIconHandle("approveFriend");
+ mi.pszName = GetIconDescription("approveFriend");
+ mi.pszService = "FacebookProto/ApproveFriend";
+ sApproveFriend = CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::ApproveFriend>);
+ g_hMenuItems[4] = reinterpret_cast<HANDLE>(
+ CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi) );
}
void UninitContactMenus()
@@ -179,6 +188,7 @@ void UninitContactMenus()
DestroyServiceFunction(sVisitProfile);
DestroyServiceFunction(sRemoveFriend);
DestroyServiceFunction(sAddFriend);
+ DestroyServiceFunction(sApproveFriend);
}
void ShowContactMenus(bool show, bool deleted)
@@ -187,7 +197,7 @@ void ShowContactMenus(bool show, bool deleted)
{
CLISTMENUITEM item = { sizeof(item) };
item.flags = CMIM_FLAGS;
- if(!show || (i == 3 && !deleted) || (i == 2 && deleted)) // 2 = REMOVE CONTACT; 3 = ADD CONTACT
+ if(!show || (i == 3 && !deleted) || (i == 2 && deleted) || (i == 4 && !deleted)) // 2 = REMOVE CONTACT; 3 = ADD CONTACT; 4 = APPROVE CONTACT
item.flags |= CMIF_HIDDEN;
CallService(MS_CLIST_MODIFYMENUITEM,reinterpret_cast<WPARAM>(g_hMenuItems[i]),
diff --git a/protocols/FacebookRM/utils.cpp b/protocols/FacebookRM/utils.cpp
index 5440757450..248bb432bd 100644
--- a/protocols/FacebookRM/utils.cpp
+++ b/protocols/FacebookRM/utils.cpp
@@ -58,6 +58,24 @@ std::string utils::time::mili_timestamp( )
return timestamp;
}
+DWORD utils::time::fix_timestamp( double mili_timestamp )
+{
+ // If it is really mili_timestamp
+ if (mili_timestamp > 100000000000) {
+ return (DWORD) (mili_timestamp / 1000);
+ }
+ return (DWORD) mili_timestamp;
+}
+
+DWORD utils::conversion::to_timestamp( std::string data )
+{
+ DWORD timestamp = NULL;
+ if (!utils::conversion::from_string<DWORD>(timestamp, data, std::dec)) {
+ timestamp = static_cast<DWORD>(::time(NULL));
+ }
+ return timestamp;
+}
+
std::string utils::conversion::to_string( void* data, WORD type )
{
std::stringstream out;
diff --git a/protocols/FacebookRM/utils.h b/protocols/FacebookRM/utils.h
index 868aeb84bc..25a92e4d9c 100644
--- a/protocols/FacebookRM/utils.h
+++ b/protocols/FacebookRM/utils.h
@@ -72,6 +72,7 @@ namespace utils
{
std::string unix_timestamp( );
std::string mili_timestamp( );
+ DWORD fix_timestamp( double );
};
namespace number
@@ -96,7 +97,8 @@ namespace utils
namespace conversion
{
- std::string to_string( void*, WORD type );
+ DWORD to_timestamp( std::string data );
+ std::string to_string( void*, WORD type );
template <class T>
bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {