From c17216f6a79994adc290a93846c25c4713754d3e Mon Sep 17 00:00:00 2001 From: ElzorFox Date: Fri, 19 Apr 2024 12:50:35 +0500 Subject: =?UTF-8?q?VKontakte:=20db=5Fevent=5Fdelivered=20support=20fix=20s?= =?UTF-8?q?erver=20id=20for=20groupchat=20message=20code=20optimization=20?= =?UTF-8?q?and=20clean=20add=20=E2=80=98reload=20messages=E2=80=99=20menu?= =?UTF-8?q?=20item=20in=20NS=20context=20menu=20version=20bump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/VKontakte/src/misc.cpp | 3 ++- protocols/VKontakte/src/resource.h | 3 ++- protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_chats.cpp | 20 --------------- protocols/VKontakte/src/vk_files.cpp | 12 ++++----- protocols/VKontakte/src/vk_messages.cpp | 45 +++++++++++++++++++++++---------- protocols/VKontakte/src/vk_proto.cpp | 41 +++++++++++++++++++++++------- protocols/VKontakte/src/vk_proto.h | 4 +-- 8 files changed, 77 insertions(+), 53 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 88c3fdde0e..e568ea9c04 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -63,7 +63,8 @@ static IconItem iconList[] = { LPGEN("Status icon"), "status", IDI_STATUS }, { LPGEN("Wall message icon"), "wall", IDI_WALL }, { LPGEN("Mark messages as read icon"), "markread", IDI_MARKMESSAGESASREAD }, - { LPGEN("Forward icon"), "forward", IDI_FORWARD } + { LPGEN("Forward icon"), "forward", IDI_FORWARD }, + { LPGEN("Reload messages icon"), "reload", IDI_RELOADMESSAGE } }; void InitIcons() diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index 3d2a2211d0..a846e8968d 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -27,6 +27,7 @@ #define IDD_CONTACTDELETE 123 #define IDD_VKUSERFORM 124 #define IDI_FORWARD 126 +#define IDI_RELOADMESSAGE 130 #define IDC_LOGIN 1001 #define IDC_PASSWORD 1002 #define IDC_URL 1003 @@ -142,7 +143,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 127 +#define _APS_NEXT_RESOURCE_VALUE 131 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1121 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index 28f3eb1c43..30c7a10457 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 16 -#define __BUILD_NUM 5 +#define __BUILD_NUM 6 #include diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index ce8af5ae93..13cf9f7b73 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -680,26 +680,6 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam) return 1; } -void CVkProto::OnSendChatMsg(MHttpResponse *reply, AsyncHttpRequest *pReq) -{ - debugLogA("CVkProto::OnSendChatMsg %d", reply->resultCode); - int iResult = ACKRESULT_FAILED; - if (reply->resultCode == 200) { - JSONNode jnRoot; - CheckJsonResponse(pReq, reply, jnRoot); - iResult = ACKRESULT_SUCCESS; - } - if (!pReq->pUserInfo) - return; - - CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo; - ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, iResult, (HANDLE)(fup)); - if (!pReq->bNeedsRestart || m_bTerminated) { - delete fup; - pReq->pUserInfo = nullptr; - } -} - ///////////////////////////////////////////////////////////////////////////////////////// LPTSTR CVkProto::ChangeChatTopic(CVkChatInfo *cc) diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index c742ec78cd..d5d13b5ba8 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -473,7 +473,7 @@ void CVkProto::OnReciveUploadFile(MHttpResponse *reply, AsyncHttpRequest *pReq) return; } - AsyncHttpRequest *pMsgReq; + AsyncHttpRequest *pMsgReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh); if (isChatRoom(fup->hContact)) { CVkChatInfo *cc = GetChatByContact(fup->hContact); @@ -482,7 +482,6 @@ void CVkProto::OnReciveUploadFile(MHttpResponse *reply, AsyncHttpRequest *pReq) return; } - pMsgReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg, AsyncHttpRequest::rpHigh); pMsgReq << INT_PARAM("chat_id", cc->m_iChatId); pMsgReq->pUserInfo = pReq->pUserInfo; @@ -494,15 +493,16 @@ void CVkProto::OnReciveUploadFile(MHttpResponse *reply, AsyncHttpRequest *pReq) return; } - pMsgReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh); pMsgReq << INT_PARAM("peer_id", iUserId); pMsgReq->pUserInfo = new CVkSendMsgParam(fup->hContact, fup); } ULONG uMsgId = ::InterlockedIncrement(&m_iMsgId); - pMsgReq << WCHAR_PARAM("message", fup->wszDesc) << WCHAR_PARAM("attachment", Attachment); - pMsgReq << INT_PARAM("random_id", ((long)time(0)) * 100 + uMsgId % 100); - pMsgReq->AddHeader("Content-Type", "application/x-www-form-urlencoded"); + pMsgReq + << WCHAR_PARAM("message", fup->wszDesc) + << WCHAR_PARAM("attachment", Attachment) + << INT_PARAM("random_id", ((long)time(0)) * 100 + uMsgId % 100); + pMsgReq->AddHeader("Content-Type", "application/x-www-form-urlencoded"); Push(pMsgReq); } \ No newline at end of file diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index b77cc65629..5ce9ad0b1e 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -84,8 +84,14 @@ int CVkProto::ForwardMsg(MCONTACT hContact, std::vector& vForvardEvents, } ULONG uMsgId = ::InterlockedIncrement(&m_iMsgId); - AsyncHttpRequest* pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, - bIsChat ? &CVkProto::OnSendChatMsg : &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh); + AsyncHttpRequest* pReq = new AsyncHttpRequest( + this, + REQUEST_POST, + "/method/messages.send.json", + true, + &CVkProto::OnSendMessage, + AsyncHttpRequest::rpHigh + ); pReq << INT_PARAM(bIsChat ? "chat_id" : "peer_id", iUserId) @@ -107,12 +113,10 @@ int CVkProto::ForwardMsg(MCONTACT hContact, std::vector& vForvardEvents, } } - if (!bIsChat) - pReq->pUserInfo = new CVkSendMsgParam(hContact, uMsgId); - + pReq->pUserInfo = new CVkSendMsgParam(hContact, uMsgId); Push(pReq); - if (!m_vkOptions.bServerDelivery && !bIsChat) + if (!m_vkOptions.bServerDelivery) ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)uMsgId); if (vForvardEvents.size() > VK_MAX_FORWARD_MESSAGES) { @@ -145,9 +149,19 @@ int CVkProto::SendMsg(MCONTACT hContact, MEVENT hReplyEvent, const char *szMsg) ptrA pszRetMsg(GetStickerId(szMsg, StickerId)); ULONG uMsgId = ::InterlockedIncrement(&m_iMsgId); - AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, - bIsChat ? &CVkProto::OnSendChatMsg : &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh); - pReq << INT_PARAM(bIsChat ? "chat_id" : "peer_id", iUserId) << INT_PARAM("random_id", ((long)time(0)) * 100 + uMsgId % 100); + AsyncHttpRequest *pReq = new AsyncHttpRequest( + this, + REQUEST_POST, + "/method/messages.send.json", + true, + &CVkProto::OnSendMessage, + AsyncHttpRequest::rpHigh + ); + + pReq + << INT_PARAM(bIsChat ? "chat_id" : "peer_id", iUserId) + << INT_PARAM("random_id", ((long)time(0)) * 100 + uMsgId % 100); + pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -170,12 +184,11 @@ int CVkProto::SendMsg(MCONTACT hContact, MEVENT hReplyEvent, const char *szMsg) } } - if (!bIsChat) - pReq->pUserInfo = new CVkSendMsgParam(hContact, uMsgId); - + + pReq->pUserInfo = new CVkSendMsgParam(hContact, uMsgId); Push(pReq); - if (!m_vkOptions.bServerDelivery && !bIsChat) + if (!m_vkOptions.bServerDelivery) ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)uMsgId); if (!IsEmpty(pszRetMsg)) @@ -237,6 +250,12 @@ void CVkProto::OnSendMessage(MHttpResponse *reply, AsyncHttpRequest *pReq) } else if (m_vkOptions.bServerDelivery) ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, iResult, (HANDLE)(param->iMsgID), (LPARAM)szMid); + + + MEVENT hDbEvent; + if ((iResult == ACKRESULT_SUCCESS) && (hDbEvent = db_event_getById(m_szModuleName, szMid))) + db_event_delivered(param->hContact, hDbEvent); + if (!pReq->bNeedsRestart || m_bTerminated) { delete param; diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index b1559c40ae..11e8c59015 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -222,6 +222,11 @@ void CVkProto::InitMenus() mi.position = NS_PROTO_MENU_POS + NSMI_FORWARD; mi.name.a = LPGEN("Forward"); m_hNewStoryMenuItems[NSMI_FORWARD] = Menu_AddNewStoryMenuItem(&mi, NSMI_FORWARD); + + mi.hIcolibItem = g_plugin.getIconHandle(IDI_RELOADMESSAGE); + mi.position = NS_PROTO_MENU_POS + NSMI_RELOADMESSAGE; + mi.name.a = LPGEN("Reload messages"); + m_hNewStoryMenuItems[NSMI_RELOADMESSAGE] = Menu_AddNewStoryMenuItem(&mi, NSMI_RELOADMESSAGE); }; //Contact Menu Services @@ -419,6 +424,7 @@ int CVkProto::OnPrebuildNSMenu(WPARAM hContact, LPARAM lParam) { auto &dbei = *(DB::EventInfo *)lParam; Menu_ShowItem(m_hNewStoryMenuItems[NSMI_FORWARD], hContact != 0 && dbei); + Menu_ShowItem(m_hNewStoryMenuItems[NSMI_RELOADMESSAGE], Proto_IsProtoOnContact(hContact, m_szModuleName) && hContact != 0 && dbei); return 0; } @@ -428,13 +434,18 @@ INT_PTR CVkProto::SvcNSExecMenu(WPARAM iCommand, LPARAM pHandle) if (hCurrentEvent == -1) return 1; + std::vector vIds = NS_GetSelection(HANDLE(pHandle)); + if (vIds.empty()) + return 1; + + if (!vIds.size()) + vIds.push_back(hCurrentEvent); + + std::sort(vIds.begin(), vIds.end()); + switch (iCommand) { case NSMI_FORWARD: { - std::vector vIds = NS_GetSelection(HANDLE(pHandle)); - if (vIds.empty()) - break; - wchar_t wszMsg[2048] = L""; if (auto *pDlg = NS_GetSrmm((HANDLE)pHandle)) GetWindowText(pDlg->GetInput(), wszMsg, 2048); @@ -451,17 +462,29 @@ INT_PTR CVkProto::SvcNSExecMenu(WPARAM iCommand, LPARAM pHandle) if (!dlg.DoModal()) break; - if (!vIds.size()) - vIds.push_back(hCurrentEvent); - - std::sort(vIds.begin(), vIds.end()); - T2Utf pszMsg(dlg.wszMessage.c_str()); for (auto &hContact : dlg.lContacts) ForwardMsg((UINT_PTR)hContact, vIds, pszMsg); } break; + case NSMI_RELOADMESSAGE: + { + CMStringA szIds; + for (auto& mEvnt : vIds) { + DB::EventInfo dbei(mEvnt); + if (!dbei || dbei.eventType != EVENTTYPE_MESSAGE) + continue; + + if (!szIds.IsEmpty()) + szIds.AppendChar(','); + szIds += dbei.szId; + } + + if (!szIds.IsEmpty()) + RetrieveMessagesByIds(szIds); + } + break; } return 0; } diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 901408c1b9..359bb01f74 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -195,6 +195,7 @@ private: enum NewStoryMenuIndexes { NSMI_FORWARD, + NSMI_RELOADMESSAGE, NSMI_COUNT }; @@ -430,8 +431,7 @@ private: void AppendChatConversationMessage(VKUserID_t iChatId, const JSONNode& jnMsg, const JSONNode& jnFUsers, bool bIsHistory); void AppendChatMessage(CVkChatInfo* vkChatInfo, VKMessageID_t iMessageId, VKMessageID_t iReplyMsgId, VKUserID_t iUserId, time_t tMsgTime, LPCWSTR pwszBody, bool bIsHistory, bool bIsRead, bool bIsAction = false); void RetrieveChatInfo(CVkChatInfo*); - void OnReceiveChatInfo(MHttpResponse*, AsyncHttpRequest*); - void OnSendChatMsg(MHttpResponse*, AsyncHttpRequest*); + void OnReceiveChatInfo(MHttpResponse*, AsyncHttpRequest*); void OnChatLeave(MHttpResponse*, AsyncHttpRequest *); void OnChatDestroy(MHttpResponse*, AsyncHttpRequest*); int __cdecl OnChatEvent(WPARAM, LPARAM); -- cgit v1.2.3