From b8a7168685627ff4ea79dcaf3d917f6b40a23f3b Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Wed, 10 Sep 2014 13:15:54 +0000 Subject: =?UTF-8?q?VKontakte:=20fix=20for=20=E2=80=98to=20many=20connectio?= =?UTF-8?q?ns=E2=80=99=20on=20FindUser=20add=20read=20status=20every=2060?= =?UTF-8?q?=20sec=20add=20StatusMsg=20and=20About=20profile=20fields=20som?= =?UTF-8?q?e=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.miranda-ng.org/main/trunk@10422 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/misc.cpp | 1 - protocols/VKontakte/src/vk_captcha.cpp | 2 -- protocols/VKontakte/src/vk_proto.h | 1 + protocols/VKontakte/src/vk_thread.cpp | 60 ++++++++++++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 6 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index a2fae6f2d1..9ce00e1d04 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -51,7 +51,6 @@ MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate) CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hNewContact, (LPARAM)m_szModuleName); setDword(hNewContact, "ID", dwUserid); db_set_ts(hNewContact, "CList", "Group", m_defaultGroup); - RetrieveUserInfo(dwUserid); return hNewContact; } diff --git a/protocols/VKontakte/src/vk_captcha.cpp b/protocols/VKontakte/src/vk_captcha.cpp index 1637ba608d..89b77168e7 100644 --- a/protocols/VKontakte/src/vk_captcha.cpp +++ b/protocols/VKontakte/src/vk_captcha.cpp @@ -152,8 +152,6 @@ bool CVkProto::ApplyCaptcha(AsyncHttpRequest *pReq, JSONNODE *pErrorNode) if (!RunCaptchaForm(szUrl, userReply)) return false; -// pReq->m_szUrl = pReq->szUrl; -// pReq->m_szUrl.AppendFormat("&captcha_sid=%s&captcha_key=%s", szSid, userReply.GetString()); pReq << CHAR_PARAM("captcha_sid", szSid) << CHAR_PARAM("captcha_key", userReply.GetString()); pReq->bNeedsRestart = true; return true; diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 60350ce5ab..38509f42d6 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -200,6 +200,7 @@ struct CVkProto : public PROTO void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void RetrieveUserInfo(LONG userId); + void RetrieveUsersInfo(int flag = 0); void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void RetrieveFriends(); diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 033edb4265..6766ec5ab6 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -42,8 +42,10 @@ void CVkProto::ConnectionFailed(int iReason) static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) { - for (int i=0; i < vk_Instances.getCount(); i++) + for (int i = 0; i < vk_Instances.getCount(); i++){ vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iStatus); + vk_Instances[i]->RetrieveUsersInfo(1); + } } static void CALLBACK VKSetTimer(void *pObject) @@ -228,11 +230,33 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) ///////////////////////////////////////////////////////////////////////////////////////// +static char fieldsName[] = "id, first_name, last_name, photo_100, sex, country, timezone, contacts, online, status, about"; + void CVkProto::RetrieveUserInfo(LONG userID) { Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnReceiveUserInfo) << INT_PARAM("user_ids", userID) - << CHAR_PARAM("fields", "id, first_name, last_name, photo_100, sex, country, timezone, contacts, online") + << CHAR_PARAM("fields", fieldsName) + << CHAR_PARAM("name_case", "nom") + << VER_API); +} + +void CVkProto::RetrieveUsersInfo(int flag) +{ + CMStringA userIDs; + for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)){ + LONG userID = getDword(hContact, "ID", -1); + if (userID == -1) + continue; + if (!userIDs.IsEmpty()) + userIDs.AppendChar(','); + userIDs.AppendFormat("%i", userID); + + } + + Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/users.get.json", true, &CVkProto::OnReceiveUserInfo) + << CHAR_PARAM("user_ids", userIDs) + << CHAR_PARAM("fields", flag?"online,status":fieldsName) << CHAR_PARAM("name_case", "nom") << VER_API); } @@ -264,6 +288,7 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe return; CMString tszNick; + int iValue; ptrT szValue( json_as_string( json_get(pRecord, "first_name"))); if (szValue) { setTString(hContact, "FirstName", szValue); @@ -294,6 +319,26 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe SetAvatarUrl(hContact, szValue); setWord(hContact, "Status", (json_as_int(json_get(pRecord, "online")) == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE); + + if ((iValue = json_as_int(json_get(pRecord, "timezone"))) != 0) + setByte(hContact, "Timezone", iValue * -2); + + szValue = json_as_string(json_get(pRecord, "mobile_phone")); + if (szValue && *szValue) + setTString(hContact, "Cellular", szValue); + szValue = json_as_string(json_get(pRecord, "home_phone")); + if (szValue && *szValue) + setTString(hContact, "Phone", szValue); + + szValue = json_as_string(json_get(pRecord, "status")); + if (szValue && *szValue) + db_set_ts(hContact, "CList", "StatusMsg", szValue); + + szValue = json_as_string(json_get(pRecord, "about")); + if (szValue && *szValue) + setTString(hContact, "About", szValue); + + } } @@ -304,7 +349,7 @@ void CVkProto::RetrieveFriends() debugLogA("CVkProto::RetrieveFriends"); Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.get.json", true, &CVkProto::OnReceiveFriends) << INT_PARAM("count", 1000) - << CHAR_PARAM("fields", "id, first_name, last_name, photo_100, sex, country, timezone, contacts, online") + << CHAR_PARAM("fields", fieldsName) <