From 58e977eada0eb95198dbc552d99446c83506a73a Mon Sep 17 00:00:00 2001 From: ElzorFox Date: Thu, 9 Mar 2017 14:51:23 +0500 Subject: VKontakte: move js code to vk stored procedures version bump --- protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_chats.cpp | 61 ++++++++------------------------- protocols/VKontakte/src/vk_feed.cpp | 3 +- protocols/VKontakte/src/vk_history.cpp | 23 +++++-------- protocols/VKontakte/src/vk_messages.cpp | 21 ++---------- protocols/VKontakte/src/vk_status.cpp | 41 +++++----------------- protocols/VKontakte/src/vk_thread.cpp | 39 ++++++++------------- 7 files changed, 52 insertions(+), 138 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index c5db730bcd..889fc82466 100644 --- a/protocols/VKontakte/src/version.h +++ b/protocols/VKontakte/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 2 -#define __BUILD_NUM 13 +#define __BUILD_NUM 14 #include diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index f26d6f061f..975bcd9fdc 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -93,33 +93,12 @@ CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg) void CVkProto::RetrieveChatInfo(CVkChatInfo *cc) { + debugLogA("CVkProto::RetrieveChatInfo"); - CMStringA wszQuery(FORMAT, "var ChatId=%d;", cc->m_chatid); - wszQuery += "var Info=API.messages.getChat({\"chat_id\":ChatId});" - "var ChatUsers=API.messages.getChatUsers({\"chat_id\":ChatId,\"fields\":\"id,first_name,last_name\"});"; - - if (!cc->m_bHistoryRead) { - wszQuery += "var ChatMsg=API.messages.getHistory({\"chat_id\":ChatId,\"count\":20,\"rev\":0});var UR=parseInt(ChatMsg.unread);" - "if(UR>20){if(UR>200)UR=200;ChatMsg=API.messages.getHistory({\"chat_id\":ChatId,\"count\":UR,\"rev\":0});};" - "var FMsgs = ChatMsg.items@.fwd_messages;var Idx = 0;var Uids =[];while (Idx < FMsgs.length){" - "var Jdx = 0;var CFMsgs = parseInt(FMsgs[Idx].length);while (Jdx < CFMsgs){" - "Uids.unshift(FMsgs[Idx][Jdx].user_id);Jdx = Jdx + 1;};Idx = Idx + 1;};" - "var FUsers = API.users.get({\"user_ids\": Uids, \"name_case\":\"gen\"});" - "var MsgUsers=API.users.get({\"user_ids\":ChatMsg.items@.user_id,\"fields\":\"id,first_name,last_name\"});"; - } - - wszQuery += "return {\"info\":Info,\"users\":ChatUsers"; - - if (!cc->m_bHistoryRead) - wszQuery += ",\"msgs\":ChatMsg,\"fwd_users\":FUsers,\"msgs_users\":MsgUsers"; - - wszQuery +="};"; - - debugLogA("CVkProto::RetrieveChantInfo(%d)", cc->m_chatid); - if (!IsOnline()) - return; - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveChatInfo) - << CHAR_PARAM("code", wszQuery))->pUserInfo = cc; + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.RetrieveChatInfo", true, &CVkProto::OnReceiveChatInfo) + << INT_PARAM("chatid", cc->m_chatid) + << INT_PARAM("func_v", cc->m_bHistoryRead ? 1 : 2) + )->pUserInfo = cc; } void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) @@ -569,18 +548,13 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) case IDM_DESTROY: if (IDYES == MessageBoxW(NULL, TranslateT("This chat is going to be destroyed forever with all its contents. This action cannot be undone. Are you sure?"), - TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION)) - { - CMStringA code; - code.Format("API.messages.removeChatUser({\"chat_id\":%d, \"user_id\":%d});" - "var Hist = API.messages.getHistory({\"chat_id\":%d, \"count\":200});" - "var countMsg = Hist.count;var itemsMsg = Hist.items@.id; " - "while (countMsg > 0) { API.messages.delete({\"message_ids\":itemsMsg});" - "Hist=API.messages.getHistory({\"chat_id\":%d, \"count\":200});" - "countMsg = Hist.count;itemsMsg = Hist.items@.id;}; return 1;", cc->m_chatid, m_myUserId, cc->m_chatid, cc->m_chatid); - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnChatDestroy) - << CHAR_PARAM("code", code))->pUserInfo = cc; - } + TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION) + ) + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.DestroyChat", true, &CVkProto::OnChatDestroy) + << INT_PARAM("chatid", cc->m_chatid) + << INT_PARAM("userid", m_myUserId) + )->pUserInfo = cc; + break; } } @@ -703,14 +677,9 @@ INT_PTR __cdecl CVkProto::SvcDestroyKickChat(WPARAM hContact, LPARAM) if (chat_id == VK_INVALID_USER) return 1; - CMStringA code; - code.Format("var Hist = API.messages.getHistory({\"chat_id\":%d, \"count\":200});" - "var countMsg = Hist.count;var itemsMsg = Hist.items@.id; " - "while (countMsg > 0) { API.messages.delete({\"message_ids\":itemsMsg});" - "Hist=API.messages.getHistory({\"chat_id\":%d, \"count\":200});" - "countMsg = Hist.count;itemsMsg = Hist.items@.id;}; return 1;", chat_id, chat_id); - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveSmth) - << CHAR_PARAM("code", code)); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.DestroyKickChat", true, &CVkProto::OnReceiveSmth) + << INT_PARAM("chatid", chat_id) + ); db_delete_contact(hContact); diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 44dc556477..1f1e496950 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -713,7 +713,8 @@ void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime) m_vkOptions.bNotificationFilterInvites ? L",\"groupinvates\":API.groups.getInvites({\"extended\":1})};" : L"};"); Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveUnreadNotifications) - << WCHAR_PARAM("code", code) ); + << WCHAR_PARAM("code", code) + ); setDword("LastNotificationsReqTime", (DWORD)time(NULL)); } diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp index fd27cc8104..4f71591353 100644 --- a/protocols/VKontakte/src/vk_history.cpp +++ b/protocols/VKontakte/src/vk_history.cpp @@ -123,20 +123,15 @@ void CVkProto::GetServerHistory(MCONTACT hContact, int iOffset, int iCount, int if (VK_INVALID_USER == userID || userID == VK_FEED_USER) return; - CMStringA code(FORMAT, "var iOffset=%d;var iReqCount=%d;var userID=%d;var iTime=%d;var lastMid=%d;" - "var Hist=API.messages.getHistory({\"user_id\":userID,\"count\":iReqCount,\"offset\":iOffset});" - "var ext=Hist.items.length;var index=0;" - "while(ext!=0){if(Hist.items[index].date>iTime){if(Hist.items[index].id>lastMid)" - "{index=index+1;ext=ext-1;}else ext=0;}else ext=0;};" - "var ret=Hist.items.slice(0,index);" - "var FMsgs=ret@.fwd_messages;var Idx=0;var Uids=[];while(IdxpUserInfo = new CVkSendMsgParam(hContact, iLastMsgId, iOffset); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.GetServerHistory", true, &CVkProto::OnReceiveHistoryMessages, AsyncHttpRequest::rpLow) + << INT_PARAM("reqcount", iCount) + << INT_PARAM("offset", iOffset) + << INT_PARAM("userid", userID) + << INT_PARAM("time", iTime) + << INT_PARAM("lastmid", iLastMsgId) + << INT_PARAM("once", (int)once) + )->pUserInfo = new CVkSendMsgParam(hContact, iLastMsgId, iOffset); + } void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg) diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index 98b1a1076a..220c4d98b5 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -198,21 +198,9 @@ void CVkProto::RetrieveMessagesByIds(const CMStringA &mids) if (!IsOnline() || mids.IsEmpty()) return; - CMStringA code(FORMAT, "var Mids=\"%s\";" - "var Msgs=API.messages.getById({\"message_ids\":Mids});" - "var FMsgs=Msgs.items@.fwd_messages;" - "var Idx=0;var Uids=[];" - "while(IdxCntLmt){Cnt=CntLmt;}" - "if(Cnt==0){API.audio.setBroadcast();}" - "else{var i=0;var j=0;var Track=\" \";" - "while(iCntLmt){Cnt=CntLmt;}" - "if(Cnt==0){Track=\"♫ \"+StatusMsg;API.status.set({\"text\":Track});}" - "else{var i=0;var j=-1;" - "while(i0){" - "US=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});" - "var index=US.length;while(index>0){" - "index=index-1;if(US[index].online!=0){res.push(US[index]);};};" - "t=t-1;if(res.length>0)t=0;};" - "return{\"freeoffline\":1,\"norepeat\":%d,\"usercount\":res.length,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); - else - codeformat += CMStringW("var res=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});" - "return{\"freeoffline\":0,\"norepeat\":%d,\"usercount\":res.length,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); - code.AppendFormat(codeformat, userIDs, CMStringW(bFreeOffline ? "online,status" : fieldsName), (int)bRepeat); + Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.RetrieveUsersInfo", true, &CVkProto::OnReceiveUserInfo) + << CHAR_PARAM("userids", userIDs) + << CHAR_PARAM("fields", (bFreeOffline ? "online,status" : fieldsName)) + << INT_PARAM("norepeat", (int)bRepeat) + << INT_PARAM("setonline", (int)m_bNeedSendOnline) + << INT_PARAM("func_v", (bFreeOffline && !m_vkOptions.bLoadFullCList) ? 1 : 2) + ); - Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.json", true, &CVkProto::OnReceiveUserInfo) - << WCHAR_PARAM("code", code)); } void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) -- cgit v1.2.3