From f5c6577e2ae7e5addfbc2aa5aecffcd99a43ce94 Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Mon, 8 Sep 2014 05:48:59 +0000 Subject: VKontakte: upgrade vk api version to 5.24 part 1 git-svn-id: http://svn.miranda-ng.org/main/trunk@10403 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk.h | 4 ++++ protocols/VKontakte/src/vk_chats.cpp | 22 +++++++++++++++++----- protocols/VKontakte/src/vk_proto.cpp | 4 +++- protocols/VKontakte/src/vk_queue.cpp | 1 + protocols/VKontakte/src/vk_thread.cpp | 30 +++++++++++++++++++++--------- 5 files changed, 46 insertions(+), 15 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h index 20a5fec2e8..2a322ddb86 100644 --- a/protocols/VKontakte/src/vk.h +++ b/protocols/VKontakte/src/vk.h @@ -40,6 +40,10 @@ along with this program. If not, see . #define VKFLAG_MSGFIXED 256 // сообщение проверено пользователем на спам #define VKFLAG_MSGMEDIA 512 // сообщение содержит медиаконтент +#define VK_API_VER "5.24" +#define VER_API CHAR_PARAM("v", VK_API_VER) + + #if defined(_DEBUG) #define VK_NODUMPHEADERS 0 #else diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 7a83bd2853..ba78103f0d 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -82,6 +82,7 @@ CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg) void CVkProto::RetrieveChatInfo(CVkChatInfo *cc) { + //need rework CMStringA szQuery("return { "); // retrieve title & owner id @@ -335,7 +336,7 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam) TCHAR *buf = NEWTSTR_ALLOCA(gch->ptszText); rtrimt(buf); UnEscapeChatTags(buf); - + // need rework - change reply format and type not supported yet AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg) << INT_PARAM("type", 1) << INT_PARAM("chat_id", cc->m_chatid); pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -425,7 +426,9 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) case IDM_TOPIC: if (LPTSTR ptszNew = ChangeChatTopic(cc)) { Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.editChat.json", true, &CVkProto::OnReceiveSmth) - << TCHAR_PARAM("title", ptszNew) << INT_PARAM("chat_id", cc->m_chatid)); + << TCHAR_PARAM("title", ptszNew) + << INT_PARAM("chat_id", cc->m_chatid) + << VER_API); mir_free(ptszNew); } break; @@ -436,7 +439,9 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) int uid = getDword(hContact, "ID", -1); if (uid != -1) Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.addChatUser.json", true, &CVkProto::OnReceiveSmth) - << INT_PARAM("uid", uid) << INT_PARAM("chat_id", cc->m_chatid)); + << INT_PARAM("user_id", uid) + << INT_PARAM("chat_id", cc->m_chatid) + << VER_API); } break; @@ -445,6 +450,9 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) TranslateT("This chat is going to be destroyed forever with all its contents. This action cannot be undone. Are you sure?"), TranslateT("Warning"), MB_YESNOCANCEL | MB_ICONQUESTION)) { + // need rework + // hmmm + // deleteDialog not support chat_id yet Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.deleteDialog.json", true, &CVkProto::OnChatDestroy) << INT_PARAM("chat_id", cc->m_chatid))->pUserInfo = cc; } @@ -486,7 +494,9 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) case IDM_KICK: Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.removeChatUser.json", true, &CVkProto::OnReceiveSmth) - << INT_PARAM("chat_id", cc->m_chatid) << INT_PARAM("uid", cu->m_uid)); + << INT_PARAM("chat_id", cc->m_chatid) + << INT_PARAM("uid", cu->m_uid) + << VER_API); cu->m_bUnknown = true; break; } @@ -619,7 +629,9 @@ INT_PTR CVkProto::SvcCreateChat(WPARAM, LPARAM) void CVkProto::CreateNewChat(LPCSTR uids, LPCTSTR ptszTitle) { Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.createChat.json", true, &CVkProto::OnCreateNewChat) - << TCHAR_PARAM("title", ptszTitle) << CHAR_PARAM("uids", uids)); + << TCHAR_PARAM("title", ptszTitle) + << CHAR_PARAM("user_ids", uids) + << VER_API); } void CVkProto::OnCreateNewChat(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index e12e19ae5e..63467a2cd4 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -203,6 +203,7 @@ int CVkProto::SendMsg(MCONTACT hContact, int flags, const char *msg) szMsg = mir_utf8encode(msg); ULONG msgId = ::InterlockedIncrement(&m_msgId); + // need rework - change reply format and uid => user_id, type not supported yet AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage) << INT_PARAM("type", 0) << INT_PARAM("uid", userID); pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -342,7 +343,8 @@ int CVkProto::UserIsTyping(MCONTACT hContact, int type) Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.setActivity.json", true, &CVkProto::OnReceiveSmth) << INT_PARAM("user_id", userID) - << CHAR_PARAM("type", "typing")); + << CHAR_PARAM("type", "typing") + << VER_API); return 0; } return 1; diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index f02dcde11a..b19d47f4cc 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -80,6 +80,7 @@ void CVkProto::WorkerThread(void*) else { // Initialize new OAuth session extern char szBlankUrl[]; + //need rework Push(new AsyncHttpRequest(this, REQUEST_GET, "/oauth/authorize", false, &CVkProto::OnOAuthAuthorize) << INT_PARAM("client_id", VK_APP_ID) << CHAR_PARAM("scope", "friends,photos,audio,video,wall,messages,offline") << CHAR_PARAM("redirect_uri", szBlankUrl) << CHAR_PARAM("display", "wap") << CHAR_PARAM("response_type", "token")); diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index c8b5642ce9..4d6a19d458 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -97,11 +97,13 @@ void CVkProto::SetServerStatus(int iNewStatus) if (iNewStatus == ID_STATUS_OFFLINE) { m_iStatus = ID_STATUS_OFFLINE; - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/account.setOffline.json", true, &CVkProto::OnReceiveSmth)); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/account.setOffline.json", true, &CVkProto::OnReceiveSmth) + << VER_API); } else if (iNewStatus != ID_STATUS_INVISIBLE) { m_iStatus = ID_STATUS_ONLINE; - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/account.setOnline.json", true, &CVkProto::OnReceiveSmth)); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/account.setOnline.json", true, &CVkProto::OnReceiveSmth) + << VER_API); } else m_iStatus = ID_STATUS_INVISIBLE; @@ -198,6 +200,7 @@ LBL_NoForm: void CVkProto::RetrieveMyInfo() { + // Old method Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/getUserInfoEx.json", true, &CVkProto::OnReceiveMyInfo)); } @@ -234,6 +237,8 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) void CVkProto::RetrieveUserInfo(LONG userID) { + // Old method + // replaced to users.get Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/getProfiles.json", true, &CVkProto::OnReceiveUserInfo) << INT_PARAM("uids", userID) << CHAR_PARAM("fields", "uid,first_name,last_name,photo_medium,sex,bdate,city,relation")); } @@ -300,7 +305,8 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe void CVkProto::RetrieveFriends() { debugLogA("CVkProto::RetrieveFriends"); - + // Old method + // fields 'country' and 'city' replaced to objects Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.get.json", true, &CVkProto::OnReceiveFriends) << INT_PARAM("count", 1000) << CHAR_PARAM("fields", "uid,first_name,last_name,photo_medium,sex,country,timezone,contacts")); } @@ -380,7 +386,7 @@ void CVkProto::MarkMessagesRead(const CMStringA &mids) return; Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth) - << CHAR_PARAM("mids", mids)); + << CHAR_PARAM("message_ids", mids) << VER_API); } void CVkProto::MarkMessagesRead(const MCONTACT hContact) @@ -390,14 +396,15 @@ void CVkProto::MarkMessagesRead(const MCONTACT hContact) return; Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth) - << INT_PARAM("peer_id", userID)); + << INT_PARAM("peer_id", userID) << VER_API); } void CVkProto::RetrieveMessagesByIds(const CMStringA &mids) { if (mids.IsEmpty()) return; - + // Old method + // change 'message' object and mids => message_ids Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getById.json", true, &CVkProto::OnReceiveMessages) << CHAR_PARAM("mids", mids)); } @@ -405,7 +412,8 @@ void CVkProto::RetrieveMessagesByIds(const CMStringA &mids) void CVkProto::RetrieveUnreadMessages() { debugLogA("CVkProto::RetrieveMessages"); - + // Old method + // change 'message' and dialogs object and filters=1 not suported Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveMessages) << CHAR_PARAM("code", "return { \"msgs\":API.messages.get({\"filters\":1}), \"dlgs\":API.messages.getDialogs() };")); } @@ -557,7 +565,7 @@ void CVkProto::GetHistoryDlgMessages(MCONTACT hContact, int iOffset, int iMaxCou << INT_PARAM("offset", iOffset) << INT_PARAM("count", iReqCount) << INT_PARAM("user_id", userID) - << CHAR_PARAM("v", "5.24"); + << VER_API; pReq->pUserInfo = new CVkSendMsgParam(hContact, iOffset); Push(pReq); @@ -640,7 +648,8 @@ void CVkProto::RetrievePollingInfo() { debugLogA("CVkProto::RetrievePollingInfo"); - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getLongPollServer.json", true, &CVkProto::OnReceivePollingInfo)); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getLongPollServer.json", true, &CVkProto::OnReceivePollingInfo) + << VER_API); } void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) @@ -744,6 +753,7 @@ int CVkProto::PollServer() { debugLogA("CVkProto::PollServer"); + //need rework NETLIBHTTPREQUEST req = { sizeof(req) }; req.requestType = REQUEST_GET; req.szUrl = NEWSTR_ALLOCA(CMStringA().Format("http://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken)); @@ -796,6 +806,8 @@ void CVkProto::PollingThread(void*) CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments) { + // need rework + CMString res; res.AppendChar('\n'); res += TranslateT("Attachments:"); -- cgit v1.2.3