diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-18 07:15:32 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-18 07:15:32 +0000 |
commit | f6ea237b83c24ff0a9bfe8722465cde83c0b5d2d (patch) | |
tree | 48ffab29ab35caefdd3fab80a0dec43bead32a4f /protocols/VKontakte | |
parent | 10ab40864d776ad079938c36a39aef7a25d19b8c (diff) |
VKontakte:
remove PF1_SEARCHBYEMAIL protocol caps (not supported)
rework search by name logic
git-svn-id: http://svn.miranda-ng.org/main/trunk@10505 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 12 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_search.cpp | 86 |
3 files changed, 76 insertions, 24 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index e8f01b8897..ae146dd2f8 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -174,7 +174,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_SEARCHBYEMAIL | PF1_SEARCHBYNAME | PF1_MODEMSG;
+ return PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_SEARCHBYNAME | PF1_MODEMSG;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_INVISIBLE | PF2_ONTHEPHONE | PF2_IDLE;
@@ -345,9 +345,13 @@ HANDLE CVkProto::SearchByEmail(const PROTOCHAR* email) HANDLE CVkProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName)
{
- TCHAR arg[200]; - mir_sntprintf(arg, SIZEOF(arg), _T("%s %s %s"), nick, firstName, lastName);
- ForkThread(&CVkProto::SearchByStringThread, (void *)arg);
+ PROTOSEARCHBYNAME * psr = new (PROTOSEARCHBYNAME);
+
+ psr->pszFirstName = mir_wstrdup(firstName);
+ psr->pszLastName = mir_wstrdup(lastName);
+ psr->pszNick = mir_wstrdup(nick);
+
+ ForkThread(&CVkProto::SearchThread, (void *)psr);
return (HANDLE)1;
}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 750034ccc6..cd362baac6 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -205,7 +205,7 @@ struct CVkProto : public PROTO<CVkProto> //==== Search ========================================================================
void __cdecl SearchBasicThread(void* id);
- void __cdecl SearchByStringThread(void* id);
+ void __cdecl SearchThread(void* p);
void OnSearch(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
//==== Misc ==========================================================================
diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp index 0e7a0f4094..d85d91168b 100644 --- a/protocols/VKontakte/src/vk_search.cpp +++ b/protocols/VKontakte/src/vk_search.cpp @@ -17,28 +17,56 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
+
+static bool tlstrstr(TCHAR* _s1, TCHAR* _s2)
+{
+ TCHAR s1[200], s2[200];
+ mir_sntprintf(s1, SIZEOF(s1), _T("%s"), _s1);
+ mir_sntprintf(s2, SIZEOF(s2), _T("%s"), _s2);
+ CharLowerBuff(s1, SIZEOF(s1));
+ CharLowerBuff(s2, SIZEOF(s2));
+ return (_tcsstr(s1, s2)==NULL);
+}
+
void CVkProto::SearchBasicThread(void* id)
{
debugLogA("CVkProto::OnSearchBasicThread");
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnSearch)
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnSearch)
<< TCHAR_PARAM("user_ids", (TCHAR *)id)
- << VER_API);
-
+ << CHAR_PARAM("fields", "nickname, domain")
+ << VER_API;
+ pReq->pUserInfo = NULL;
+ Push(pReq);
}
-void __cdecl CVkProto::SearchByStringThread(void* str)
+void __cdecl CVkProto::SearchThread(void* p)
{
- debugLogA("CVkProto::SearchByStringThread");
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.search.json", true, &CVkProto::OnSearch)
- << TCHAR_PARAM("q", (TCHAR *)str)
+ PROTOSEARCHBYNAME *pParam = (PROTOSEARCHBYNAME *)p;
+ + TCHAR arg[200]; + mir_sntprintf(arg, SIZEOF(arg), _T("%s %s %s"), pParam->pszFirstName, pParam->pszNick, pParam->pszLastName);
+ debugLog(_T("CVkProto::SearchThread %s"), arg);
+
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/users.search.json", true, &CVkProto::OnSearch)
+ << TCHAR_PARAM("q", (TCHAR *)arg)
+ << CHAR_PARAM("fields", "nickname, domain")
<< INT_PARAM("count", 200)
- << VER_API);
+ << VER_API;
+ pReq->pUserInfo = p;
+ Push(pReq);
}
void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
+ PROTOSEARCHBYNAME *pParam = (PROTOSEARCHBYNAME *)pReq->pUserInfo;
debugLogA("CVkProto::OnSearch %d", reply->resultCode);
if (reply->resultCode != 200){
+ if (pParam){
+ mir_free(pParam->pszFirstName);
+ mir_free(pParam->pszLastName);
+ mir_free(pParam->pszNick);
+ delete pParam;
+ }
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
}
@@ -46,6 +74,12 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) JSONROOT pRoot;
JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
if (pResponse == NULL){
+ if (pParam){
+ mir_free(pParam->pszFirstName);
+ mir_free(pParam->pszLastName);
+ mir_free(pParam->pszNick);
+ delete pParam;
+ }
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
}
@@ -57,26 +91,40 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) iCount = 1;
}
-
- for (size_t i = 0; i<iCount; i++) {
- PROTOSEARCHRESULT psr = { sizeof(psr) };
- psr.flags = PSR_TCHAR;
-
+ for (int i = 0; i<iCount; i++) {
JSONNODE *pRecord = json_at(pItems, i);
if (pRecord == NULL)
break;
- CMString tszNick;
+ 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")));
- tszNick.Append(psr.firstName);
- tszNick.AppendChar(' ');
- tszNick.Append(psr.lastName);
- psr.nick = mir_wstrdup(tszNick.GetBuffer());
+ psr.nick = mir_wstrdup(json_as_string(json_get(pRecord, "nickname")));
+ if (!psr.nick || !psr.nick[0])
+ psr.nick = mir_wstrdup(json_as_string(json_get(pRecord, "domain")));
- ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
+ bool filter = true;
+ if (pParam){
+ if (psr.firstName&&pParam->pszFirstName)
+ filter = tlstrstr(psr.firstName, pParam->pszFirstName) && filter;
+ if (psr.lastName&&pParam->pszLastName)
+ filter = tlstrstr(psr.lastName, pParam->pszLastName) && filter;
+ if (psr.nick&&pParam->pszNick)
+ filter = tlstrstr(psr.nick, pParam->pszNick) && filter;
+ }
+
+ if (filter)
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
}
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ if (pParam){
+ mir_free(pParam->pszFirstName);
+ mir_free(pParam->pszLastName);
+ mir_free(pParam->pszNick);
+ delete pParam;
+ }
}
|