diff options
author | George Hazan <george.hazan@gmail.com> | 2013-10-20 19:46:04 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-10-20 19:46:04 +0000 |
commit | e246ae2c7c1089664be37d80ef26414ae7b20875 (patch) | |
tree | bd21d92454551e020c565b85dba019695c2e4b49 /protocols/VKontakte | |
parent | bf5c3829141ee76e65ff68d622e9a526a3082e24 (diff) |
fix for retrieving user info
git-svn-id: http://svn.miranda-ng.org/main/trunk@6565 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 4639e087b7..d4743493dc 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -189,21 +189,6 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) m_myUserId = json_as_int(it);
setDword("ID", m_myUserId);
}
- else if ( !_stricmp(id, "user_name"))
- setTString("Nick", ptrT( json_as_string(it)));
- else if ( !_stricmp(id, "user_sex"))
- setByte("Gender", json_as_int(it) == 2 ? 'M' : 'F');
- else if ( !_stricmp(id, "user_bdate")) {
- ptrT date( json_as_string(it));
- int d, m, y;
- if ( _stscanf(date, _T("%d.%d.%d"), &d, &m, &y) == 3) {
- setByte("BirthDay", d);
- setByte("BirthMonth", m);
- setWord("BirthYear", y);
- }
- }
- else if ( !_stricmp(id, "user_photo"))
- setTString("Photo", ptrT( json_as_string(it)));
}
RetrieveUserInfo(m_myUserId);
@@ -220,7 +205,7 @@ void CVkProto::RetrieveUserInfo(LONG userID) _itoa(userID, szUserId, 10);
HttpParam params[] = {
- { "fields", "uid,first_name,last_name,photo,sex,bdate,city,relation" },
+ { "fields", "uid,first_name,last_name,photo_medium,sex,bdate,city,relation" },
{ "uids", szUserId },
{ "access_token", m_szAccessToken }
};
@@ -238,32 +223,49 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (pResponse == NULL)
return;
- HANDLE hContact;
- for (size_t i = 0; i < json_size(pResponse); i++) {
- JSONNODE *it = json_at(pResponse, i);
- LPCSTR id = json_name(it);
- if ( !_stricmp(id, "user_id")) {
- LONG userid = json_as_int(it);
- if (userid == m_myUserId)
- hContact = NULL;
- else if ((hContact = FindUser(userid, false)) == NULL)
- return;
+ for (size_t i=0; ; i++) {
+ JSONNODE *pRecord = json_at(pResponse, i);
+ if (pRecord == NULL) break;
+
+ LONG userid = json_as_int( json_get(pRecord, "uid"));
+ if (userid == 0)
+ return;
+
+ HANDLE hContact;
+ if (userid == m_myUserId)
+ hContact = NULL;
+ else if ((hContact = FindUser(userid, false)) == NULL)
+ return;
+
+ CMString tszNick;
+ ptrT szValue( json_as_string( json_get(pRecord, "first_name")));
+ if (szValue) {
+ setTString(hContact, "FirstName", szValue);
+ tszNick.Append(szValue);
+ tszNick.AppendChar(' ');
+ }
+
+ if (szValue = json_as_string( json_get(pRecord, "last_name"))) {
+ setTString(hContact, "LastName", szValue);
+ tszNick.Append(szValue);
}
- else if ( !_stricmp(id, "user_name"))
- setTString(hContact, "Nick", ptrT( json_as_string(it)));
- else if ( !_stricmp(id, "user_sex"))
- setByte(hContact, "Gender", json_as_int(it) == 2 ? 'M' : 'F');
- else if ( !_stricmp(id, "user_bdate")) {
- ptrT date( json_as_string(it));
+
+ if ( !tszNick.IsEmpty())
+ setTString(hContact, "Nick", tszNick);
+
+ setByte(hContact, "Gender", json_as_int( json_get(pRecord, "sex")) == 2 ? 'M' : 'F');
+
+ if (szValue = json_as_string( json_get(pRecord, "bdate"))) {
int d, m, y;
- if ( _stscanf(date, _T("%d.%d.%d"), &d, &m, &y) == 3) {
+ if ( _stscanf(szValue, _T("%d.%d.%d"), &d, &m, &y) == 3) {
setByte(hContact, "BirthDay", d);
setByte(hContact, "BirthMonth", m);
setWord(hContact, "BirthYear", y);
}
}
- else if ( !_stricmp(id, "user_photo"))
- setTString(hContact, "Photo", ptrT( json_as_string(it)));
+
+ if (szValue = json_as_string( json_get(pRecord, "photo_medium")))
+ setTString(hContact, "AvatarUrl", szValue);
}
}
@@ -274,7 +276,7 @@ void CVkProto::RetrieveFriends() debugLogA("CVkProto::RetrieveFriends");
HttpParam params[] = {
- { "fields", "uid,first_name,last_name,photo,contacts" },
+ { "fields", "uid,first_name,last_name,photo_medium,contacts" },
{ "count", "1000" },
{ "access_token", m_szAccessToken }
};
@@ -307,8 +309,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq tszNick.AppendChar(' ');
}
- szValue = json_as_string( json_get(pInfo, "last_name"));
- if (szValue) {
+ if (szValue = json_as_string( json_get(pInfo, "last_name"))) {
setTString(hContact, "LastName", szValue);
tszNick.Append(szValue);
}
@@ -316,8 +317,8 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq if ( !tszNick.IsEmpty())
setTString(hContact, "Nick", tszNick);
- szValue = json_as_string( json_get(pInfo, "photo"));
- if (szValue) setTString(hContact, "AvatarUrl", szValue);
+ if (szValue = json_as_string( json_get(pInfo, "photo_medium")))
+ setTString(hContact, "AvatarUrl", szValue);
setWord(hContact, "Status", (json_as_int( json_get(pInfo, "online")) == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE);
|