diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-03-19 20:13:44 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-03-19 20:13:44 +0000 |
commit | c659a92109a8c2a4d7c0cf142eab84fd636a62dc (patch) | |
tree | dc5f24c4331414582d5ebd9b7b12b9aafe1bcfc5 | |
parent | 3b2d89185012c78f5e2db43a4c28cd774bea618d (diff) |
SkypeWeb: added contacts profile getting
git-svn-id: http://svn.miranda-ng.org/main/trunk@12435 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/SkypeWeb/SkypeWeb_12.vcxproj | 1 | ||||
-rw-r--r-- | protocols/SkypeWeb/SkypeWeb_12.vcxproj.filters | 3 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/common.h | 1 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/profiles.h | 27 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_contacts.cpp | 95 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 1 |
6 files changed, 116 insertions, 12 deletions
diff --git a/protocols/SkypeWeb/SkypeWeb_12.vcxproj b/protocols/SkypeWeb/SkypeWeb_12.vcxproj index 697f430030..a67cf6a78a 100644 --- a/protocols/SkypeWeb/SkypeWeb_12.vcxproj +++ b/protocols/SkypeWeb/SkypeWeb_12.vcxproj @@ -206,6 +206,7 @@ <ClInclude Include="src\requests\contacts.h" />
<ClInclude Include="src\requests\login.h" />
<ClInclude Include="src\requests\logout.h" />
+ <ClInclude Include="src\requests\profiles.h" />
<ClInclude Include="src\resource.h" />
<ClInclude Include="src\skype_icons.h" />
<ClInclude Include="src\skype_menus.h" />
diff --git a/protocols/SkypeWeb/SkypeWeb_12.vcxproj.filters b/protocols/SkypeWeb/SkypeWeb_12.vcxproj.filters index e4467299e4..3d9cbab39c 100644 --- a/protocols/SkypeWeb/SkypeWeb_12.vcxproj.filters +++ b/protocols/SkypeWeb/SkypeWeb_12.vcxproj.filters @@ -51,6 +51,9 @@ <ClInclude Include="src\requests\contacts.h">
<Filter>Header Files\requests</Filter>
</ClInclude>
+ <ClInclude Include="src\requests\profiles.h">
+ <Filter>Header Files\requests</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\stdafx.cpp">
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<char> &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<char> 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);
|