From c659a92109a8c2a4d7c0cf142eab84fd636a62dc Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 19 Mar 2015 20:13:44 +0000 Subject: SkypeWeb: added contacts profile getting git-svn-id: http://svn.miranda-ng.org/main/trunk@12435 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/common.h | 1 + protocols/SkypeWeb/src/requests/profiles.h | 27 +++++++++ protocols/SkypeWeb/src/skype_contacts.cpp | 95 ++++++++++++++++++++++++++---- protocols/SkypeWeb/src/skype_proto.h | 1 + 4 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 protocols/SkypeWeb/src/requests/profiles.h (limited to 'protocols/SkypeWeb/src') diff --git a/protocols/SkypeWeb/src/common.h b/protocols/SkypeWeb/src/common.h index e8184c9e50..41012c2a6d 100644 --- a/protocols/SkypeWeb/src/common.h +++ b/protocols/SkypeWeb/src/common.h @@ -46,6 +46,7 @@ struct CSkypeProto; #include "requests\login.h" #include "requests\logout.h" #include "requests\contacts.h" +#include "requests\profiles.h" #include "request_queue.h" #include "skype_proto.h" diff --git a/protocols/SkypeWeb/src/requests/profiles.h b/protocols/SkypeWeb/src/requests/profiles.h new file mode 100644 index 0000000000..564ee92b7f --- /dev/null +++ b/protocols/SkypeWeb/src/requests/profiles.h @@ -0,0 +1,27 @@ +#ifndef _SKYPE_REQUEST_PROFILES_H_ +#define _SKYPE_REQUEST_PROFILES_H_ + +class GetProfilesRequest : public HttpRequest +{ +public: + GetProfilesRequest(const char *token, const LIST &skypenames) : + HttpRequest(REQUEST_POST, "api.skype.com//users/self/contacts/profiles") + { + flags |= NLHRF_SSL; + + CMStringA data; + for (size_t i = 0; i < skypenames.getCount(); i++) + { + data.AppendFormat("contacts[]=%s&", skypenames[i]); + } + data.Delete(data.GetLength() - 1); + + SetData(data, data.GetLength()); + + AddHeader("X-Skypetoken", token); + AddHeader("Accept", "application/json"); + AddHeader("Content-Type", "application/x-www-form-urlencoded"); + } +}; + +#endif //_SKYPE_REQUEST_PROFILES_H_ diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index cc50f7cef9..5aebc68c75 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -83,8 +83,59 @@ MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary) return hContact; } -//[{"skypename":"echo123", "fullname" : "Echo \/ Sound Test Service", "authorized" : true, "blocked" : false, "display_name" : null, "pstn_number" : null, \ - "phone1" : null, "phone1_label" : null, "phone2" : null, "phone2_label" : null, "phone3" : null, "phone3_label" : null}] +//[{ "username":"echo123", "firstname" : "Echo \/ Sound Test Service", "lastname" : null, "avatarUrl" : null, "mood" : null, "richMood" : null, "displayname" : null, "country" : null, "city" : null },...] +void CSkypeProto::LoadProfiles(const NETLIBHTTPREQUEST *response) +{ + if (response == NULL) + return; + + JSONROOT root(response->pData); + if (root == NULL) + return; + + JSONNODE *items = json_as_array(root), *item, *node; + for (size_t i = 0; i < json_size(items); i++) + { + item = json_at(items, i); + if (item == NULL) + break; + + node = json_get(item, "username"); + ptrA skypename(mir_t2a(ptrT(json_as_string(node)))); + MCONTACT hContact = AddContact(skypename); + if (hContact) + { + node = json_get(item, "avatarUrl"); + CMStringA avatarUrl = mir_t2a(ptrT(json_as_string(node))); + if (avatarUrl && avatarUrl != "null") + ; // TODO: load avatar + + node = json_get(item, "mood"); + CMString mood = ptrT(json_as_string(node)); + if (!mood.IsEmpty() && mood != "null") + db_set_ts(hContact, "CList", "StatusMsg", mood); + else + db_unset(hContact, "CList", "StatusMsg"); + + node = json_get(item, "richMood"); + ptrT richMood(json_as_string(node)); + + node = json_get(item, "country"); + ptrA country(mir_t2a(ptrT(json_as_string(node)))); + + node = json_get(item, "city"); + CMString city = ptrT(json_as_string(node)); + if (!city.IsEmpty() && city != "null") + setTString(hContact, "City", city); + else + delSetting(hContact, "City"); + } + + } + json_delete(items); +} + +//[{"skypename":"echo123", "fullname" : "Echo \/ Sound Test Service", "authorized" : true, "blocked" : false, "display_name" : null, "pstn_number" : null, "phone1" : null, "phone1_label" : null, "phone2" : null, "phone2_label" : null, "phone3" : null, "phone3_label" : null},...] void CSkypeProto::LoadContacts(const NETLIBHTTPREQUEST *response) { if (response == NULL) @@ -94,6 +145,8 @@ void CSkypeProto::LoadContacts(const NETLIBHTTPREQUEST *response) if (root == NULL) return; + LIST skypenames(1); + JSONNODE *items = json_as_array(root), *item, *node; for (size_t i = 0; i < json_size(items); i++) { @@ -103,7 +156,7 @@ void CSkypeProto::LoadContacts(const NETLIBHTTPREQUEST *response) node = json_get(item, "skypename"); ptrA skypename(mir_t2a(ptrT(json_as_string(node)))); - MCONTACT hContact = AddContact(skypename, _T("")); + MCONTACT hContact = AddContact(skypename); if (hContact) { node = json_get(item, "fullname"); @@ -133,27 +186,45 @@ void CSkypeProto::LoadContacts(const NETLIBHTTPREQUEST *response) if (!nick.IsEmpty() && nick != "null") setTString(hContact, "Nick", nick); else - { - node = json_get(item, "pstn_number"); - CMString pstn = ptrT(json_as_string(node)); - if (!nick.IsEmpty() && pstn != "null") - setTString(hContact, "Nick", pstn); - else - delSetting(hContact, "Nick"); - } - + delSetting(hContact, "Nick"); + + node = json_get(item, "pstn_number"); + CMString ptsnNumber = ptrT(json_as_string(node)); + if (!ptsnNumber.IsEmpty() && ptsnNumber != "null") + setString(hContact, "PtsnNumber", ptrA(mir_u2a(ptsnNumber))); + else + delSetting(hContact, "PtsnNumber"); + node = json_get(item, "authorized"); if (json_as_bool(node)) { delSetting(hContact, "Auth"); delSetting(hContact, "Grant"); } + else + { + setByte(hContact, "Grant", 1); + } node = json_get(item, "blocked"); setByte(hContact, "IsBlocked", json_as_bool(node)); + + skypenames.insert(mir_strdup(skypename)); } } json_delete(items); + + if (skypenames.getCount() > 0) + { + ptrA token(getStringA("TokenSecret")); + PushRequest(new GetProfilesRequest(token, skypenames), &CSkypeProto::LoadProfiles); + + for (size_t i = 0; i < skypenames.getCount(); i++) + { + mir_free(skypenames[i]); + } + skypenames.destroy(); + } } INT_PTR CSkypeProto::OnRequestAuth(WPARAM hContact, LPARAM lParam) diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 286e562ab7..a94fa3ae6a 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -129,6 +129,7 @@ private: MCONTACT GetContactFromAuthEvent(MEVENT hEvent); + void LoadProfiles(const NETLIBHTTPREQUEST *response); void LoadContacts(const NETLIBHTTPREQUEST *response); INT_PTR __cdecl OnRequestAuth(WPARAM hContact, LPARAM lParam); -- cgit v1.2.3