diff options
author | George Hazan <george.hazan@gmail.com> | 2013-10-11 22:41:40 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-10-11 22:41:40 +0000 |
commit | d4c204ca301117519e21ec50ecfb565d400e2cda (patch) | |
tree | 2474015aefbdc619ce71662d667ac093abc4cf8a /protocols/VKontakte | |
parent | fabafbe2f69ba2c78e05b3ac93ce5da8db61916f (diff) |
VK:
- message sending
- fix for hangup on exit
git-svn-id: http://svn.miranda-ng.org/main/trunk@6454 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 57 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 3 |
2 files changed, 52 insertions, 8 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 78ca6fbdc4..2ef53906ea 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -19,7 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
PROTO<CVkProto>(szModuleName, ptszUserName),
- m_arRequestsQueue(10)
+ m_arRequestsQueue(10),
+ m_msgId(1)
{
InitQueue();
@@ -62,8 +63,6 @@ int CVkProto::OnPreShutdown(WPARAM wParam, LPARAM lParam) {
m_bTerminated = true;
SetEvent(m_evRequestsQueue);
- if (m_hPollingThread)
- TerminateThread(m_hPollingThread, 0);
return 0;
}
@@ -109,6 +108,53 @@ int CVkProto::RecvMsg(HANDLE hContact, PROTORECVEVENT *pre) //////////////////////////////////////////////////////////////////////////////
+struct TFakeAckParams
+{
+ __inline TFakeAckParams(HANDLE _hContact, int _msgid) :
+ hContact(_hContact), msgid(_msgid)
+ {}
+
+ HANDLE hContact;
+ int msgid;
+};
+
+void CVkProto::SendMsgAck(void *param)
+{
+ TFakeAckParams *ack = (TFakeAckParams*)param;
+ Sleep(100);
+ ProtoBroadcastAck(ack->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)ack->msgid, 0);
+ delete ack;
+}
+
+int CVkProto::SendMsg(HANDLE hContact, int flags, const char *msg)
+{
+ ptrA szID( getStringA(hContact, "ID"));
+ if (szID == NULL)
+ return 0;
+
+ ptrA szMsg;
+ if (flags & PREF_UTF)
+ szMsg = mir_strdup(msg);
+ else if (flags & PREF_UNICODE)
+ msg = mir_utf8encodeW((wchar_t*)&msg[strlen(msg)+1]);
+ else
+ msg = mir_utf8encode(msg);
+
+ HttpParam params[] = {
+ { "type", "0" },
+ { "uid", szID },
+ { "message", szMsg },
+ { "access_token", m_szAccessToken }
+ };
+ PushAsyncHttpRequest(REQUEST_GET, "/method/messages.send.json", true, NULL, SIZEOF(params), params);
+
+ ULONG msgId = ::InterlockedIncrement(&m_msgId);
+ ForkThread(&CVkProto::SendMsgAck, new TFakeAckParams(hContact, msgId));
+ return msgId;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
int CVkProto::SetStatus(int iNewStatus)
{
if (m_iDesiredStatus == iNewStatus)
@@ -193,11 +239,6 @@ int CVkProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason) return 1;
}
-int CVkProto::SendMsg(HANDLE hContact, int flags, const char *msg)
-{
- return 0;
-}
-
int CVkProto::UserIsTyping(HANDLE hContact, int type)
{
return 0;
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 3f5d8df4e0..c8275ae6f1 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -152,6 +152,8 @@ private: void SetAllContactStatuses(int status);
+ void __cdecl SendMsgAck(void *param);
+
bool m_bOnline;
HANDLE m_hNetlibConn;
@@ -161,4 +163,5 @@ private: ptrA m_pollingServer, m_pollingKey, m_pollingTs;
HANDLE m_hPollingThread;
+ ULONG m_msgId;
};
|