summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb/src/skype_contacts.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-03-18 20:28:01 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-03-18 20:28:01 +0000
commit3364fd6b8bdc21692805302a4333e49b44590b2c (patch)
tree578dd1a7a5db05311add225a78c65cc2a7b03f6d /protocols/SkypeWeb/src/skype_contacts.cpp
parentcd4a3aab6a6406bcaca07734848e57477db4485d (diff)
SkypeWeb:
- contact list loading - refactoring git-svn-id: http://svn.miranda-ng.org/main/trunk@12431 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb/src/skype_contacts.cpp')
-rw-r--r--protocols/SkypeWeb/src/skype_contacts.cpp83
1 files changed, 76 insertions, 7 deletions
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp
index c8aea263e5..cc50f7cef9 100644
--- a/protocols/SkypeWeb/src/skype_contacts.cpp
+++ b/protocols/SkypeWeb/src/skype_contacts.cpp
@@ -41,13 +41,13 @@ MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent)
return DbGetAuthEventContact(&dbei);
}
-MCONTACT CSkypeProto::GetContact(const char *login)
+MCONTACT CSkypeProto::GetContact(const char *skypename)
{
MCONTACT hContact = NULL;
for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
- ptrA contactLogin(getStringA(hContact, SKYPE_SETTINGS_ID));
- if (mir_strcmpi(login, contactLogin) == 0)
+ ptrA cSkypename(getStringA(hContact, SKYPE_SETTINGS_ID));
+ if (mir_strcmpi(skypename, cSkypename) == 0)
{
break;
}
@@ -55,15 +55,15 @@ MCONTACT CSkypeProto::GetContact(const char *login)
return hContact;
}
-MCONTACT CSkypeProto::AddContact(const char *login, bool isTemporary)
+MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary)
{
- MCONTACT hContact = GetContact(login);
+ MCONTACT hContact = GetContact(skypename);
if (!hContact)
{
hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)m_szModuleName);
- setString(hContact, SKYPE_SETTINGS_ID, login);
+ setString(hContact, SKYPE_SETTINGS_ID, skypename);
DBVARIANT dbv;
if (!getTString(SKYPE_SETTINGS_GROUP, &dbv))
@@ -83,8 +83,77 @@ MCONTACT CSkypeProto::AddContact(const char *login, bool isTemporary)
return hContact;
}
-void CSkypeProto::LoadFriendList(void*)
+//[{"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)
+ 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, "skypename");
+ ptrA skypename(mir_t2a(ptrT(json_as_string(node))));
+ MCONTACT hContact = AddContact(skypename, _T(""));
+ if (hContact)
+ {
+ node = json_get(item, "fullname");
+ CMString realname = ptrT(json_as_string(node));
+ if (!realname.IsEmpty() && realname != "null")
+ {
+ size_t pos = realname.Find(' ', 1);
+ if (mir_strcmpi(skypename, "echo123") != 0 && pos != -1)
+ {
+ setTString(hContact, "FirstName", realname.Mid(0, pos));
+ setTString(hContact, "LastName", realname.Mid(pos + 1));
+ }
+ else
+ {
+ setTString(hContact, "FirstName", realname);
+ delSetting(hContact, "LastName");
+ }
+ }
+ else
+ {
+ delSetting(hContact, "FirstName");
+ delSetting(hContact, "LastName");
+ }
+
+ node = json_get(item, "display_name");
+ CMString nick = ptrT(json_as_string(node));
+ 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");
+ }
+
+ node = json_get(item, "authorized");
+ if (json_as_bool(node))
+ {
+ delSetting(hContact, "Auth");
+ delSetting(hContact, "Grant");
+ }
+
+ node = json_get(item, "blocked");
+ setByte(hContact, "IsBlocked", json_as_bool(node));
+ }
+ }
+ json_delete(items);
}
INT_PTR CSkypeProto::OnRequestAuth(WPARAM hContact, LPARAM lParam)