diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-06-07 13:36:36 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-06-07 13:36:36 +0000 |
commit | 45542da458084e66d534b9d9f8f3ce6570888e95 (patch) | |
tree | 2cdcfa03906cc85fade40d26f8eaf6ef32d9cacc /protocols/SkypeWeb/src | |
parent | 15bd23ef81adbc57885854d8220a0f777a23fb4a (diff) |
SkypeWeb: Contact list loading rewritted to new api.
git-svn-id: http://svn.miranda-ng.org/main/trunk@14051 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb/src')
-rw-r--r-- | protocols/SkypeWeb/src/requests/contacts.h | 12 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_contacts.cpp | 102 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_login.cpp | 7 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_mslogin.cpp | 2 |
4 files changed, 87 insertions, 36 deletions
diff --git a/protocols/SkypeWeb/src/requests/contacts.h b/protocols/SkypeWeb/src/requests/contacts.h index 1d01ae9cc5..613b9962ab 100644 --- a/protocols/SkypeWeb/src/requests/contacts.h +++ b/protocols/SkypeWeb/src/requests/contacts.h @@ -30,6 +30,18 @@ public: << CHAR_VALUE("X-Skypetoken", token)
<< CHAR_VALUE("Accept", "application/json");
}
+ GetContactListRequest(const char *token, const char *skypename, const char *filter) :
+ HttpRequest(REQUEST_GET, FORMAT, "contacts.skype.com/contacts/v1/users/%s/contacts", CMStringA(skypename).MakeLower().GetBuffer())
+ {
+ if (filter != NULL)
+ {
+ Url
+ << CHAR_VALUE ("filter", filter); //?filter=contacts[?(@.type="skype" or @.type="msn")]
+ }
+
+ Headers
+ << CHAR_VALUE("X-SkypeToken", token);
+ }
};
class GetContactsInfoRequest : public HttpRequest
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index cd8c80c358..1afb872205 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -185,19 +185,16 @@ void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response) MCONTACT hContact = AddContact(skypename.c_str());
if (hContact)
{
- UpdateProfileFirstName(item, hContact);
- UpdateProfileLastName(item, hContact);
- UpdateProfileDisplayName(item, hContact);
UpdateProfileCountry(item, hContact);
UpdateProfileCity(item, hContact);
UpdateProfileStatusMessage(item, hContact);
- UpdateProfileAvatar(item, hContact);
}
}
}
//[{"skypename":"echo123", "authorized" : true, "blocked" : false, ...},...]
// other properties is exists but empty
+
void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
@@ -208,42 +205,85 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) return;
LIST<char> skypenames(1);
-
- const JSONNode &items = root.as_array();
+ bool loadAll = getBool("LoadAllContacts", false);
+ const JSONNode &items = root["contacts"].as_array();
for (size_t i = 0; i < items.size(); i++)
{
const JSONNode &item = items.at(i);
if (!item)
break;
- std::string skypename = item["skypename"].as_string();
- MCONTACT hContact = AddContact(skypename.c_str());
- if (hContact)
+ const JSONNode &name = item["name"];
+ const JSONNode &phones = item["phones"];
+
+ std::string skypename = item["id"].as_string();
+ CMString display_name = item["display_name"].as_mstring();
+ CMString first_name = name["first"].as_mstring();
+ CMString last_name = name["surname"].as_mstring();
+ CMString avatar_url = item["avatar_url"].as_mstring();
+ std::string type = item["type"].as_string();
+
+ if (type == "skype" || loadAll)
{
- if (item["authorized"].as_bool())
+ MCONTACT hContact = AddContact(skypename.c_str());
+ if (hContact)
{
- delSetting(hContact, "Auth");
- delSetting(hContact, "Grant");
- }
- else setByte(hContact, "Grant", 1);
+ if (item["authorized"].as_bool())
+ {
+ delSetting(hContact, "Auth");
+ delSetting(hContact, "Grant");
+ }
+ else setByte(hContact, "Grant", 1);
- if (item["blocked"].as_bool())
- {
- db_set_dw(hContact, "Ignore", "Mask1", 127);
- db_set_b(hContact, "CList", "Hidden", 1);
- setByte(hContact, "IsBlocked", 1);
- }
- else
- {
- if (db_get_b(hContact, m_szModuleName, "IsBlocked", 0))
+ if (item["blocked"].as_bool())
{
- db_set_dw(hContact, "Ignore", "Mask1", 0);
- db_set_b(hContact, "CList", "Hidden", 0);
- setByte(hContact, "IsBlocked", 0);
+ db_set_dw(hContact, "Ignore", "Mask1", 127);
+ db_set_b(hContact, "CList", "Hidden", 1);
+ setByte(hContact, "IsBlocked", 1);
}
- }
+ else
+ {
+ if (db_get_b(hContact, m_szModuleName, "IsBlocked", 0))
+ {
+ db_set_dw(hContact, "Ignore", "Mask1", 0);
+ db_set_b(hContact, "CList", "Hidden", 0);
+ setByte(hContact, "IsBlocked", 0);
+ }
+ }
+
+ setString(hContact, "Type", type.c_str());
+
+ if (display_name)
+ setTString(hContact, "Nick", display_name);
+ if (first_name)
+ setTString(hContact, "FirstName", first_name);
+ if (last_name)
+ setTString(hContact, "LastName", last_name);
+
+ SetAvatarUrl(hContact, avatar_url);
+ ReloadAvatarInfo(hContact);
- skypenames.insert(mir_strdup(skypename.c_str()));
+ for (size_t j = 0; j < phones.size(); j++)
+ {
+ const JSONNode &phone = phones.at(j);
+ if (!phone)
+ break;
+
+ CMString number = phone["number"].as_mstring();
+
+ switch (phone["type"].as_int())
+ {
+ case 0:
+ setTString(hContact, "Phone", number);
+ break;
+ case 2:
+ setTString(hContact, "Cellular", number);
+ break;
+ }
+ }
+
+ if (type == "skype" || type == "msn") skypenames.insert(mir_strdup(skypename.c_str()));
+ }
}
}
@@ -279,9 +319,8 @@ INT_PTR CSkypeProto::OnRequestAuth(WPARAM hContact, LPARAM) if (hContact == INVALID_CONTACT_ID)
return 1;
- ptrA token(getStringA("TokenSecret"));
ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
- PushRequest(new AddContactRequest(token, skypename));
+ PushRequest(new AddContactRequest(m_szTokenSecret, skypename));
return 0;
}
@@ -290,9 +329,8 @@ INT_PTR CSkypeProto::OnGrantAuth(WPARAM hContact, LPARAM) if (hContact == INVALID_CONTACT_ID)
return 1;
- ptrA token(getStringA("TokenSecret"));
ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
- PushRequest(new AuthAcceptRequest(token, skypename));
+ PushRequest(new AuthAcceptRequest(m_szTokenSecret, skypename));
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index c9dabd80d1..063360f894 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -26,7 +26,7 @@ void CSkypeProto::Login() requestQueue->Start();
int tokenExpires(getDword("TokenExpiresIn", 0));
ptrA login(getStringA(SKYPE_SETTINGS_ID));
- HistorySynced = false;
+ HistorySynced = isTerminated = false;
if ((tokenExpires - 1800) > time(NULL))
OnLoginSuccess();
else
@@ -103,6 +103,7 @@ void CSkypeProto::OnLoginOAuth(const NETLIBHTTPREQUEST *response) }
void CSkypeProto::OnLoginSuccess()
{
+ isTerminated = false;
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_SUCCESS, NULL, 0);
m_szSelfSkypeName = getStringA(SKYPE_SETTINGS_ID);
m_szTokenSecret = getStringA("TokenSecret");
@@ -214,7 +215,7 @@ void CSkypeProto::SendPresence(bool isLogin) }
if (isLogin)
- PushRequest(new SendCapabilitiesRequest(m_szRegToken, m_szEndpointId, epname, m_szServer), &CSkypeProto::OnCapabilitiesSended);
+ SendRequest(new SendCapabilitiesRequest(m_szRegToken, m_szEndpointId, epname, m_szServer), &CSkypeProto::OnCapabilitiesSended);
else
PushRequest(new SendCapabilitiesRequest(m_szRegToken, m_szEndpointId, epname, m_szServer));
}
@@ -237,7 +238,7 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response) m_hPollingThread = ForkThreadEx(&CSkypeProto::PollingThread, 0, NULL);
PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl"))), &CSkypeProto::OnReceiveAvatar, NULL);
- PushRequest(new GetContactListRequest(m_szTokenSecret), &CSkypeProto::LoadContactList);
+ PushRequest(new GetContactListRequest(m_szTokenSecret, m_szSelfSkypeName, NULL), &CSkypeProto::LoadContactList);
SendRequest(new LoadChatsRequest(m_szRegToken, m_szServer), &CSkypeProto::OnLoadChats);
if (getBool("AutoSync", true))
diff --git a/protocols/SkypeWeb/src/skype_mslogin.cpp b/protocols/SkypeWeb/src/skype_mslogin.cpp index 637876f1e9..b6134d231b 100644 --- a/protocols/SkypeWeb/src/skype_mslogin.cpp +++ b/protocols/SkypeWeb/src/skype_mslogin.cpp @@ -127,7 +127,7 @@ void CSkypeProto::OnMSLoginThird(const NETLIBHTTPREQUEST *response) std::smatch match;
std::string content = response->pData;
- regex = "<input type=\"hidden\" name=\"t\" value=\"(.+?)\">";
+ regex = "<input type=\"hidden\" name=\"t\" value=\"(.+?)\"/>";
if (!std::regex_search(content, match, regex))
{
|