diff options
author | ElzorFox <elzorfox@ya.ru> | 2017-01-23 13:42:53 +0500 |
---|---|---|
committer | ElzorFox <elzorfox@ya.ru> | 2017-01-23 13:42:53 +0500 |
commit | 705649686832a6e12d7eea59e20528a7e61abe14 (patch) | |
tree | e093abc6ffe2ca6ebe822b6f2fffac12ea3bef87 /protocols/VKontakte/src/vk_messages.cpp | |
parent | f7bbe11df6dc63ca32e7599a4bd64ea95990065d (diff) |
VKontakte:
rename option ‘Automatically wipe local contacts missing in your friend list’ ->’ Load only friends to local contact list’
rework loading clist logic (now if option ‘ Load only friends to local contact list’ is true, non-friends contact are not created on loading dialogs and are not cleaned automatically on loading friendlist)
version bump
Diffstat (limited to 'protocols/VKontakte/src/vk_messages.cpp')
-rw-r--r-- | protocols/VKontakte/src/vk_messages.cpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index 84b8075d3f..a627fbaf93 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -210,8 +210,11 @@ void CVkProto::RetrieveUnreadMessages() debugLogA("CVkProto::RetrieveUnreadMessages");
if (!IsOnline())
return;
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getDialogs.json", true, &CVkProto::OnReceiveDlgs)
- << INT_PARAM ("count", 200));
+
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveDlgs, AsyncHttpRequest::rpHigh)
+ << CHAR_PARAM("code", "var dlg=API.messages.getDialogs({\"count\":200});"
+ "var users=API.friends.areFriends({\"user_ids\":dlg.items@.message@.user_id});"
+ "return{\"dialogs\":dlg, \"users\":users};"));
}
void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
@@ -343,10 +346,30 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) if (!jnResponse)
return;
- const JSONNode &jnDlgs = jnResponse["items"];
+ const JSONNode &jnDialogs = jnResponse["dialogs"];
+ if (!jnDialogs)
+ return;
+
+ const JSONNode &jnDlgs = jnDialogs["items"];
if (!jnDlgs)
return;
+ OBJLIST<CVKUsersAreFriend> lufUsers(20, NumericKeySortT);
+ const JSONNode &jnUsers = jnResponse["users"];
+ if (jnUsers) {
+ for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) {
+ int iUserId = (*it)["user_id"].as_int();
+ int iStatus = (*it)["friend_status"].as_int();
+
+ CVKUsersAreFriend* ufUser = lufUsers.find((CVKUsersAreFriend*)&iUserId);
+ if (ufUser)
+ continue;
+
+ ufUser = new CVKUsersAreFriend(iUserId, iStatus);
+ lufUsers.insert(ufUser);
+ }
+ }
+
CMStringA szGroupIds;
for (auto it = jnDlgs.begin(); it != jnDlgs.end(); ++it) {
@@ -364,7 +387,18 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) if (!chatid) {
uid = jnDlg["user_id"].as_int();
+
+ CVKUsersAreFriend* ufUser = lufUsers.find((CVKUsersAreFriend*)&uid);
+ int iFriendStatus = ufUser ? ufUser->iStatus : 0;
+ debugLogA("CVkProto::OnReceiveDlgs UserId = %d, FriendStatus = %d, numUnread = %d", uid, iFriendStatus, numUnread);
+
+ // iFriendStatus == 3 - user is friend
+ // uid > 0 - user is not group and etc.
+ if (m_vkOptions.bLoadOnlyFriends && uid > 0 && numUnread == 0 && iFriendStatus != 3)
+ continue;
+
hContact = FindUser(uid, true);
+ debugLogA("CVkProto::OnReceiveDlgs add UserId = %d", uid);
if (IsGroupUser(hContact))
szGroupIds.AppendFormat(szGroupIds.IsEmpty() ? "%d" : ",%d", -1 * uid);
@@ -406,6 +440,8 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) MarkMessagesRead(hContact);
}
}
+
+ lufUsers.destroy();
RetrieveUsersInfo();
RetrieveGroupInfo(szGroupIds);
}
\ No newline at end of file |