diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-25 13:07:04 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-25 13:07:04 +0000 |
commit | de497674186d02d6752de6d64ed978cca6dccbc5 (patch) | |
tree | ffffcc82be6ffc59fa06ef36a60801e06d8bc55b | |
parent | aea3eae236772b0661a246d516720dc3fb026ed9 (diff) |
VKontakte: work with friends.getRequests part 1
git-svn-id: http://svn.miranda-ng.org/main/trunk@10586 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 40 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 69 |
3 files changed, 95 insertions, 16 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index f7856a5b4f..da01c8dbcc 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -349,3 +349,43 @@ void CVkProto::ApplyCookies(AsyncHttpRequest *pReq) if (!szCookie.IsEmpty())
pReq->AddHeader("Cookie", szCookie);
}
+
+void CVkProto::DBAddAuthRequest(const MCONTACT hContact)
+{
+ //char* szJid = mir_utf8encodeT(jid);
+ CMString tszNick = db_get_sa(hContact, m_szModuleName, "Nick");
+ char* szNick = mir_utf8encodeT(tszNick.GetBuffer());
+
+ //blob is: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
+ //blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ)
+ DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
+ dbei.szModule = m_szModuleName;
+ dbei.timestamp = (DWORD)time(NULL);
+ dbei.flags = DBEF_UTF;
+ dbei.eventType = EVENTTYPE_AUTHREQUEST;
+ dbei.cbBlob = (DWORD)(sizeof(DWORD) * 2 + strlen(szNick) + 5);
+
+ PBYTE pCurBlob = dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
+
+ *((PDWORD)pCurBlob) = 0;
+ pCurBlob += sizeof(DWORD); // uin(DWORD) = 0 (DWORD)
+
+ *((PDWORD)pCurBlob) = (DWORD)hContact;
+ pCurBlob += sizeof(DWORD); // hContact(DWORD)
+
+ strcpy((char*)pCurBlob, szNick);
+ pCurBlob += strlen(szNick) + 1;
+
+ *pCurBlob = '\0'; //firstName
+ pCurBlob++;
+ *pCurBlob = '\0'; //lastName
+ pCurBlob++;
+ *pCurBlob = '\0'; //email
+ pCurBlob++;
+ *pCurBlob = '\0'; //reason
+
+ db_event_add(NULL, &dbei);
+ debugLogA("CVkProto::DBAddAuthRequest '%s'", szNick);
+
+ mir_free(szNick);
+}
\ No newline at end of file diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index dc6d3bd8d4..03a6995035 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -373,4 +373,6 @@ private: HANDLE m_hPopupClass;
void InitPopups(void);
void MsgPopup(MCONTACT hContact, const TCHAR *szMsg, const TCHAR *szTitle);
+
+ void DBAddAuthRequest(const MCONTACT hContact);
};
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 1f4373fbd5..3804fbe525 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -239,58 +239,76 @@ static char fieldsName[] = "id, first_name, last_name, photo_100, bdate, sex, ti void CVkProto::RetrieveUserInfo(LONG userID)
{
+ debugLogA("CVkProto::RetrieveUserInfo %d", userID);
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnReceiveUserInfo)
<< INT_PARAM("user_ids", userID)
<< CHAR_PARAM("fields", fieldsName)
<< CHAR_PARAM("name_case", "nom")
- << VER_API);
+ << VER_API)->pUserInfo = new CVkSendMsgParam(NULL);
}
void CVkProto::RetrieveUsersInfo(bool flag)
{
- CMStringA userIDs;
+ debugLogA("CVkProto::RetrieveUsersInfo");
+
+ CMString userIDs;
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)){
LONG userID = getDword(hContact, "ID", -1);
if (userID == -1)
continue;
if (!userIDs.IsEmpty())
userIDs.AppendChar(',');
- userIDs.AppendFormat("%i", userID);
-
+ userIDs.AppendFormat(L"%i", userID);
}
-
- Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/users.get.json", true, &CVkProto::OnReceiveUserInfo)
- << CHAR_PARAM("user_ids", userIDs)
- << CHAR_PARAM("fields", flag?"online,status":fieldsName)
- << CHAR_PARAM("name_case", "nom")
- << VER_API);
+ if (flag){
+ CMString codeformat("var userIDs=\"%s\";"
+ "return{\"users\":API.users.get({\"user_ids\":userIDs,\"fields\":\"online,status\",\"name_case\":\"nom\"}),"
+ "\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":1})};"), code;
+ code.AppendFormat(codeformat, userIDs.GetBuffer());
+ Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.json", true, &CVkProto::OnReceiveUserInfo)
+ << TCHAR_PARAM("code", code)
+ << VER_API)->pUserInfo = new CVkSendMsgParam(NULL, flag);
+ }
+ else
+ Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/users.get.json", true, &CVkProto::OnReceiveUserInfo)
+ << TCHAR_PARAM("user_ids", userIDs)
+ << CHAR_PARAM("fields", fieldsName)
+ << CHAR_PARAM("name_case", "nom")
+ << VER_API)->pUserInfo = new CVkSendMsgParam(NULL, flag);
}
void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnReceiveUserInfo %d", reply->resultCode);
+
if ((reply->resultCode != 200) || !IsOnline())
return;
+ bool bIsReqInfo = ((CVkSendMsgParam*)pReq->pUserInfo)->iMsgID!=0;
+ delete pReq->pUserInfo;
JSONROOT pRoot;
JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
if (pResponse == NULL)
return;
+ JSONNODE *pUsers = bIsReqInfo ? json_get(pResponse, "users") : pResponse;
+ if (pUsers == NULL)
+ return;
+
for (size_t i=0; ; i++) {
- JSONNODE *pRecord = json_at(pResponse, i);
+ JSONNODE *pRecord = json_at(pUsers, i);
if (pRecord == NULL)
break;
LONG userid = json_as_int( json_get(pRecord, "id"));
if (userid == 0)
- return;
-
+ break;
+
MCONTACT hContact;
if (userid == m_myUserId)
hContact = NULL;
else if ((hContact = FindUser(userid, false)) == NULL)
- return;
+ break;
CMString tszNick;
int iValue;
@@ -363,6 +381,25 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (szValue && *szValue)
setTString(hContact, "domain", szValue);
}
+
+ return; // tempory
+
+ if (!bIsReqInfo)
+ return;
+
+ JSONNODE *pRequests = json_get(pResponse, "requests");
+ int iCount = json_as_int(json_get(pRequests, "count"));
+ JSONNODE *pItems = json_get(pRequests, "items"), *pInfo;
+
+ for (int i = 0; (pInfo = json_at(pItems, i)) != NULL; i++) {
+ LONG userid = json_as_int(pInfo);
+ if (userid == 0)
+ break;
+ MCONTACT hContact = FindUser(userid, true);
+ RetrieveUserInfo(userid);
+ Sleep(1000);
+ DBAddAuthRequest(hContact);
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -858,10 +895,10 @@ INT_PTR __cdecl CVkProto::SvcDeleteFriend(WPARAM hContact, LPARAM) return 1;
CMString formatstr = TranslateT("Are you sure to delete %s from your friend list?"),
- ptszNick = db_get_tsa(hContact, m_szModuleName, "Nick"),
+ tszNick = db_get_tsa(hContact, m_szModuleName, "Nick"),
ptszMsg;
- ptszMsg.AppendFormat(formatstr, ptszNick.IsEmpty() ? TranslateT("(Unknown contact)") : ptszNick);
+ ptszMsg.AppendFormat(formatstr, tszNick.IsEmpty() ? TranslateT("(Unknown contact)") : tszNick);
if (IDNO == MessageBox(NULL, ptszMsg.GetBuffer(), TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
return 1;
|