From 3a08c1d0ba1fe146bd53bdfd5b47e08db745cd5b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 13 Oct 2013 07:24:58 +0000 Subject: VK: online statuses git-svn-id: http://svn.miranda-ng.org/main/trunk@6473 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/misc.cpp | 12 ++++++------ protocols/VKontakte/src/vk.h | 12 ++++++++++++ protocols/VKontakte/src/vk_proto.h | 2 +- protocols/VKontakte/src/vk_queue.cpp | 7 ++----- protocols/VKontakte/src/vk_thread.cpp | 34 +++++++++++++++++++++++++++------- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 2d7cc09fca..64dc4d006a 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -38,14 +38,14 @@ void CVkProto::SetAllContactStatuses(int iStatus) } } -HANDLE CVkProto::FindUser(LPCSTR pUserid, bool bCreate) +HANDLE CVkProto::FindUser(LONG dwUserid, bool bCreate) { for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - ptrA dbUserid(getStringA(hContact, "ID")); - if (dbUserid == NULL) + LONG dbUserid = getDword(hContact, "ID", -1); + if (dbUserid == -1) continue; - if ( !strcmp(dbUserid, pUserid)) + if (dbUserid == dwUserid) return hContact; } @@ -54,7 +54,7 @@ HANDLE CVkProto::FindUser(LPCSTR pUserid, bool bCreate) HANDLE hNewContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hNewContact, (LPARAM)m_szModuleName); - setString(hNewContact, "ID", pUserid); + setDword(hNewContact, "ID", dwUserid); db_set_ts(hNewContact, "CList", "Group", m_defaultGroup); return hNewContact; } @@ -193,7 +193,7 @@ CMStringA CVkProto::RunCaptchaForm(LPCSTR szUrl) NETLIBHTTPREQUEST req = { sizeof(req) }; req.requestType = REQUEST_GET; req.szUrl = (LPSTR)szUrl; - req.flags = NLHRF_HTTP11; + req.flags = NLHRF_HTTP11 | NLHRF_NODUMPHEADERS; req.timeout = 60; NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req); diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h index e9f0779ca8..6c17a983ea 100644 --- a/protocols/VKontakte/src/vk.h +++ b/protocols/VKontakte/src/vk.h @@ -20,6 +20,18 @@ along with this program. If not, see . #define VK_API_URL "api.vk.com" #define VK_REDIRECT_URL "http://" VK_API_URL "/blank.html" +#define VKPOLL_MSG_REMOVED 0 +#define VKPOLL_MSG_NEWFLAGS 1 +#define VKPOLL_MSG_ADDFLAGS 2 +#define VKPOLL_MSG_DELFLAGS 3 +#define VKPOLL_MSG_ADDED 4 +#define VKPOLL_USR_ONLINE 8 +#define VKPOLL_USR_OFFLINE 9 +#define VKPOLL_CHAT_CHANGED 51 +#define VKPOLL_USR_UTN 61 +#define VKPOLL_CHAT_UTN 62 +#define VKPOLL_RING 70 + struct HttpParam { LPCSTR szName, szValue; diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 14c4e6b354..a1f3347ac7 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -152,7 +152,7 @@ private: void GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t cbLen); - HANDLE FindUser(LPCSTR userid, bool bCreate = false); + HANDLE FindUser(LONG userid, bool bCreate = false); void SetAllContactStatuses(int status); diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index 4df189f99f..6efc4d29ea 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -67,7 +67,7 @@ bool CVkProto::PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure return false; AsyncHttpRequest *pReq = new AsyncHttpRequest(); - pReq->flags = NLHRF_DUMPASTEXT | NLHRF_PERSISTENT | NLHRF_HTTP11 | NLHRF_REDIRECT; + pReq->flags = NLHRF_NODUMPHEADERS | NLHRF_DUMPASTEXT | NLHRF_PERSISTENT | NLHRF_HTTP11 | NLHRF_REDIRECT; if (bSecure) pReq->flags |= NLHRF_SSL; @@ -77,10 +77,7 @@ bool CVkProto::PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure url += szUrl; pReq->nlc = m_hNetlibConn; } - else { - url = szUrl; - pReq->flags |= NLHRF_REMOVEHOST | NLHRF_SMARTREMOVEHOST; - } + else url = szUrl; for (int i=0; i < nParams; i++) { url.AppendChar((i == 0) ? '?' : '&'); diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 20a4cbde22..43f495756f 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -298,7 +298,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, void*) if (szValue == NULL) continue; - HANDLE hContact = FindUser(_T2A(szValue), true); + HANDLE hContact = FindUser( _ttoi(szValue), true); szValue = json_as_string( json_get(pInfo, "first_name")); if (szValue) setTString(hContact, "FirstName", szValue); @@ -363,10 +363,9 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, void*) int isRead = json_as_int( json_get(pMsg, "read_state")); ptrT ptszBody( json_as_string( json_get(pMsg, "body"))); - char szUserid[40], szMid[40]; - _itoa(uid, szUserid, 10); + char szMid[40]; _itoa(mid, szMid, 10); - HANDLE hContact = FindUser(szUserid, true); + HANDLE hContact = FindUser(uid, true); PROTORECVEVENT recv = { 0 }; recv.flags = PREF_TCHAR; @@ -431,7 +430,8 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) debugLogA("CVkProto::PollUpdates"); CMStringA mids; - int msgid; + int msgid, uid; + HANDLE hContact; JSONNODE *pChild; for (int i=0; (pChild = json_at(pUpdates, i)) != NULL; i++) { @@ -440,7 +440,7 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) continue; switch (json_as_int( json_at(pArray, 0))) { - case 4: // new message + case VKPOLL_MSG_ADDED: // new message msgid = json_as_int( json_at(pArray, 1)); if ( !CheckMid(msgid)) { if ( !mids.IsEmpty()) @@ -448,6 +448,26 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) mids.AppendFormat("%d", msgid); } break; + + case VKPOLL_USR_ONLINE: + uid = -json_as_int( json_at(pArray, 1)); + if ((hContact = FindUser(uid)) != NULL) + setWord(hContact, "Status", ID_STATUS_ONLINE); + break; + + case VKPOLL_USR_OFFLINE: + uid = -json_as_int( json_at(pArray, 1)); + if ((hContact = FindUser(uid)) != NULL) { + int flags = json_as_int( json_at(pArray, 2)); + setWord(hContact, "Status", (flags == 0) ? ID_STATUS_OFFLINE : ID_STATUS_AWAY); + } + break; + + case VKPOLL_USR_UTN: + uid = json_as_int( json_at(pArray, 1)); + if ((hContact = FindUser(uid)) != NULL) + CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, 5); + break; } } @@ -467,7 +487,7 @@ int CVkProto::PollServer() NETLIBHTTPREQUEST req = { sizeof(req) }; req.requestType = REQUEST_GET; req.szUrl = NEWSTR_ALLOCA(CMStringA().Format("%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken)); - req.flags = NLHRF_NODUMP | NLHRF_HTTP11 | NLHRF_PERSISTENT; + req.flags = NLHRF_NODUMPHEADERS | NLHRF_HTTP11 | NLHRF_PERSISTENT; req.nlc = m_pollingConn; req.timeout = 30000; -- cgit v1.2.3