summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src/vk_messages.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/VKontakte/src/vk_messages.cpp')
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp109
1 files changed, 52 insertions, 57 deletions
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp
index 1c24dc30e5..3020907d3a 100644
--- a/protocols/VKontakte/src/vk_messages.cpp
+++ b/protocols/VKontakte/src/vk_messages.cpp
@@ -86,10 +86,10 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
debugLogA("CVkProto::OnSendMessage %d", reply->resultCode);
if (reply->resultCode == 200) {
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse != NULL) {
- UINT mid = json_as_int(pResponse);
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse.isnull()) {
+ UINT mid = jnResponse.as_int();
if (param->iMsgID != -1)
m_sendIds.insert((HANDLE)mid);
if (mid > getDword(param->hContact, "lastmsgid", 0))
@@ -180,49 +180,49 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
CMStringA mids;
- int numMessages = json_as_int(json_get(pResponse, "count"));
- JSONNODE *pMsgs = json_get(pResponse, "items");
+ int numMessages = jnResponse["count"].as_int();
+ const JSONNode &jnMsgs = jnResponse["items"];
debugLogA("CVkProto::OnReceiveMessages numMessages = %d", numMessages);
- for (int i = 0; i < numMessages; i++) {
- JSONNODE *pMsg = json_at(pMsgs, i);
- if (pMsg == NULL) {
+ for (auto it = jnMsgs.begin(); it != jnMsgs.end(); ++it) {
+ const JSONNode &jnMsg = (*it);
+ if (!jnMsg) {
debugLogA("CVkProto::OnReceiveMessages pMsg == NULL");
break;
}
- UINT mid = json_as_int(json_get(pMsg, "id"));
- ptrT ptszBody(json_as_string(json_get(pMsg, "body")));
- int datetime = json_as_int(json_get(pMsg, "date"));
- int isOut = json_as_int(json_get(pMsg, "out"));
- int isRead = json_as_int(json_get(pMsg, "read_state"));
- int uid = json_as_int(json_get(pMsg, "user_id"));
-
- JSONNODE *pFwdMessages = json_get(pMsg, "fwd_messages");
- if (pFwdMessages != NULL){
- CMString tszFwdMessages = GetFwdMessages(pFwdMessages, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+ UINT mid = jnMsg["id"].as_int();
+ CMString tszBody(jnMsg["body"].as_mstring());
+ int datetime = jnMsg["date"].as_int();
+ int isOut = jnMsg["out"].as_int();
+ int isRead = jnMsg["read_state"].as_int();
+ int uid = jnMsg["user_id"].as_int();
+
+ const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
+ if (!jnFwdMessages.isnull()){
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszFwdMessages);
+ tszBody += tszFwdMessages;
}
- JSONNODE *pAttachments = json_get(pMsg, "attachments");
- if (pAttachments != NULL){
- CMString tszAttachmentDescr = GetAttachmentDescr(pAttachments, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+ const JSONNode &jnAttachments = jnMsg["attachments"];
+ if (!jnAttachments.isnull()){
+ CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszAttachmentDescr);
+ tszBody += tszAttachmentDescr;
}
MCONTACT hContact = NULL;
- int chat_id = json_as_int(json_get(pMsg, "chat_id"));
+ int chat_id = jnMsg["chat_id"].as_int();
if (chat_id == 0)
hContact = FindUser(uid, true);
@@ -236,12 +236,12 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (chat_id != 0) {
debugLogA("CVkProto::OnReceiveMessages chat_id != 0");
- CMString action_chat = json_as_CMString(json_get(pMsg, "action"));
- int action_mid = _ttoi(json_as_CMString(json_get(pMsg, "action_mid")));
+ CMString action_chat = jnMsg["action"].as_mstring();
+ int action_mid = _ttoi(jnMsg["action_mid"].as_mstring().GetBuffer());
if ((action_chat == "chat_kick_user") && (action_mid == m_myUserId))
- KickFromChat(chat_id, uid, pMsg);
+ KickFromChat(chat_id, uid, jnMsg);
else
- AppendChatMessage(chat_id, pMsg, false);
+ AppendChatMessage(chat_id, jnMsg, false);
continue;
}
@@ -253,7 +253,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
else if (m_bUserForceOnlineOnActivity)
SetInvisible(hContact);
- T2Utf pszBody(ptszBody);
+ T2Utf pszBody(tszBody.GetBuffer());
recv.timestamp = m_bUseLocalTime ? time(NULL) : datetime;
recv.szMessage = pszBody;
recv.lParam = isOut;
@@ -261,7 +261,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
recv.cbCustomDataSize = (int)mir_strlen(szMid);
Sleep(100);
- debugLogA("CVkProto::OnReceiveMessages i = %d, mid = %d, datetime = %d, isOut = %d, isRead = %d, uid = %d", i, mid, datetime, isOut, isRead, uid);
+ debugLogA("CVkProto::OnReceiveMessages mid = %d, datetime = %d, isOut = %d, isRead = %d, uid = %d", mid, datetime, isOut, isRead, uid);
if (!CheckMid(m_sendIds, mid)) {
debugLogA("CVkProto::OnReceiveMessages ProtoChainRecvMsg");
@@ -283,37 +283,32 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
-
- int numDlgs = json_as_int(json_get(pResponse, "count"));
- JSONNODE *pDlgs = json_get(pResponse, "items");
-
- if (pDlgs == NULL)
+
+ const JSONNode &jnDlgs = jnResponse["items"];
+ if (!jnDlgs)
return;
- for (int i = 0; i < numDlgs; i++) {
- JSONNODE *pDlg = json_at(pDlgs, i);
- if (pDlg == NULL)
+ for (auto it = jnDlgs.begin(); it != jnDlgs.end(); ++it) {
+ if (!(*it))
break;
-
- int numUnread = json_as_int(json_get(pDlg, "unread"));
-
- pDlg = json_get(pDlg, "message");
- if (pDlg == NULL)
+ int numUnread = (*it)["unread"].as_int();
+ const JSONNode &jnDlg = (*it)["message"];
+ if (jnDlg == NULL)
break;
- int chatid = json_as_int(json_get(pDlg, "chat_id"));
+ int chatid = jnDlg["chat_id"].as_int();
if (chatid != 0) {
debugLogA("CVkProto::OnReceiveDlgs chatid = %d", chatid);
if (m_chats.find((CVkChatInfo*)&chatid) == NULL)
- AppendChat(chatid, pDlg);
+ AppendChat(chatid, jnDlg);
}
else if (m_iSyncHistoryMetod) {
- int mid = json_as_int(json_get(pDlg, "id"));
- int uid = json_as_int(json_get(pDlg, "user_id"));
+ int mid = jnDlg["id"].as_int();
+ int uid = jnDlg["user_id"].as_int();
MCONTACT hContact = FindUser(uid, true);
if (getDword(hContact, "lastmsgid", -1) == -1 && numUnread)
@@ -325,7 +320,7 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
MarkMessagesRead(hContact);
}
else if (numUnread) {
- int uid = json_as_int(json_get(pDlg, "user_id"));
+ int uid = jnDlg["user_id"].as_int();
MCONTACT hContact = FindUser(uid, true);
GetServerHistory(hContact, 0, numUnread, 0, 0, true);