From f2c1244ae5e68bca70c4d0ff87e7752981b6d350 Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Thu, 8 Oct 2015 18:40:38 +0000 Subject: VKontakte: fix(?) user status processing (yes, again) git-svn-id: http://svn.miranda-ng.org/main/trunk@15518 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk_thread.cpp | 67 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 9976529a81..d0266a3930 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -380,7 +380,7 @@ void CVkProto::RetrieveUserInfo(LONG userID) if (userID == VK_FEED_USER || !IsOnline()) return; - CMString code(FORMAT, _T("var userIDs=\"%i\";var res=API.users.get({\"user_ids\":userIDs,\"fields\":\"%s\",\"name_case\":\"nom\"});return{\"freeoffline\":0,\"usercount\":res.length,\"users\":res};"), + CMString code(FORMAT, _T("var userIDs=\"%i\";var res=API.users.get({\"user_ids\":userIDs,\"fields\":\"%s\",\"name_case\":\"nom\"});return{\"freeoffline\":0,\"users\":res};"), userID, CMString(fieldsName)); Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.json", true, &CVkProto::OnReceiveUserInfo) << TCHAR_PARAM("code", code) @@ -409,12 +409,15 @@ void CVkProto::RetrieveUsersInfo(bool flag) codeformat += _T("API.account.setOnline();"); if (flag && !m_bLoadFullCList) - codeformat += CMString("var US=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});" - "var res=[];var index=US.length;var _count=index;while(index>0){index=index-1;if(US[index].online!=0){res.unshift(US[index]);};};" - "return{\"freeoffline\":1,\"usercount\":_count,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); + codeformat += CMString("var US=[];var res=[];var t=3;while(t>0){" + "US=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});" + "var index=US.length;var _count=index;" + "while(index>0){index=index-1;if(US[index].online!=0){res.push(US[index]);};};" + "t=t-1;if(res.length>0)t=0;};" + "return{\"freeoffline\":1,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); else - codeformat += CMString("var res=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});var _count=res.length;" - "return{\"freeoffline\":0,\"usercount\":_count,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); + codeformat += CMString("var res=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});" + "return{\"freeoffline\":0,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); code.AppendFormat(codeformat, userIDs, CMString(flag ? "online,status" : fieldsName)); Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.json", true, &CVkProto::OnReceiveUserInfo) @@ -439,40 +442,36 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe return; MCONTACT hContact; + LIST arContacts(10, PtrKeySortT); + + for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + if (!isChatRoom(hContact)) + arContacts.insert((HANDLE)hContact); - debugLogA("CVkProto::OnReceiveUserInfo usercount = %d", jnResponse["usercount"].as_int()); - if (jnResponse["usercount"].as_int() > 0) { - LIST arContacts(10, PtrKeySortT); - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) - if (!isChatRoom(hContact)) - arContacts.insert((HANDLE)hContact); - - for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) { - hContact = SetContactInfo((*it)); - if (hContact) - arContacts.remove((HANDLE)hContact); - } + for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) { + hContact = SetContactInfo((*it)); + if (hContact) + arContacts.remove((HANDLE)hContact); + } - if (jnResponse["freeoffline"].as_bool()) - for (int i = 0; i < arContacts.getCount(); i++) { - hContact = (UINT_PTR)arContacts[i]; - LONG userID = getDword(hContact, "ID", -1); - if (userID == m_myUserId || userID == VK_FEED_USER) - continue; + if (jnResponse["freeoffline"].as_bool()) + for (int i = 0; i < arContacts.getCount(); i++) { + hContact = (UINT_PTR)arContacts[i]; + LONG userID = getDword(hContact, "ID", -1); + if (userID == m_myUserId || userID == VK_FEED_USER) + continue; - int iContactStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE); + int iContactStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE); - if ((iContactStatus == ID_STATUS_ONLINE) - || (iContactStatus == ID_STATUS_INVISIBLE && time(NULL) - getDword(hContact, "InvisibleTS", 0) >= m_iInvisibleInterval * 60LL)) { - setWord(hContact, "Status", ID_STATUS_OFFLINE); - SetMirVer(hContact, -1); - db_unset(hContact, m_szModuleName, "ListeningTo"); - } + if ((iContactStatus == ID_STATUS_ONLINE) + || (iContactStatus == ID_STATUS_INVISIBLE && time(NULL) - getDword(hContact, "InvisibleTS", 0) >= m_iInvisibleInterval * 60LL)) { + setWord(hContact, "Status", ID_STATUS_OFFLINE); + SetMirVer(hContact, -1); + db_unset(hContact, m_szModuleName, "ListeningTo"); } + } - arContacts.destroy(); - } - + arContacts.destroy(); AddFeedSpecialUser(); const JSONNode &jnRequests = jnResponse["requests"]; -- cgit v1.2.3