diff options
-rw-r--r-- | protocols/VKontakte/src/vk_chats.cpp | 17 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_messages.cpp | 35 |
2 files changed, 26 insertions, 26 deletions
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 5a5e396721..0287809189 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -493,17 +493,13 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam) switch (gch->pDest->iType) {
case GC_USER_MESSAGE:
if (IsOnline() && mir_tstrlen(gch->ptszText) > 0) {
- TCHAR *buf = NEWTSTR_ALLOCA(gch->ptszText);
- rtrimt(buf);
- UnEscapeChatTags(buf);
- AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg, AsyncHttpRequest::rpHigh)
- << INT_PARAM("chat_id", cc->m_chatid)
- << CHAR_PARAM("message", T2Utf(buf))
- << VER_API;
- pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
- Push(pReq);
+ ptrT ptszBuf(mir_tstrdup(gch->ptszText));
+ rtrimt(ptszBuf);
+ UnEscapeChatTags(ptszBuf);
+ SendMsg(cc->m_hContact, 0, T2Utf(ptszBuf));
}
break;
+
case GC_USER_PRIVMESS:
{
MCONTACT hContact = FindUser(_ttoi(gch->ptszUID));
@@ -925,7 +921,6 @@ void CVkProto::ChatContactTypingThread(void * p) StopChatContactTyping(iChatId, iUserId);
}
-
void CVkProto::StopChatContactTyping(int iChatId, int iUserId)
{
debugLogA("CVkProto::StopChatContactTyping %d %d", iChatId, iUserId);
@@ -938,7 +933,7 @@ void CVkProto::StopChatContactTyping(int iChatId, int iUserId) return;
CVkChatUser* cu = cc->GetUserById(iUserId);
- if (cu == NULL)
+ if (cu == NULL)
return;
mir_cslock lck(m_csChatTyping);
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index cca8ad02d1..aed86581df 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -42,38 +42,43 @@ int CVkProto::SendMsg(MCONTACT hContact, int, const char *szMsg) debugLogA("CVkProto::SendMsg");
if (!IsOnline())
return 0;
- LONG userID = getDword(hContact, "ID", -1);
- if (userID == -1 || userID == VK_FEED_USER) {
+
+ bool bIsChat = isChatRoom(hContact);
+ LONG iUserID = getDword(hContact, bIsChat ? "vk_chat_id" : "ID" , -1);
+
+ if (iUserID == -1 || iUserID == VK_FEED_USER) {
ForkThread(&CVkProto::SendMsgAck, new CVkSendMsgParam(hContact));
return 0;
}
int StickerId = 0;
- ptrA retMsg(GetStickerId(szMsg, StickerId));
+ ptrA pszRetMsg(GetStickerId(szMsg, StickerId));
- ULONG msgId = ::InterlockedIncrement(&m_msgId);
- AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh)
- << INT_PARAM("user_id", userID)
- << INT_PARAM("guid", ((LONG) time(NULL)) * 100 + msgId % 100)
+ ULONG uMsgId = ::InterlockedIncrement(&m_msgId);
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, bIsChat? &CVkProto::OnSendChatMsg : &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh)
+ << INT_PARAM(bIsChat ? "chat_id" : "user_id", iUserID)
+ << INT_PARAM("guid", ((LONG) time(NULL)) * 100 + uMsgId % 100)
<< VER_API;
+ pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
- if (StickerId != 0)
+ if (StickerId)
pReq << INT_PARAM("sticker_id", StickerId);
else
pReq << CHAR_PARAM("message", szMsg);
- pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
- pReq->pUserInfo = new CVkSendMsgParam(hContact, msgId);
+ if (!bIsChat)
+ pReq->pUserInfo = new CVkSendMsgParam(hContact, uMsgId);
+
Push(pReq);
- if (!m_bServerDelivery)
- ForkThread(&CVkProto::SendMsgAck, new CVkSendMsgParam(hContact, msgId));
+ if (!m_bServerDelivery && !bIsChat)
+ ForkThread(&CVkProto::SendMsgAck, new CVkSendMsgParam(hContact, uMsgId));
- if (!IsEmpty(retMsg)) {
+ if (!IsEmpty(pszRetMsg)) {
Sleep(330);
- SendMsg(hContact, 0, retMsg);
+ SendMsg(hContact, 0, pszRetMsg);
}
- return msgId;
+ return uMsgId;
}
void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
|