diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 3 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 37 | ||||
-rw-r--r-- | protocols/FacebookRM/src/requests/profile.h | 14 |
3 files changed, 53 insertions, 1 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index b9411a8e81..61e8a3de75 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -41,7 +41,8 @@ http::response facebook_client::sendRequest(HttpRequest *request) return resp; } - if (!parent->m_locale.empty()) + // Check and append user defined locale if request doesn't have it forced already + if (!parent->m_locale.empty() && strstr(request->szUrl, "&locale=") == NULL) request->Url << CHAR_VALUE("locale", parent->m_locale.c_str()); request->Headers diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 30ca138e91..d92f8c8e5f 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -382,6 +382,43 @@ int FacebookProto::GetInfo(MCONTACT hContact, int) CheckAvatarChange(hContact, fbu.image_url); + // Load additional info from profile page (e.g., birthday) + if (isOffline()) + return 1; + + http::response resp = facy.sendRequest(new ProfileInfoRequest(facy.mbasicWorks, fbu.user_id.c_str())); + + if (resp.code == HTTP_CODE_OK) { + std::string birthday = utils::text::source_get_value(&resp.data, 4, ">Birthday</", "<td", ">", "</td>"); + birthday = utils::text::remove_html(birthday); + + std::string::size_type pos = birthday.find(" "); + std::string::size_type pos2 = birthday.find(","); + if (pos != std::string::npos) { + std::string month = birthday.substr(0, pos); + std::string day = birthday.substr(pos + 1, pos2 != std::string::npos ? pos2 - pos - 1 : std::string::npos); + + setByte(hContact, "BirthDay", atoi(day.c_str())); + + const static char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; + for (int i = 0; i < 12; i++) { + if (!mir_strcmp(months[i], month.c_str())) { + setByte(hContact, "BirthMonth", i + 1); + break; + } + } + + if (pos2 != std::string::npos) { + std::string year = birthday.substr(pos2 + 2, 4); + setWord(hContact, "BirthYear", atoi(year.c_str())); + } + else { + // We have to set ANY year, otherwise UserInfoEx shows completely wrong date + setWord(hContact, "BirthYear", 1800); + } + } + } + return 1; } diff --git a/protocols/FacebookRM/src/requests/profile.h b/protocols/FacebookRM/src/requests/profile.h index a620cc237a..d3845e4e96 100644 --- a/protocols/FacebookRM/src/requests/profile.h +++ b/protocols/FacebookRM/src/requests/profile.h @@ -78,4 +78,18 @@ public: } }; +// request mobile page containing user profile by his id, and in english language (for parsing data) +class ProfileInfoRequest : public HttpRequest +{ +public: + ProfileInfoRequest(bool mobileBasicWorks, const char *userId) : + HttpRequest(REQUEST_GET, FORMAT, "%s/profile.php", mobileBasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE) + { + Url + << CHAR_VALUE("id", userId) + << "v=info" + << "locale=en_US"; + } +}; + #endif //_FACEBOOK_REQUEST_PROFILE_H_ |