summaryrefslogtreecommitdiff
path: root/protocols/VKontakte
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2015-08-27 09:11:19 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2015-08-27 09:11:19 +0000
commit427359cbf083f5c5f709d68fd30bd08392ae57ca (patch)
treef4b2b936268794ec2681f08ae09c0f84244c019c /protocols/VKontakte
parent4d8a113f8a325b8d2ff6a008d3a8a5b8e70e2e81 (diff)
VKontakte:
fix unneeded ‘mark as read’ requests fix nick in forwarded messages code cleaning version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@15040 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r--protocols/VKontakte/src/misc.cpp58
-rw-r--r--protocols/VKontakte/src/version.h2
-rw-r--r--protocols/VKontakte/src/vk_chats.cpp26
-rw-r--r--protocols/VKontakte/src/vk_feed.cpp18
-rw-r--r--protocols/VKontakte/src/vk_files.cpp5
-rw-r--r--protocols/VKontakte/src/vk_history.cpp16
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp32
-rw-r--r--protocols/VKontakte/src/vk_pollserver.cpp3
-rw-r--r--protocols/VKontakte/src/vk_proto.h8
-rw-r--r--protocols/VKontakte/src/vk_search.cpp6
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp20
-rw-r--r--protocols/VKontakte/src/vk_wallpost.cpp3
12 files changed, 109 insertions, 88 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index 6bd1d36986..bb57d1b3ee 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -361,8 +361,7 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, const JSONNode &jnNode)
pReq->m_iRetry--;
}
else {
- CMString msg;
- msg.AppendFormat(TranslateT("Error %d. Data will not be sent or received."), iErrorCode);
+ CMString msg(FORMAT, TranslateT("Error %d. Data will not be sent or received."), iErrorCode);
MsgPopup(NULL, msg, TranslateT("Error"), true);
debugLogA("CVkProto::CheckJsonResult SendError");
}
@@ -978,8 +977,7 @@ CMString CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMString tszArtist(jnAudio["artist"].as_mstring());
CMString tszTitle(jnAudio["title"].as_mstring());
CMString tszUrl(jnAudio["url"].as_mstring());
- CMString tszAudio;
- tszAudio.AppendFormat(_T("%s - %s"), tszArtist, tszTitle);
+ CMString tszAudio(FORMAT, _T("%s - %s"), tszArtist, tszTitle);
int iParamPos = tszUrl.Find(_T("?"));
if (m_bShortenLinksForAudio && iParamPos != -1)
@@ -997,8 +995,7 @@ CMString CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMString tszTitle(jnVideo["title"].as_mstring());
int vid = jnVideo["id"].as_int();
int ownerID = jnVideo["owner_id"].as_int();
- CMString tszUrl;
- tszUrl.AppendFormat(_T("http://vk.com/video%d_%d"), ownerID, vid);
+ CMString tszUrl(FORMAT, _T("http://vk.com/video%d_%d"), ownerID, vid);
res.AppendFormat(_T("%s: %s"),
SetBBCString(TranslateT("Video"), iBBC, vkbbcB),
SetBBCString(tszTitle, iBBC, vkbbcUrl, tszUrl));
@@ -1022,8 +1019,7 @@ CMString CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMString tszText(jnWall["text"].as_mstring());
int id = jnWall["id"].as_int();
int fromID = jnWall["from_id"].as_int();
- CMString tszUrl;
- tszUrl.AppendFormat(_T("http://vk.com/wall%d_%d"), fromID, id);
+ CMString tszUrl(FORMAT, _T("http://vk.com/wall%d_%d"), fromID, id);
res.AppendFormat(_T("%s: %s"),
SetBBCString(TranslateT("Wall post"), iBBC, vkbbcUrl, tszUrl),
tszText.IsEmpty() ? _T(" ") : tszText);
@@ -1109,7 +1105,7 @@ CMString CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
return res;
}
-CMString CVkProto::GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC)
+CMString CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, BBCSupport iBBC)
{
CMString res;
debugLogA("CVkProto::GetFwdMessages");
@@ -1118,19 +1114,39 @@ CMString CVkProto::GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC)
return res;
}
+ OBJLIST<CVkUserInfo> vkUsers(2, NumericKeySortT);
+
+ for (auto it = jnFUsers.begin(); it != jnFUsers.end(); ++it) {
+ const JSONNode &jnUser = (*it);
+
+ int iUserId = jnUser["id"].as_int();
+ CMString tszNick(FORMAT, _T("%s %s"), jnUser["first_name"].as_mstring(), jnUser["last_name"].as_mstring());
+ CMString tszLink(FORMAT, _T("https://vk.com/id%d"), iUserId);
+
+ CVkUserInfo * vkUser = new CVkUserInfo(jnUser["id"].as_int(), false, tszNick, tszLink, FindUser(iUserId));
+ vkUsers.insert(vkUser);
+ }
+
+
for (auto it = jnMessages.begin(); it != jnMessages.end(); ++it) {
const JSONNode &jnMsg = (*it);
- int uid = jnMsg["user_id"].as_int();
- MCONTACT hContact = FindUser(uid);
- CMString tszNick;
- if (hContact)
- tszNick = ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"));
- if (tszNick.IsEmpty())
- tszNick = TranslateT("(Unknown contact)");
+ UINT uid = jnMsg["user_id"].as_int();
+ CVkUserInfo * vkUser = vkUsers.find((CVkUserInfo *)&uid);
+ CMString tszNick, tszUrl;
- CMString tszUrl = _T("https://vk.com/id");
- tszUrl.AppendFormat(_T("%d"), uid);
+ if (vkUser) {
+ tszNick = vkUser->m_tszUserNick;
+ tszUrl = vkUser->m_tszLink;
+ }
+ else {
+ MCONTACT hContact = FindUser(uid);
+ if (hContact || uid == m_msgId)
+ tszNick = ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"));
+ else
+ tszNick = TranslateT("(Unknown contact)");
+ tszUrl.AppendFormat(_T("https://vk.com/id%d"), uid);
+ }
time_t datetime = (time_t)jnMsg["date"].as_int();
TCHAR ttime[64];
@@ -1142,7 +1158,7 @@ CMString CVkProto::GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC)
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
if (jnFwdMessages) {
- CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, iBBC == bbcNo ? iBBC : m_iBBCForAttachments);
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, iBBC == bbcNo ? iBBC : m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
tszBody += tszFwdMessages;
@@ -1157,9 +1173,8 @@ CMString CVkProto::GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC)
}
tszBody.Replace(_T("\n"), _T("\n\t"));
- CMString tszMes;
TCHAR tcSplit = m_bSplitFormatFwdMsg ? '\n' : ' ';
- tszMes.AppendFormat(_T("%s %s%c%s %s:\n\n%s\n"),
+ CMString tszMes(FORMAT, _T("%s %s%c%s %s:\n\n%s\n"),
SetBBCString(TranslateT("Message from"), iBBC, vkbbcB),
SetBBCString(tszNick, iBBC, vkbbcUrl, tszUrl),
tcSplit,
@@ -1172,6 +1187,7 @@ CMString CVkProto::GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC)
res += tszMes;
}
+ vkUsers.destroy();
return res;
}
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h
index 87a4090093..d3926c8e38 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 1
-#define __BUILD_NUM 12
+#define __BUILD_NUM 13
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp
index 7817a89f87..d4980914fc 100644
--- a/protocols/VKontakte/src/vk_chats.cpp
+++ b/protocols/VKontakte/src/vk_chats.cpp
@@ -99,20 +99,23 @@ CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg)
void CVkProto::RetrieveChatInfo(CVkChatInfo *cc)
{
- CMString tszQuery;
- tszQuery.AppendFormat(_T("var ChatId=%d;"), cc->m_chatid);
+ CMString tszQuery(FORMAT, _T("var ChatId=%d;"), cc->m_chatid);
tszQuery += _T("var Info=API.messages.getChat({\"chat_id\":ChatId});");
tszQuery += _T("var ChatUsers=API.messages.getChatUsers({\"chat_id\":ChatId,\"fields\":\"id,first_name,last_name\"});");
if (!cc->m_bHistoryRead) {
tszQuery += _T("var ChatMsg=API.messages.getHistory({\"chat_id\":ChatId,\"count\":20,\"rev\":0});");
+ tszQuery += _T("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\"});");
tszQuery += _T("var MsgUsers=API.users.get({\"user_ids\":ChatMsg.items@.user_id,\"fields\":\"id,first_name,last_name\"});");
}
tszQuery += _T("return {\"info\":Info,\"users\":ChatUsers");
if (!cc->m_bHistoryRead)
- tszQuery += _T(",\"msgs\":ChatMsg,\"msgs_users\":MsgUsers");
+ tszQuery += _T(",\"msgs\":ChatMsg,\"fwd_users\":FUsers,\"msgs_users\":MsgUsers");
tszQuery +=_T("};");
@@ -233,6 +236,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
}
const JSONNode &jnMsgs = jnResponse["msgs"];
+ const JSONNode &jnFUsers = jnResponse["fwd_users"];
if (jnMsgs) {
const JSONNode &jnItems = jnMsgs["items"];
@@ -242,7 +246,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (!jnMsg)
break;
- AppendChatMessage(cc->m_chatid, jnMsg, true);
+ AppendChatMessage(cc->m_chatid, jnMsg, jnFUsers, true);
}
cc->m_bHistoryRead = true;
}
@@ -275,7 +279,7 @@ void CVkProto::SetChatTitle(CVkChatInfo *cc, LPCTSTR tszTopic)
/////////////////////////////////////////////////////////////////////////////////////////
-void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
+void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, const JSONNode &jnFUsers, bool bIsHistory)
{
debugLogA("CVkProto::AppendChatMessage");
CVkChatInfo *cc = AppendChat(id, nullNode);
@@ -295,7 +299,7 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
if (jnFwdMessages) {
- CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, bbcNo);
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, bbcNo);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
tszBody += tszFwdMessages;
@@ -322,8 +326,7 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
if (tszActionMid.IsEmpty())
tszBody = TranslateT("kick user");
else {
- CMString tszUid;
- tszUid.AppendFormat(_T("%d"), uid);
+ CMString tszUid(FORMAT, _T("%d"), uid);
if (tszUid == tszActionMid) {
if (cc->m_bHistoryRead)
return;
@@ -349,8 +352,7 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
if (tszActionMid.IsEmpty())
tszBody = TranslateT("invite user");
else {
- CMString tszUid;
- tszUid.AppendFormat(_T("%d"), uid);
+ CMString tszUid(FORMAT, _T("%d"), uid);
if (tszUid == tszActionMid)
tszBody.AppendFormat(_T(" (https://vk.com/id%s) %s"), tszUid, TranslateT("returned to chat"));
else {
@@ -703,7 +705,7 @@ void CVkProto::LeaveChat(int chat_id, bool close_window, bool delete_chat)
m_chats.remove(cc);
}
-void CVkProto::KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg)
+void CVkProto::KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg, const JSONNode &jnFUsers)
{
debugLogA("CVkProto::KickFromChat (%d)", user_id);
@@ -728,7 +730,7 @@ void CVkProto::KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg)
msg += TranslateT("(Unknown contact)");
}
else
- AppendChatMessage(chat_id, jnMsg, false);
+ AppendChatMessage(chat_id, jnMsg, jnFUsers, false);
MsgPopup(hContact, msg, TranslateT("Chat"));
setByte(cc->m_hContact, "kicked", 1);
diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp
index abbd9a72bf..b9dee95b9f 100644
--- a/protocols/VKontakte/src/vk_feed.cpp
+++ b/protocols/VKontakte/src/vk_feed.cpp
@@ -78,7 +78,7 @@ CVkUserInfo* CVkProto::GetVkUserInfo(LONG iUserId, OBJLIST<CVkUserInfo> &vkUsers
if (vkUser == NULL) {
CMString tszNick = TranslateT("Unknown");
- CMString tszLink = _T("https://vk.com/");
+ CMString tszLink(_T("https://vk.com/"));
if (iUserId) {
tszLink += bIsGroup ? "club" : "id";
tszLink.AppendFormat(_T("%d"), bIsGroup ? -iUserId : iUserId);
@@ -379,16 +379,14 @@ CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentT
const JSONNode &jnPost = jnParent["post"];
if (jnPost) {
- CMString tszRepl;
- tszRepl.AppendFormat(_T("?reply=%d"), iId);
+ CMString tszRepl(FORMAT, _T("?reply=%d"), iId);
delete vkNotificationItem;
return GetVkParent(jnPost, vkPost, tszText, tszRepl);
}
const JSONNode &jnTopic = jnParent["topic"];
if (jnTopic) {
- CMString tszRepl;
- tszRepl.AppendFormat(_T("?reply=%d"), iId);
+ CMString tszRepl(FORMAT, _T("?reply=%d"), iId);
delete vkNotificationItem;
return GetVkParent(jnTopic, vkTopic, tszText, tszRepl);
}
@@ -450,8 +448,7 @@ CVKNewsItem* CVkProto::GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUser
return NULL;
LONG iGroupId = jnItem["id"].as_int();
- CMString tszId;
- tszId.AppendFormat(_T("%d,"), iGroupId);
+ CMString tszId(FORMAT, _T("%d,"), iGroupId);
CMString tszIds(ptrT(db_get_tsa(NULL, m_szModuleName, "InviteGroupIds")));
if (tszIds.Find(tszId, 0) != -1)
@@ -466,9 +463,9 @@ CVKNewsItem* CVkProto::GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUser
vkNotification->vkFeedbackType = vkFeedbackType;
vkNotification->vkParentType = vkParentType;
- CMString tszGroupName, tszGLink;
+ CMString tszGroupName;
CMString tszGName = jnItem["name"].as_mstring();
- tszGLink.AppendFormat(_T("https://vk.com/%s"), jnItem["screen_name"].as_mstring());
+ CMString tszGLink(FORMAT, _T("https://vk.com/%s"), jnItem["screen_name"].as_mstring());
tszGroupName = SetBBCString(tszGName, m_iBBCForNews, vkbbcUrl, tszGLink);
CMString tszUsers = SetBBCString(iUserId ? vkNotification->vkUser->m_tszUserNick : TranslateT("Unknown"), m_iBBCForNews, vkbbcUrl, iUserId ? vkNotification->vkUser->m_tszLink : _T("https://vk.com/"));
@@ -613,8 +610,7 @@ void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime)
if (time(NULL) - tLastNotificationsReqTime < 3 * 60)
return;
- CMString code;
- code.AppendFormat(_T("return{\"notifications\":API.notifications.get({\"count\": 100, \"start_time\":%d})%s"),
+ CMString code(FORMAT, _T("return{\"notifications\":API.notifications.get({\"count\": 100, \"start_time\":%d})%s"),
(LONG)(tLastNotificationsTime + 1),
m_bNotificationFilterInvites ? _T(",\"groupinvates\":API.groups.getInvites({\"extended\":1})};") : _T("};"));
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp
index 31f736a7be..0f1cf72577 100644
--- a/protocols/VKontakte/src/vk_files.cpp
+++ b/protocols/VKontakte/src/vk_files.cpp
@@ -46,10 +46,9 @@ CVkFileUploadParam::VKFileType CVkFileUploadParam::GetType()
TCHAR DRIVE[3], DIR[256], FNAME[256], EXT[256];
_tsplitpath(FileName, DRIVE, DIR, FNAME, EXT);
-
- CMStringA fn;
+
T2Utf pszFNAME(FNAME), pszEXT(EXT);
- fn.AppendFormat("%s%s", pszFNAME, pszEXT);
+ CMStringA fn(FORMAT, "%s%s", pszFNAME, pszEXT);
fname = mir_strdup(fn);
if (tlstrstr(img, EXT)) {
diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp
index b06784d39b..c7142ef726 100644
--- a/protocols/VKontakte/src/vk_history.cpp
+++ b/protocols/VKontakte/src/vk_history.cpp
@@ -126,14 +126,17 @@ void CVkProto::GetServerHistory(MCONTACT hContact, int iOffset, int iCount, int
if (-1 == userID || userID == VK_FEED_USER)
return;
- CMStringA code;
-
- code.AppendFormat("var iOffset=%d;var iReqCount=%d;var userID=%d;var iTime=%d;var lastMid=%d;"
+ 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 allCount=Hist.count;var ext=Hist.items.length;var index=0;"
+ "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); return{\"count\":index,\"datetime\":iTime,\"items\":ret,\"once\":%d,\"rcount\":iReqCount};",
+ "var ret=Hist.items.slice(0,index);"
+ "var FMsgs=ret@.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\"});"
+ "return{\"count\":index,\"datetime\":iTime,\"items\":ret,\"fwd_users\":FUsers,\"once\":%d,\"rcount\":iReqCount};",
iOffset, iCount, userID, iTime, iLastMsgId, (int)once);
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveHistoryMessages)
<< CHAR_PARAM("code", code)
@@ -177,6 +180,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
int iTime = jnResponse["datetime"].as_int();
const JSONNode &jnMsgs = jnResponse["items"];
+ const JSONNode &jnFUsers = jnResponse["fwd_users"];
int iLastMsgId = getDword(param->hContact, "lastmsgid", -1);
int count = 0;
@@ -199,7 +203,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
if (jnFwdMessages) {
- CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
tszBody += tszFwdMessages;
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp
index 1dbfd32435..39c1d07f23 100644
--- a/protocols/VKontakte/src/vk_messages.cpp
+++ b/protocols/VKontakte/src/vk_messages.cpp
@@ -153,7 +153,7 @@ void CVkProto::MarkMessagesRead(const CMStringA &mids)
void CVkProto::MarkMessagesRead(const MCONTACT hContact)
{
debugLogA("CVkProto::MarkMessagesRead (hContact)");
- if (!IsOnline())
+ if (!IsOnline() || !hContact)
return;
LONG userID = getDword(hContact, "ID", -1);
if (userID == -1 || userID == VK_FEED_USER)
@@ -170,8 +170,21 @@ void CVkProto::RetrieveMessagesByIds(const CMStringA &mids)
if (!IsOnline() || mids.IsEmpty())
return;
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getById.json", true, &CVkProto::OnReceiveMessages, AsyncHttpRequest::rpHigh)
- << CHAR_PARAM("message_ids", mids)
+ 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(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\"});"
+ "return{\"Msgs\":Msgs,\"fwd_users\":FUsers};",
+ mids
+ );
+
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveMessages, AsyncHttpRequest::rpHigh)
+ << CHAR_PARAM("code", code)
<< VER_API);
}
@@ -194,10 +207,13 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
if (!jnResponse)
return;
+ if (!jnResponse["Msgs"])
+ return;
CMStringA mids;
- int numMessages = jnResponse["count"].as_int();
- const JSONNode &jnMsgs = jnResponse["items"];
+ int numMessages = jnResponse["Msgs"]["count"].as_int();
+ const JSONNode &jnMsgs = jnResponse["Msgs"]["items"];
+ const JSONNode &jnFUsers = jnResponse["fwd_users"];
debugLogA("CVkProto::OnReceiveMessages numMessages = %d", numMessages);
@@ -217,7 +233,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
if (jnFwdMessages) {
- CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
tszBody += tszFwdMessages;
@@ -249,12 +265,12 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
CMString action_chat = jnMsg["action"].as_mstring();
int action_mid = _ttoi(jnMsg["action_mid"].as_mstring());
if ((action_chat == "chat_kick_user") && (action_mid == m_myUserId))
- KickFromChat(chat_id, uid, jnMsg);
+ KickFromChat(chat_id, uid, jnMsg, jnFUsers);
else {
MCONTACT chatContact = FindChat(chat_id);
if (chatContact && getBool(chatContact, "kicked", true))
db_unset(chatContact, m_szModuleName, "kicked");
- AppendChatMessage(chat_id, jnMsg, false);
+ AppendChatMessage(chat_id, jnMsg, jnFUsers, false);
}
continue;
}
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp
index 3faa43723c..4bcf807a4f 100644
--- a/protocols/VKontakte/src/vk_pollserver.cpp
+++ b/protocols/VKontakte/src/vk_pollserver.cpp
@@ -172,8 +172,7 @@ int CVkProto::PollServer()
debugLogA("CVkProto::PollServer (online)");
int iPollConnRetry = MAX_RETRIES;
NETLIBHTTPREQUEST *reply;
- CMStringA szReqUrl;
- szReqUrl.AppendFormat("https://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s&mode=%d", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken, 106);
+ CMStringA szReqUrl(FORMAT, "https://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s&mode=%d", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken, 106);
// see mode parametr description on https://vk.com/dev/using_longpoll (Russian version)
NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 38b7921016..e646312f2f 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PS_OPENBROADCAST "/OpenBroadcast"
#define PS_SETSTATUSMSG "/SetStatusMsg"
#define PS_WALLPOST "/WallPost"
-#define MAXHISTORYMIDSPERONE 200
+#define MAXHISTORYMIDSPERONE 175
#define MAX_RETRIES 10
struct CVkProto;
@@ -413,7 +413,7 @@ struct CVkProto : public PROTO<CVkProto>
CMString& ClearFormatNick(CMString& tszText);
CMString GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport iBBC = bbcNo);
- CMString GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC = bbcNo);
+ CMString GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, BBCSupport iBBC = bbcNo);
void SetInvisible(MCONTACT hContact);
@@ -643,7 +643,7 @@ private:
OBJLIST<CVkChatInfo> m_chats;
CVkChatInfo* AppendChat(int id, const JSONNode &jnNode);
void SetChatTitle(CVkChatInfo *cc, LPCTSTR tszTopic);
- void AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory);
+ void AppendChatMessage(int id, const JSONNode &jnMsg, const JSONNode &jnFUsers, bool bIsHistory);
void AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory, bool bIsAction = false);
void RetrieveChatInfo(CVkChatInfo*);
void OnReceiveChatInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -652,7 +652,7 @@ private:
void OnChatDestroy(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
int __cdecl OnChatEvent(WPARAM, LPARAM);
int __cdecl OnGcMenuHook(WPARAM, LPARAM);
- void KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg);
+ void KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg, const JSONNode &jnFUsers);
void LeaveChat(int chat_id, bool close_window = true, bool delete_chat = false);
INT_PTR __cdecl OnLeaveChat(WPARAM, LPARAM);
INT_PTR __cdecl OnJoinChat(WPARAM, LPARAM);
diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp
index a2fab4a335..cf8616d9d5 100644
--- a/protocols/VKontakte/src/vk_search.cpp
+++ b/protocols/VKontakte/src/vk_search.cpp
@@ -122,8 +122,7 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_TCHAR;
- CMString Id;
- Id.AppendFormat(_T("%d"), jnRecord["id"].as_int());
+ CMString Id(FORMAT, _T("%d"), jnRecord["id"].as_int());
CMString FirstName(jnRecord["first_name"].as_mstring());
CMString LastName(jnRecord["last_name"].as_mstring());
CMString Nick(jnRecord["nickname"].as_mstring());
@@ -186,8 +185,7 @@ void CVkProto::OnSearchByMail(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_TCHAR;
- CMString Id;
- Id.AppendFormat(_T("%d"), jnRecord["id"].as_int());
+ CMString Id(FORMAT, _T("%d"), jnRecord["id"].as_int());
CMString FirstName(jnRecord["first_name"].as_mstring());
CMString LastName(jnRecord["last_name"].as_mstring());
CMString Nick(jnRecord["nickname"].as_mstring());
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index 48e20824d6..e490908188 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -380,11 +380,8 @@ void CVkProto::RetrieveUserInfo(LONG userID)
if (userID == VK_FEED_USER || !IsOnline())
return;
- CMString userIDs, code;
- userIDs.AppendFormat(_T("%i"), userID);
-
- code.AppendFormat(_T("var userIDs=\"%s\";return{\"freeoffline\":0,\"users\":API.users.get({\"user_ids\":userIDs,\"fields\":\"%s\",\"name_case\":\"nom\"})};"),
- userIDs, CMString(fieldsName));
+ CMString code(FORMAT, _T("var userIDs=\"%i\";return{\"freeoffline\":0,\"users\":API.users.get({\"user_ids\":userIDs,\"fields\":\"%s\",\"name_case\":\"nom\"})};"),
+ userID, CMString(fieldsName));
Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.json", true, &CVkProto::OnReceiveUserInfo)
<< TCHAR_PARAM("code", code)
<< VER_API);
@@ -634,8 +631,7 @@ INT_PTR __cdecl CVkProto::SvcBanUser(WPARAM hContact, LPARAM)
if (!IsOnline() || userID == -1 || userID == VK_FEED_USER)
return 1;
- CMStringA code;
- code.AppendFormat("var userID=\"%d\";API.account.banUser({\"user_id\":userID});", userID);
+ CMStringA code(FORMAT, "var userID=\"%d\";API.account.banUser({\"user_id\":userID});", userID);
CMString tszVarWarning;
if (m_bReportAbuse) {
@@ -669,9 +665,7 @@ INT_PTR __cdecl CVkProto::SvcBanUser(WPARAM hContact, LPARAM)
code += "return 1;";
ptrT ptszNick(db_get_tsa(hContact, m_szModuleName, "Nick"));
- CMString ptszMsg;
-
- ptszMsg.AppendFormat(TranslateT("Are you sure to ban %s? %s%sContinue?"),
+ CMString ptszMsg(FORMAT, TranslateT("Are you sure to ban %s? %s%sContinue?"),
IsEmpty(ptszNick) ? TranslateT("(Unknown contact)") : ptszNick,
tszVarWarning.IsEmpty() ? _T(" ") : TranslateT("\nIt will also"),
tszVarWarning.IsEmpty() ? _T("\n") : tszVarWarning);
@@ -696,10 +690,8 @@ INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM)
if (!IsOnline() || userID == -1 || userID == VK_FEED_USER)
return 1;
- CMString formatstr = TranslateT("Are you sure to report abuse on %s?"),
- tszNick(ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"))),
- ptszMsg;
- ptszMsg.AppendFormat(formatstr, tszNick.IsEmpty() ? TranslateT("(Unknown contact)") : tszNick);
+ CMString tszNick(ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"))),
+ ptszMsg(FORMAT, TranslateT("Are you sure to report abuse on %s?"), tszNick.IsEmpty() ? TranslateT("(Unknown contact)") : tszNick);
if (IDNO == MessageBox(NULL, ptszMsg, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
return 1;
diff --git a/protocols/VKontakte/src/vk_wallpost.cpp b/protocols/VKontakte/src/vk_wallpost.cpp
index e46aec3d77..47debae295 100644
--- a/protocols/VKontakte/src/vk_wallpost.cpp
+++ b/protocols/VKontakte/src/vk_wallpost.cpp
@@ -48,8 +48,7 @@ static INT_PTR CALLBACK WallPostFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara
TranslateDialogDefault(hwndDlg);
{
SetDlgItemText(hwndDlg, IDC_ST_WARNING, _T(""));
- CMString tszTitle;
- tszTitle.AppendFormat(_T("%s %s"), TranslateT("Wall message for"), param->ptszNick);
+ CMString tszTitle(FORMAT, _T("%s %s"), TranslateT("Wall message for"), param->ptszNick);
SetWindowText(hwndDlg, tszTitle);
}
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)param);