diff options
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 5 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_search.cpp | 53 |
3 files changed, 58 insertions, 2 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index c867bf0c65..2e437d290e 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -281,7 +281,7 @@ DWORD_PTR CVkProto::GetCaps(int type, MCONTACT hContact) {
switch(type) {
case PFLAGNUM_1:
- return PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_SEARCHBYNAME | PF1_MODEMSG;
+ return PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_SEARCHBYNAME | PF1_SEARCHBYEMAIL | PF1_MODEMSG;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_INVISIBLE | PF2_ONTHEPHONE | PF2_IDLE;
@@ -447,7 +447,8 @@ HANDLE CVkProto::SearchBasic(const PROTOCHAR* id) HANDLE CVkProto::SearchByEmail(const PROTOCHAR* email)
{
- return 0;
+ ForkThread(&CVkProto::SearchByMailThread, (void *)email);
+ return (HANDLE)1;
}
HANDLE CVkProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName)
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index d5352338dc..2768b61ebe 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -219,8 +219,10 @@ struct CVkProto : public PROTO<CVkProto> //==== Search ========================================================================
void __cdecl SearchBasicThread(void* id);
+ void __cdecl SearchByMailThread(void* email);
void __cdecl SearchThread(void* p);
void OnSearch(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnSearchByMail(NETLIBHTTPREQUEST *, AsyncHttpRequest *);
//==== Misc ==========================================================================
diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp index d85d91168b..5763f6d7ca 100644 --- a/protocols/VKontakte/src/vk_search.cpp +++ b/protocols/VKontakte/src/vk_search.cpp @@ -39,6 +39,16 @@ void CVkProto::SearchBasicThread(void* id) Push(pReq);
}
+void CVkProto::SearchByMailThread(void* email)
+{
+ debugLogA("CVkProto::OnSearchBasicThread");
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/account.lookupContacts.json", true, &CVkProto::OnSearchByMail)
+ << TCHAR_PARAM("contacts", (TCHAR *)email)
+ << CHAR_PARAM("service", "email")
+ << VER_API;
+ Push(pReq);
+}
+
void __cdecl CVkProto::SearchThread(void* p)
{
PROTOSEARCHBYNAME *pParam = (PROTOSEARCHBYNAME *)p;
@@ -128,3 +138,46 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) delete pParam;
}
}
+
+void CVkProto::OnSearchByMail(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
+{
+ debugLogA("CVkProto::OnSearch %d", reply->resultCode);
+ if (reply->resultCode != 200){
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ return;
+ }
+
+ JSONROOT pRoot;
+ JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
+ if (pResponse == NULL){
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ return;
+ }
+
+ JSONNODE *pItems = json_get(pResponse, "found");
+ if (!pItems){
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ return;
+ }
+
+ for (int i = 0;; i++) {
+ JSONNODE *pRecord = json_at(pItems, i);
+ if (pRecord == NULL)
+ break;
+
+ PROTOSEARCHRESULT psr = { sizeof(psr) };
+ psr.flags = PSR_TCHAR;
+
+ psr.id = mir_wstrdup(json_as_string(json_get(pRecord, "id")));
+ psr.firstName = mir_wstrdup(json_as_string(json_get(pRecord, "first_name")));
+ psr.lastName = mir_wstrdup(json_as_string(json_get(pRecord, "last_name")));
+ psr.nick = mir_wstrdup(json_as_string(json_get(pRecord, "nickname")));
+ psr.email = mir_wstrdup(json_as_string(json_get(pRecord, "contact")));
+ if (!psr.nick || !psr.nick[0])
+ psr.nick = psr.email;
+
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
+ }
+
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+}
|