summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2015-06-09 10:53:31 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2015-06-09 10:53:31 +0000
commitbc5b5ca600ad9364aa50de6afe2bf92dc63e1420 (patch)
tree26c00a736566af3c2817647beb480e58028f3a49
parent173995b62f1440f7c9bfd7a30371094a22e6fb9d (diff)
VKontakte:
add MessageState support update VK API to 5.34 add basic action support for muc fix Nick for left chat user version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@14071 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/VKontakte/src/misc.cpp2
-rw-r--r--protocols/VKontakte/src/version.h2
-rw-r--r--protocols/VKontakte/src/vk.h2
-rw-r--r--protocols/VKontakte/src/vk_chats.cpp90
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp2
-rw-r--r--protocols/VKontakte/src/vk_proto.h7
6 files changed, 84 insertions, 21 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index 34c4ef33ac..7d497c13fd 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -303,7 +303,7 @@ bool CVkProto::CheckMid(LIST<void> &lList, int guid)
JSONNode& CVkProto::CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONNode &root)
{
- debugLogA("CVkProto::CheckJsonResponse JSONNode");
+ debugLogA("CVkProto::CheckJsonResponse");
root = JSONNode::parse(reply->pData);
if (!root)
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h
index d75ec44455..7ae0564876 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 4
+#define __BUILD_NUM 5
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h
index 47bcf11039..f4f4153a46 100644
--- a/protocols/VKontakte/src/vk.h
+++ b/protocols/VKontakte/src/vk.h
@@ -67,7 +67,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define VKERR_INVALID_FILENAME 301 // Invalid filename
#define VKERR_INVALID_FILESIZE 302 // Invalid filesize
-#define VK_API_VER "5.33"
+#define VK_API_VER "5.34"
#define VER_API CHAR_PARAM("v", VK_API_VER)
#define VK_FEED_USER 2147483647L
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp
index 85d725b372..53f1f8ef1d 100644
--- a/protocols/VKontakte/src/vk_chats.cpp
+++ b/protocols/VKontakte/src/vk_chats.cpp
@@ -99,24 +99,29 @@ CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg)
void CVkProto::RetrieveChatInfo(CVkChatInfo *cc)
{
- CMStringA szQuery("return { ");
- // retrieve title & owner id
- szQuery.AppendFormat("\"info\": API.messages.getChat({\"chat_id\":%d}),", cc->m_chatid);
+ CMString tszQuery;
+ tszQuery.AppendFormat(_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\"});");
- // retrieve users
- szQuery.AppendFormat("\"users\": API.messages.getChatUsers({\"chat_id\":%d, \"fields\":\"id,first_name,last_name\"})", cc->m_chatid);
+ if (!cc->m_bHistoryRead) {
+ tszQuery += _T("var ChatMsg=API.messages.getHistory({\"chat_id\":ChatId,\"count\":20,\"rev\":0});");
+ 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)
- szQuery.AppendFormat(",\"msgs\": API.messages.getHistory({\"chat_id\":%d, \"count\":20, \"rev\":0})", cc->m_chatid);
+ tszQuery += _T(",\"msgs\":ChatMsg,\"msgs_users\":MsgUsers");
- szQuery.Append("};");
+ tszQuery +=_T("};");
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", szQuery)
+ << TCHAR_PARAM("code", tszQuery)
<< VER_API)->pUserInfo = cc;
}
@@ -214,6 +219,24 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
}
}
+ const JSONNode &jnMsgsUsers = jnResponse["msgs_users"];
+ for (auto it = jnMsgsUsers.begin(); it != jnMsgsUsers.end(); ++it) {
+ const JSONNode &jnUser = (*it);
+ LONG uid = jnUser["id"].as_int();
+ CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid);
+ if (cu)
+ continue;
+
+ MCONTACT hContact = FindUser(uid);
+ if (hContact)
+ continue;
+
+ hContact = SetContactInfo(jnUser, true);
+ db_set_b(hContact, "CList", "Hidden", 1);
+ db_set_b(hContact, "CList", "NotOnList", 1);
+ db_set_dw(hContact, "Ignore", "Mask1", 0);
+ }
+
const JSONNode &jnMsgs = jnResponse["msgs"];
if (!jnMsgs.isnull()) {
@@ -232,7 +255,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
for (int j = 0; j < cc->m_msgs.getCount(); j++) {
CVkChatMessage &p = cc->m_msgs[j];
- AppendChatMessage(cc, p.m_uid, p.m_date, p.m_tszBody, p.m_bHistory);
+ AppendChatMessage(cc, p.m_uid, p.m_date, p.m_tszBody, p.m_bHistory, p.m_bIsAction);
}
cc->m_msgs.destroy();
}
@@ -248,6 +271,7 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
int mid = jnMsg["id"].as_int();
int uid = jnMsg["user_id"].as_int();
+ bool bIsAction = false;
int msgTime = jnMsg["date"].as_int();
time_t now = time(NULL);
@@ -272,8 +296,44 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
tszBody += tszAttachmentDescr;
}
+ if (tszBody.IsEmpty() && !jnMsg["action"].isnull()){
+ bIsAction = true;
+ CMString tszAction = jnMsg["action"].as_mstring();
+
+ if (tszAction.IsEmpty())
+ tszBody = _T("...");
+ else if (tszAction == _T("chat_create")) {
+ CMString tszActionText = jnMsg["action_text"].as_mstring();
+ tszBody.AppendFormat(_T("%s \"%s\""), TranslateT("create chat"), tszActionText);
+ }
+ else if (tszAction == _T("chat_kick_user")){
+ CMString tszActionMid = jnMsg["action_mid"].as_mstring();
+ if (tszActionMid.IsEmpty())
+ tszBody = TranslateT("was kiked");
+ else {
+ CMString tszUid;
+ tszUid.AppendFormat(_T("%d"), uid);
+ if (tszUid == tszActionMid)
+ tszBody = TranslateT("left chat");
+ else {
+ int a_uid = 0;
+ int iReadCount = _stscanf(tszActionMid, _T("%d"), &a_uid);
+ if (iReadCount == 1) {
+ CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&a_uid);
+ if (cu == NULL)
+ tszBody = TranslateT("was kiked");
+ else
+ tszBody.AppendFormat(_T("%s by %s"), TranslateT("was kiked"), cu->m_tszNick);
+ }
+ else
+ tszBody = TranslateT("was kiked");
+ }
+ }
+ }
+ }
+
if (cc->m_bHistoryRead)
- AppendChatMessage(cc, uid, msgTime, tszBody, bIsHistory);
+ AppendChatMessage(cc, uid, msgTime, tszBody, bIsHistory, bIsAction);
else {
CVkChatMessage *cm = cc->m_msgs.find((CVkChatMessage *)&mid);
if (cm == NULL)
@@ -283,29 +343,31 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
cm->m_date = msgTime;
cm->m_tszBody = mir_tstrdup(tszBody);
cm->m_bHistory = bIsHistory;
+ cm->m_bIsAction = bIsAction;
}
}
-void CVkProto::AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory)
+void CVkProto::AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory, bool bIsAction)
{
debugLogA("CVkProto::AppendChatMessage2");
+ MCONTACT hContact = FindUser(uid);
CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid);
if (cu == NULL) {
cc->m_users.insert(cu = new CVkChatUser(uid));
- cu->m_tszNick = mir_tstrdup(TranslateT("Unknown"));
+ cu->m_tszNick = mir_tstrdup(hContact ? ptrT(db_get_tsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown"));
cu->m_bUnknown = true;
}
TCHAR tszId[20];
_itot(uid, tszId, 10);
- GCDEST gcd = { m_szModuleName, cc->m_tszId, GC_EVENT_MESSAGE };
+ GCDEST gcd = { m_szModuleName, cc->m_tszId, bIsAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE };
GCEVENT gce = { sizeof(GCEVENT), &gcd };
gce.bIsMe = (uid == m_myUserId);
gce.ptszUID = tszId;
gce.time = msgTime;
gce.dwFlags = (bIsHistory) ? GCEF_NOTNOTIFY : GCEF_ADDTOLOG;
- gce.ptszNick = cu->m_tszNick ? mir_tstrdup(cu->m_tszNick) : mir_tstrdup(TranslateT("Unknown"));
+ gce.ptszNick = cu->m_tszNick ? mir_tstrdup(cu->m_tszNick) : mir_tstrdup(hContact ? ptrT(db_get_tsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown"));
gce.ptszText = IsEmpty((TCHAR *)ptszBody) ? mir_tstrdup(_T("...")) : mir_tstrdup(ptszBody);
CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
}
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index a09c0b35e0..37bf19cac7 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -461,7 +461,7 @@ DWORD_PTR CVkProto::GetCaps(int type, MCONTACT)
return PF2_ONLINE;
case PFLAGNUM_4:
- return PF4_AVATARS | PF4_SUPPORTTYPING | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE | PF4_OFFLINEFILES;
+ return PF4_AVATARS | PF4_SUPPORTTYPING | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE | PF4_OFFLINEFILES | PF4_READNOTIFY;
case PFLAGNUM_5:
return PF2_ONTHEPHONE;
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index cd034b1bc9..615026ebaa 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -116,11 +116,12 @@ struct CVkChatMessage : public MZeroedObject
m_mid(_id),
m_uid(0),
m_date(0),
- m_bHistory(false)
+ m_bHistory(false),
+ m_bIsAction(false)
{}
int m_mid, m_uid, m_date;
- bool m_bHistory;
+ bool m_bHistory, m_bIsAction;
ptrT m_tszBody;
};
@@ -639,7 +640,7 @@ private:
OBJLIST<CVkChatInfo> m_chats;
CVkChatInfo* AppendChat(int id, const JSONNode &jnNode);
void AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory);
- void AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory);
+ void AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory, bool bIsAction = false);
void RetrieveChatInfo(CVkChatInfo*);
void OnReceiveChatInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSendChatMsg(NETLIBHTTPREQUEST*, AsyncHttpRequest*);