summaryrefslogtreecommitdiff
path: root/protocols/VKontakte
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-01-08 19:40:19 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-01-08 19:40:19 +0000
commit0242b87e3fd62749b0d3c32cdfe0353d8496e9ec (patch)
tree8aeb60ce65b16dfa9a5729295caf3f720fed5815 /protocols/VKontakte
parent05cd7934d4bdb097e112efdda356946868f3f5d6 (diff)
initial version of VK chats (invisible for a while)
git-svn-id: http://svn.miranda-ng.org/main/trunk@7550 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r--protocols/VKontakte/src/stdafx.h1
-rw-r--r--protocols/VKontakte/src/vk_chats.cpp59
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp8
-rw-r--r--protocols/VKontakte/src/vk_proto.h22
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp25
-rw-r--r--protocols/VKontakte/vk_10.vcxproj1
-rw-r--r--protocols/VKontakte/vk_10.vcxproj.filters3
-rw-r--r--protocols/VKontakte/vk_11.vcxproj1
-rw-r--r--protocols/VKontakte/vk_11.vcxproj.filters3
-rw-r--r--protocols/VKontakte/vk_12.vcxproj1
-rw-r--r--protocols/VKontakte/vk_12.vcxproj.filters3
11 files changed, 121 insertions, 6 deletions
diff --git a/protocols/VKontakte/src/stdafx.h b/protocols/VKontakte/src/stdafx.h
index ff37ff59a3..0b7db5824d 100644
--- a/protocols/VKontakte/src/stdafx.h
+++ b/protocols/VKontakte/src/stdafx.h
@@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_system_cpp.h>
#include <m_avatars.h>
+#include <m_chat.h>
#include <m_clistint.h>
#include <m_database.h>
#include <m_extraicons.h>
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp
new file mode 100644
index 0000000000..bdbe536d1f
--- /dev/null
+++ b/protocols/VKontakte/src/vk_chats.cpp
@@ -0,0 +1,59 @@
+/*
+Copyright (c) 2013-14 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+void CVkProto::AppendChat(int id, JSONNODE *pDlg)
+{
+ CVkChatInfo *c = new CVkChatInfo(id);
+
+ ptrT tszTitle(json_as_string(json_get(pDlg, "title")));
+ c->m_tszTitle = mir_tstrdup((tszTitle != NULL) ? tszTitle : _T(""));
+
+ CMString ids = ptrT(json_as_string(json_get(pDlg, "chat_active")));
+ for (int iStart = 0;;) {
+ CMString uid = ids.Tokenize(_T(","), iStart);
+ if (iStart == -1)
+ break;
+
+ CVkChatUser *cu = new CVkChatUser();
+ cu->userid = _ttoi(uid);
+ c->m_users.insert(cu);
+ }
+
+ CMString sid; sid.Format(_T("%S_%d"), m_szModuleName, id);
+
+ GCSESSION gcw = { sizeof(gcw) };
+ gcw.iType = GCW_CHATROOM;
+ gcw.pszModule = m_szModuleName;
+ gcw.ptszName = tszTitle;
+ gcw.ptszID = sid;
+ CallServiceSync(MS_GC_NEWSESSION, NULL, (LPARAM)&gcw);
+
+ GC_INFO gci = { 0 };
+ gci.pszModule = m_szModuleName;
+ gci.pszID = sid.GetBuffer();
+ gci.Flags = BYID | HCONTACT;
+ CallService(MS_GC_GETINFO, 0, (LPARAM)&gci);
+ c->m_hContact = gci.hContact;
+ m_chats.insert(c);
+
+ GCDEST gcd = { m_szModuleName, sid.GetBuffer(), GC_EVENT_CONTROL };
+ GCEVENT gce = { sizeof(GCEVENT), &gcd };
+ CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, (LPARAM)&gce);
+ // CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce);
+}
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index 1d45da95fe..65d43eed8c 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -22,7 +22,8 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
m_arRequestsQueue(10),
m_sendIds(3, PtrKeySortT),
m_cookies(5),
- m_msgId(1)
+ m_msgId(1),
+ m_chats(1, NumericKeySortT)
{
InitQueue();
@@ -51,6 +52,11 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
m_bServerDelivery = getBool("ServerDelivery", true);
+ GCREGISTER gcr = { sizeof(gcr) };
+ gcr.ptszDispName = m_tszUserName;
+ gcr.pszModule = m_szModuleName;
+ CallServiceSync(MS_GC_REGISTER, NULL, (LPARAM)&gcr);
+
// Set all contacts offline -- in case we crashed
SetAllContactStatuses(ID_STATUS_OFFLINE);
}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 7b488f15ae..32f597d939 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -31,6 +31,25 @@ struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
void *pUserInfo;
};
+struct CVkChatUser
+{
+ int userid;
+ ptrT tszTitle, tszImage;
+};
+
+struct CVkChatInfo
+{
+ CVkChatInfo(int _id) :
+ m_users(10, NumericKeySortT),
+ m_chatid(_id)
+ {}
+
+ int m_chatid;
+ ptrT m_tszTitle;
+ HANDLE m_hContact;
+ OBJLIST<CVkChatUser> m_users;
+};
+
struct CVkProto : public PROTO<CVkProto>
{
CVkProto(const char*, const TCHAR*);
@@ -202,4 +221,7 @@ private:
bool CheckMid(int msgid);
static INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
+ OBJLIST<CVkChatInfo> m_chats;
+ void AppendChat(int id, JSONNODE *pNode);
};
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index f4acb24a5e..9d7fc28a48 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -385,11 +385,10 @@ void CVkProto::RetrieveUnreadMessages()
debugLogA("CVkProto::RetrieveMessages");
HttpParam params[] = {
- { "filters", "1" },
- { "preview_length", "0" },
+ { "code", "return { \"msgs\":API.messages.get({\"filters\":1}), \"dlgs\":API.messages.getDialogs() };" },
{ "access_token", m_szAccessToken }
};
- PushAsyncHttpRequest(REQUEST_GET, "/method/messages.get.json", true, &CVkProto::OnReceiveMessages, SIZEOF(params), params);
+ PushAsyncHttpRequest(REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveMessages, SIZEOF(params), params);
}
static char* szImageTypes[] = { "src_xxxbig", "src_xxbig", "src_xbig", "src_big", "src", "src_small" };
@@ -405,12 +404,28 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (pResponse == NULL)
return;
+ JSONNODE *pDlgs = json_as_array(json_get(pResponse, "dlgs"));
+ if (pDlgs != NULL) {
+ int numDialogs = json_as_int(json_at(pDlgs, 0));
+ for (int i = 1; i <= numDialogs; i++) {
+ JSONNODE *pDlg = json_at(pDlgs, i);
+ if (pDlg == NULL)
+ continue;
+
+ int chatid = json_as_int(json_get(pDlg, "chat_id"));
+ if (chatid != 0)
+ if (m_chats.find((CVkChatInfo*)&chatid) == NULL) {
+ AppendChat(chatid, pDlg);
+ }
+ }
+ }
+
+ CMStringA mids, lmids;
+
JSONNODE *pMsgs = json_as_array( json_get(pResponse, "msgs"));
if (pMsgs == NULL)
pMsgs = pResponse;
- CMStringA mids, lmids;
-
int numMessages = json_as_int( json_at(pMsgs, 0));
for (int i=1; i <= numMessages; i++) {
JSONNODE *pMsg = json_at(pMsgs, i);
diff --git a/protocols/VKontakte/vk_10.vcxproj b/protocols/VKontakte/vk_10.vcxproj
index d77fddaca8..dcf885f75c 100644
--- a/protocols/VKontakte/vk_10.vcxproj
+++ b/protocols/VKontakte/vk_10.vcxproj
@@ -182,6 +182,7 @@
</ClCompile>
<ClCompile Include="src\vk_avatars.cpp" />
<ClCompile Include="src\vk_captcha.cpp" />
+ <ClCompile Include="src\vk_chats.cpp" />
<ClCompile Include="src\vk_options.cpp" />
<ClCompile Include="src\vk_proto.cpp" />
<ClCompile Include="src\vk_queue.cpp" />
diff --git a/protocols/VKontakte/vk_10.vcxproj.filters b/protocols/VKontakte/vk_10.vcxproj.filters
index 69ca485705..5e6610c062 100644
--- a/protocols/VKontakte/vk_10.vcxproj.filters
+++ b/protocols/VKontakte/vk_10.vcxproj.filters
@@ -42,6 +42,9 @@
<ClCompile Include="src\vk_captcha.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\vk_chats.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\version.h">
diff --git a/protocols/VKontakte/vk_11.vcxproj b/protocols/VKontakte/vk_11.vcxproj
index 1c245f8b62..f8374562fa 100644
--- a/protocols/VKontakte/vk_11.vcxproj
+++ b/protocols/VKontakte/vk_11.vcxproj
@@ -185,6 +185,7 @@
</ClCompile>
<ClCompile Include="src\vk_avatars.cpp" />
<ClCompile Include="src\vk_captcha.cpp" />
+ <ClCompile Include="src\vk_chats.cpp" />
<ClCompile Include="src\vk_options.cpp" />
<ClCompile Include="src\vk_proto.cpp" />
<ClCompile Include="src\vk_queue.cpp" />
diff --git a/protocols/VKontakte/vk_11.vcxproj.filters b/protocols/VKontakte/vk_11.vcxproj.filters
index a0612f1dc5..f52152d3af 100644
--- a/protocols/VKontakte/vk_11.vcxproj.filters
+++ b/protocols/VKontakte/vk_11.vcxproj.filters
@@ -42,6 +42,9 @@
<ClCompile Include="src\vk_captcha.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\vk_chats.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\version.h">
diff --git a/protocols/VKontakte/vk_12.vcxproj b/protocols/VKontakte/vk_12.vcxproj
index c6b079fcc3..840c644a58 100644
--- a/protocols/VKontakte/vk_12.vcxproj
+++ b/protocols/VKontakte/vk_12.vcxproj
@@ -185,6 +185,7 @@
</ClCompile>
<ClCompile Include="src\vk_avatars.cpp" />
<ClCompile Include="src\vk_captcha.cpp" />
+ <ClCompile Include="src\vk_chats.cpp" />
<ClCompile Include="src\vk_options.cpp" />
<ClCompile Include="src\vk_proto.cpp" />
<ClCompile Include="src\vk_queue.cpp" />
diff --git a/protocols/VKontakte/vk_12.vcxproj.filters b/protocols/VKontakte/vk_12.vcxproj.filters
index a0612f1dc5..f52152d3af 100644
--- a/protocols/VKontakte/vk_12.vcxproj.filters
+++ b/protocols/VKontakte/vk_12.vcxproj.filters
@@ -42,6 +42,9 @@
<ClCompile Include="src\vk_captcha.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\vk_chats.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\version.h">