summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElzorFox <elzorfox@ya.ru>2017-01-23 13:42:53 +0500
committerElzorFox <elzorfox@ya.ru>2017-01-23 13:42:53 +0500
commit705649686832a6e12d7eea59e20528a7e61abe14 (patch)
treee093abc6ffe2ca6ebe822b6f2fffac12ea3bef87
parentf7bbe11df6dc63ca32e7599a4bd64ea95990065d (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
-rw-r--r--protocols/VKontakte/res/resource.rc2
-rw-r--r--protocols/VKontakte/src/resource.h2
-rw-r--r--protocols/VKontakte/src/version.h2
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp42
-rw-r--r--protocols/VKontakte/src/vk_options.cpp4
-rw-r--r--protocols/VKontakte/src/vk_options.h2
-rw-r--r--protocols/VKontakte/src/vk_struct.cpp10
-rw-r--r--protocols/VKontakte/src/vk_struct.h13
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp4
9 files changed, 67 insertions, 14 deletions
diff --git a/protocols/VKontakte/res/resource.rc b/protocols/VKontakte/res/resource.rc
index 8e39824aaa..5badf44389 100644
--- a/protocols/VKontakte/res/resource.rc
+++ b/protocols/VKontakte/res/resource.rc
@@ -305,7 +305,7 @@ BEGIN
CONTROL "Server-side delivery confirmation",IDC_DELIVERY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,157,278,10
CONTROL "Use local time for received messages",IDC_USE_LOCAL_TIME,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,137,278,10
- CONTROL "Automatically wipe local contacts missing in your friend list",IDC_AUTOCLEAN,
+ CONTROL "Load only friends to local contact list",IDC_LOADONLYFRIENDS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,147,278,10
RTEXT "Mark message as read:",IDC_STATIC,12,101,150,12,SS_CENTERIMAGE
COMBOBOX IDC_COMBO_MARKASREAD,167,101,121,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h
index 0fa7af88fc..edfaff5ac3 100644
--- a/protocols/VKontakte/src/resource.h
+++ b/protocols/VKontakte/src/resource.h
@@ -41,7 +41,7 @@
#define IDC_CLIST 1013
#define IDC_HIDECHATS 1014
#define IDC_CONTACT 1015
-#define IDC_AUTOCLEAN 1020
+#define IDC_LOADONLYFRIENDS 1020
#define IDC_MESASUREAD 1025
#define IDC_SYNC_MSG_STATUS 1026
#define IDC_USE_LOCAL_TIME 1029
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h
index 7348f04c1f..6c45de27ca 100644
--- a/protocols/VKontakte/src/version.h
+++ b/protocols/VKontakte/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 2
-#define __BUILD_NUM 10
+#define __BUILD_NUM 11
#include <stdver.h>
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
diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp
index 161fd266cb..15cec12e55 100644
--- a/protocols/VKontakte/src/vk_options.cpp
+++ b/protocols/VKontakte/src/vk_options.cpp
@@ -146,7 +146,7 @@ CVkOptionAccountForm::CVkOptionAccountForm(CVkProto *proto):
m_cbxVKLang(this, IDC_COMBO_LANGUAGE),
m_cbDelivery(this, IDC_DELIVERY),
m_cbUseLocalTime(this, IDC_USE_LOCAL_TIME),
- m_cbAutoClean(this, IDC_AUTOCLEAN),
+ m_cbLoadOnlyFriends(this, IDC_LOADONLYFRIENDS),
m_cbxMarkAsRead(this, IDC_COMBO_MARKASREAD),
m_cbxSyncHistory(this, IDC_COMBO_SYNCHISTORY)
{
@@ -154,7 +154,7 @@ CVkOptionAccountForm::CVkOptionAccountForm(CVkProto *proto):
CreateLink(m_edtGroupName, m_proto->m_vkOptions.pwszDefaultGroup);
CreateLink(m_cbDelivery, m_proto->m_vkOptions.bServerDelivery);
CreateLink(m_cbUseLocalTime, m_proto->m_vkOptions.bUseLocalTime);
- CreateLink(m_cbAutoClean, m_proto->m_vkOptions.bAutoClean);
+ CreateLink(m_cbLoadOnlyFriends, m_proto->m_vkOptions.bLoadOnlyFriends);
}
void CVkOptionAccountForm::OnInitDialog()
diff --git a/protocols/VKontakte/src/vk_options.h b/protocols/VKontakte/src/vk_options.h
index 4b6ff217be..9758d95ddf 100644
--- a/protocols/VKontakte/src/vk_options.h
+++ b/protocols/VKontakte/src/vk_options.h
@@ -50,7 +50,7 @@ class CVkOptionAccountForm : public CVkDlgBase
CCtrlCombo m_cbxVKLang;
CCtrlCheck m_cbDelivery;
CCtrlCheck m_cbUseLocalTime;
- CCtrlCheck m_cbAutoClean;
+ CCtrlCheck m_cbLoadOnlyFriends;
CCtrlCombo m_cbxSyncHistory;
CCtrlCombo m_cbxMarkAsRead;
diff --git a/protocols/VKontakte/src/vk_struct.cpp b/protocols/VKontakte/src/vk_struct.cpp
index ec7531c212..67eec095fa 100644
--- a/protocols/VKontakte/src/vk_struct.cpp
+++ b/protocols/VKontakte/src/vk_struct.cpp
@@ -167,7 +167,7 @@ CVkChatUser* CVkChatInfo::GetUserById(int user_id)
/////////////////////////////////////////////////////////////////////////////////////////
CVKOptions::CVKOptions(PROTO_INTERFACE *proto) :
- bAutoClean(proto, "AutoClean", false),
+ bLoadOnlyFriends(proto, "LoadOnlyFriends", false),
bServerDelivery(proto, "BsDirect", true),
bHideChats(proto, "HideChats", true),
bMesAsUnread(proto, "MesAsUnread", false),
@@ -239,4 +239,12 @@ CVKOptions::CVKOptions(PROTO_INTERFACE *proto) :
pwszVKLang(proto, "VKLang", NULL)
{
+ // Note: Delete this code after next stable build
+ int iAutoClean = db_get_b(NULL, proto->m_szModuleName, "AutoClean", -1);
+ if (iAutoClean != -1) {
+ bLoadOnlyFriends = (BYTE) iAutoClean;
+ db_set_b(NULL, proto->m_szModuleName, "LoadOnlyFriends", bLoadOnlyFriends);
+ db_unset(NULL, proto->m_szModuleName, "AutoClean");
+ }
+ // Note
}
diff --git a/protocols/VKontakte/src/vk_struct.h b/protocols/VKontakte/src/vk_struct.h
index 9e04c20d98..45ddd37fcf 100644
--- a/protocols/VKontakte/src/vk_struct.h
+++ b/protocols/VKontakte/src/vk_struct.h
@@ -287,7 +287,7 @@ struct CVkCookie
};
struct CVKOptions {
- CMOption<BYTE> bAutoClean;
+ CMOption<BYTE> bLoadOnlyFriends;
CMOption<BYTE> bServerDelivery;
CMOption<BYTE> bHideChats;
CMOption<BYTE> bMesAsUnread;
@@ -363,8 +363,17 @@ struct CVKOptions {
};
-
struct CVKDeactivateEvent {
wchar_t *wszType;
char *szDescription;
+};
+
+struct CVKUsersAreFriend {
+ CVKUsersAreFriend(int _iUserId, int _iStatus) :
+ iUserId(_iUserId),
+ iStatus(_iStatus)
+ {}
+
+ int iUserId;
+ int iStatus;
}; \ No newline at end of file
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index e47ca75430..9bec13a8f6 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -659,7 +659,7 @@ void CVkProto::OnReceiveGroupInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR
int iGroupId = (-1)*jnItem["id"].as_int();
bool bIsMember = jnItem["is_member"].as_bool();
- if (!bIsMember && m_vkOptions.bAutoClean)
+ if (!bIsMember && m_vkOptions.bLoadOnlyFriends)
continue;
MCONTACT hContact = FindUser(iGroupId, true);
@@ -740,7 +740,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
return;
CVkSendMsgParam *param = (CVkSendMsgParam *)pReq->pUserInfo;
- bool bCleanContacts = m_vkOptions.bAutoClean || (param->iMsgID != 0);
+ bool bCleanContacts = (param->iMsgID != 0);
delete param;
LIST<void> arContacts(10, PtrKeySortT);